/** * MCP Streamable HTTP transport, written against the Fetch API only. * * `handleMcpHttpRequest` turns one `Request` into one `Response`, so any * runtime with `Request`/`Response` can host it: a Cloudflare Worker, Deno, Bun * or Node 20+. It imports nothing Node-specific and no tool with a side effect; * the host passes the tool list and a per-request context, which is how the * Worker attaches authorization, rate limiting and storage to the shared tool * contracts. * * The server is stateless: it issues no `Mcp-Session-Id`, opens no * server-initiated stream (GET answers 405), and replies to every POST with a * single JSON body rather than an SSE stream, which the specification allows. */ import { type ToolResult } from './mcp-protocol.js'; import type { McpTool } from './mcp-tool-definitions.js'; /** Request body ceiling used when the host does not set one: 1 MiB. */ export declare const DEFAULT_MCP_MAX_REQUEST_BYTES: number; /** * Most members one batch may carry. A batch is answered member by member in one * request, so without a ceiling a small body buys unbounded work and output. */ export declare const DEFAULT_MCP_MAX_BATCH_SIZE = 16; export interface McpHttpOptions { /** The tools this endpoint serves, in the order `tools/list` announces them. */ tools: readonly McpTool>[]; /** Per-request context handed to every tool call in this request. */ context: C; /** `initialize` instructions for the model. */ instructions: string; /** * Browser origins allowed besides the endpoint's own. A request carrying any * other `Origin` is refused with 403, which is the DNS-rebinding guard the * transport specification requires. Requests without `Origin` (non-browser * clients) are not affected. */ allowedOrigins?: readonly string[]; /** Request body ceiling in bytes. */ maxRequestBytes?: number; /** Most members a JSON-RPC batch may carry. */ maxBatchSize?: number; /** * Runs once per request after every transport check passed and before any * message is dispatched. A returned `Response` is sent as is (for example a * 401 for a rejected bearer); `undefined` lets the request through. */ preflight?: () => Promise; /** * Turns an error a tool threw into a tool result. Defaults to reporting the * error's message; a hosted server passes a mapper that hides internals. */ toolError?: (error: unknown) => ToolResult; } /** * Serve one Streamable HTTP request on the MCP endpoint. * * - POST with one JSON-RPC message (or a batch, for 2025-03-26 clients) answers * 200 with the JSON response, or 202 with no body when every message was a * notification or a response. * - A batch answers 400 when the request's protocol revision has no batching * (2025-06-18 and later), when it is larger than `maxBatchSize`, or when it * carries `initialize`, which must be sent alone. * - Any other method answers 405: this server has no server-initiated stream * and no session to delete. * - An unsupported `MCP-Protocol-Version` header answers 400. */ export declare function handleMcpHttpRequest(request: Request, options: McpHttpOptions): Promise; //# sourceMappingURL=mcp-http-transport.d.ts.map