---
title: "Plain HTTP"
description: "Serve the same tools as JSON over plain HTTP. One GET lists them, one POST calls one, and writes stay off until you say so"
canonical_url: "https://tools.agntn.dev/guide/http"
---
# Plain HTTP

> Serve the same tools as JSON over plain HTTP. One GET lists them, one POST calls one, and writes stay off until you say so

A GTK app, script or dashboard can call your tools with a plain POST and get JSON back. Making a GTK app learn an MCP handshake just to call a tool is overkill. Want to give it a simpler door?

## Mount the handler

Import `createHttpHandler` from `@agntn/tools/http`. Pass it `info`, the tools and options. `info` is just a `name` and a `version`.

You get a Fetch handler with a `fetch(request)` method. It takes a `Request` and returns a `Response`. Any host that speaks Fetch can mount it. Here, h3 mounts it at `/http/slugs`:

```ts [server.ts]
import { H3, serve } from "h3";
import { createHttpHandler } from "@agntn/tools/http";
import { slugTool } from "./tools.ts";

const http = createHttpHandler({ name: "slugs", version: "1.0.0" }, [slugTool], {
  base: "/http/slugs",
});

const app = new H3().all("/http/slugs/**", (event) => http.fetch(event.req));
serve(app, { port: 3000 });
```

## List the tools

A GET at the root lists the server name, version and tools. Each tool has a name, title, description, effect and `inputSchema`. With `base` set to `/http/slugs`, the listing lives there:

```text [terminal]
$ curl -s http://localhost:3000/http/slugs | jq
{
  "name": "slugs",
  "version": "1.0.0",
  "tools": [
    {
      "name": "text_slug",
      "title": "Text Slug",
      "description": "Turn a title into a lowercase URL slug.",
      "effect": "read",
      "inputSchema": {
        "type": "object",
        "required": [
          "text"
        ],
        "properties": {
          "text": {
            "type": "string",
            "minLength": 1
          }
        },
        "additionalProperties": false
      }
    }
  ]
}
```

## Call a tool

POST to the tool's name under the base path. Send its input as JSON. An empty body counts as `{}`.

```text [terminal]
$ curl -s -H 'content-type: application/json' -d '{"text":"Hello, World"}' http://localhost:3000/http/slugs/text_slug
{"text":"hello-world","details":{"slug":"hello-world"}}
```

The core checks input before calling the tool, just as it does on other hosts. A typo gets the same error lines MCP would return:

```text [terminal]
$ curl -s -w '\n%{http_code}\n' -H 'content-type: application/json' -d '{"txt":"Hello, World"}' http://localhost:3000/http/slugs/text_slug
{"lines":["Invalid arguments: unknown property \"txt\"; takes text","Invalid arguments at /: must have required properties text"]}
400
```

## What comes back?

A tool answer has `text` and `details`. It's 200, or 422 if the tool set `isError`. Both fields stay in the answer. Results with image blocks also include `images`, an array of `data` and `mimeType` objects.

A refusal has `lines` instead. Each line is a separate entry. Newlines inside an error message become spaces, so they can't forge another line.

<table>
<thead>
  <tr>
    <th>
      Status
    </th>
    
    <th>
      Body
    </th>
    
    <th>
      When
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      200
    </td>
    
    <td>
      <code>
        { text, details }
      </code>
    </td>
    
    <td>
      the tool answered
    </td>
  </tr>
  
  <tr>
    <td>
      422
    </td>
    
    <td>
      <code>
        { text, details }
      </code>
    </td>
    
    <td>
      the tool set <code>
        isError
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      400
    </td>
    
    <td>
      <code>
        { lines }
      </code>
    </td>
    
    <td>
      bad input, or a body that isn't JSON
    </td>
  </tr>
  
  <tr>
    <td>
      403
    </td>
    
    <td>
      <code>
        { lines }
      </code>
    </td>
    
    <td>
      the tool's effect isn't in <code>
        effects
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      404
    </td>
    
    <td>
      <code>
        { lines }
      </code>
    </td>
    
    <td>
      no such tool, or nothing at that path
    </td>
  </tr>
  
  <tr>
    <td>
      405
    </td>
    
    <td>
      <code>
        { lines }
      </code>
    </td>
    
    <td>
      wrong method, <code>
        Allow
      </code>
      
       names the right one
    </td>
  </tr>
  
  <tr>
    <td>
      413
    </td>
    
    <td>
      <code>
        { lines }
      </code>
    </td>
    
    <td>
      body over <code>
        maxRequestBodySize
      </code>
      
      , 4 MiB by default
    </td>
  </tr>
  
  <tr>
    <td>
      415
    </td>
    
    <td>
      <code>
        { lines }
      </code>
    </td>
    
    <td>
      no <code>
        Content-Type: application/json
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      500
    </td>
    
    <td>
      <code>
        { lines }
      </code>
    </td>
    
    <td>
      the tool threw, <code>
        caused by:
      </code>
      
       lines included
    </td>
  </tr>
