import type { McpServer } from './server.js'; /** Options for `mcpHttpHandler()`. */ export interface McpHttpOptions { /** * Origins allowed to call it from a browser, beside the endpoint's own: a request whose `Origin` * header names any other is refused with 403, so a web page cannot reach a server on this machine * through the person's browser. */ allowedOrigins?: readonly string[]; /** * Answers each request as JSON, after the server finishes, rather than as a stream of events. What * the server sends meanwhile then waits for the session's `GET` stream. */ json?: boolean; /** How long a session lasts without a request, in milliseconds. Defaults to 30 minutes. */ sessionTtlMs?: number; /** The most sessions held at once: a new one past it is refused with 503. Defaults to 1,000. */ maxSessions?: number; /** Makes a new session's id. Defaults to a random UUID. */ sessionId?: () => string; } /** A Web handler serving an MCP server over streamable HTTP, and what it holds. */ export interface McpHttpHandler { /** Answers one HTTP request: a `POST` of a message, a `GET` stream, or a `DELETE` of a session. */ (request: Request): Promise; /** How many sessions are open. */ sessions(): number; /** Ends every session. */ close(): Promise; } /** * Serves an MCP server over streamable HTTP, MCP's transport since 2025-03-26: each client that sends * `initialize` gets a session, named in the `Mcp-Session-Id` header it sends from then on. A request is * answered as a stream of events, which carries the server's progress and its questions for the * client, such as a tool's `context.mcp.createMessage()`, before the answer; with `json`, as JSON. A * notification or an answer the client sends is taken with 202. A `GET` holds the session's own stream, * for what the server sends of its own accord, and a `DELETE` ends the session. A request from a web * page on another origin is refused, unless `allowedOrigins` names it. * * ```ts * const handle = mcpHttpHandler(new McpServer({ tools: [search] })); * Bun.serve({ fetch: handle }); // or any server that speaks Request and Response * ``` */ export declare function mcpHttpHandler(server: McpServer, options?: McpHttpOptions): McpHttpHandler;