/** * MCP-over-web-standard-transport adapter used by the `handleWebFetch` execute * stage of the `http:request` flow (V8 isolates / Cloudflare Workers). * * Two modes, both speaking the SAME `WebStandardStreamableHTTPServerTransport`: * * - **Stateless** ({@link runWebStandardMcp} with no `persistent`): a fresh * `McpServer` + transport per request (`sessionIdGenerator: undefined`). The * default serverless model. * - **Stateful** (a Durable Object passes `persistent`): one persistent * `McpServer` + session-bound transport built once via {@link * buildPersistentWebStandardMcp} and reused across the session's requests, so * the standalone GET notification stream stays open and a `tools/call`'s * notifications reach it. The DO owns the lifecycle — no per-request teardown. * * Auth / quota / router / audit / metrics + hooks have already run in the flow * around this call; this only translates the MCP request↔response. */ import { type AuthInfo } from '@frontmcp/protocol'; import { type Scope } from '../scope/scope.instance'; import { type ScopedServerOptions } from './build-scoped-server-options'; /** A persistent MCP server + transport bound to one session (Durable Object). */ export interface WebStandardMcpPair { mcpServer: { close(): Promise; }; transport: { handleRequest(request: Request, options?: { authInfo?: AuthInfo; }): Promise; onclose?: () => void; }; } export interface RunWebStandardMcpOptions { /** Capability/server options for the `McpServer` (from `buildScopedServerOptions`). */ serverOptions: ScopedServerOptions; /** Verified auth info to expose to handlers (derived from the flow's session:verify result). */ authInfo?: Partial; /** Allow SSE streaming responses on POST when the client accepts `text/event-stream` (stateless mode). */ sse: boolean; /** Worker `ExecutionContext` so an SSE body can keep the isolate alive past `fetch` (stateless mode). */ ctx?: { waitUntil?(promise: Promise): void; }; /** * A persistent, session-bound server+transport (Durable Object / stateful * sessions). When provided, the request is handled on it and no fresh server * is created or torn down — the DO owns its lifecycle. */ persistent?: WebStandardMcpPair; } /** * Build a persistent, session-bound MCP server + transport for a Durable Object. * Stateful (`sessionIdGenerator: () => sessionId`) and streaming-capable * (`enableJsonResponse: false`) so the standalone GET notification stream and * server-initiated notifications work. Call once per session; the DO keeps it * alive and passes it back via `RunWebStandardMcpOptions.persistent`. */ export declare function buildPersistentWebStandardMcp(scope: Scope, options: { sessionId: string; }): Promise; export declare function runWebStandardMcp(scope: Scope, request: Request, options: RunWebStandardMcpOptions): Promise; //# sourceMappingURL=web-standard-mcp.d.ts.map