</tbody>
</table>

The body needs `Content-Type: application/json`, or the handler returns 415. A browser page can't send that header across origins without a CORS preflight. This handler never answers one.

## Writes stay off

The `effects` option defaults to `["read"]`. An HTTP call has nobody there to click "approve". Write tools stay out of the listing and return 403.

You can turn writes on:

```ts [server.ts]
const http = createHttpHandler({ name: "slugs", version: "1.0.0" }, [slugTool], {
  base: "/http/slugs",
  effects: ["read", "write"],
});
```

Only do that behind your host's authentication.

## Stream progress over HTTP

Want to see a call make progress? Send your usual POST with `Accept: text/event-stream`. You'll get Server-Sent Events with `Content-Type: text/event-stream` and `Cache-Control: no-cache`.

Each `progress` event carries `message`, plus `progress` and `total` when they're numbers. HTTP doesn't renumber or drop updates. That's handy for a slow call: you can tell it's still working.

Here a `job_wait` tool, mounted at `/http/jobs`, checks a build three times:

```text [terminal]
$ curl -sN -H 'accept: text/event-stream' -H 'content-type: application/json' -d '{"id":"build-42"}' http://localhost:3000/http/jobs/job_wait
event: progress
data: {"message":"build-42 still running, check 1","progress":1,"total":3}

event: progress
data: {"message":"build-42 still running, check 2","progress":2,"total":3}

event: progress
data: {"message":"build-42 still running, check 3","progress":3,"total":3}

event: result
data: {"status":200,"text":"build-42 is done","details":{"id":"build-42","checks":3}}
```

The stream ends with one `result` event. It carries the usual `{ text, details }` or `{ lines }`, plus `status`. The status rides in the result because the headers already left with the first event. Close the stream halfway and the read stops with it.

Bad tool input arrives as a `result` with `status: 400` and the usual `lines`.

```text [terminal]
$ curl -sN -H 'accept: text/event-stream' -H 'content-type: application/json' -d '{"di":"build-42"}' http://localhost:3000/http/jobs/job_wait
event: result
data: {"status":400,"lines":["Invalid arguments: unknown property \"di\"; takes id","Invalid arguments at /: must have required properties id"]}
```

Some refusals happen before the call starts. These stay plain JSON, even when you ask for events:

- Unknown tool: 404.
- Wrong method: 405.
- Write tool not served: 403.
- Missing JSON content type: 415.
- Oversized body: 413.
- Body that isn't JSON: 400.

Without the header, you'll get one JSON answer at the end. `Accept: */*` doesn't request events. Neither does `text/event-stream;q=0`.

## Who's calling?

Authentication belongs to the host. Check `Host`, `Origin` and a token before the request reaches the handler.

Tools receive `host` with `http: true` and the `request`, so they can read its headers. But client headers are name tags, not keys. They can identify a caller, not authorize one.

The request's `signal` becomes the call's `signal`. If the host aborts it when the client hangs up, a read is cancelled. h3 does. Progress is available only on a streamed call, which makes a long wait easier to follow. But `ask` is absent: an HTTP form has nobody to fill it in.


## Sitemap

See the full [sitemap](https://tools.agntn.dev/sitemap.md) for all pages.
