/** * Request checks for the HTTP transport. * * The server is meant to be reached by MCP clients, on this machine or across * the network, so the Host header is not checked: a client on another machine * sends the server's own address or name there. What it must keep out is a web * page in someone's browser. A page can reach the server two ways: a cross-site * POST (a text/plain body with "application/json" in a parameter passes the * SDK's content-type check without a CORS preflight) and DNS rebinding (the * attacker's hostname re-resolves to the server, so the page can also read the * response). Browsers send an Origin header on every POST, and in both cases it * names the attacker's site, so refuseForeignOrigins answers a request only when * it has no Origin (MCP clients that are not browsers send none), a loopback * Origin, or one listed in MCP_ALLOWED_ORIGINS. * * requireBearerToken is the opt-in shared secret (MCP_HTTP_TOKEN) for a server * that other machines can reach. * * MAX_MCP_MESSAGE_BYTES is the /mcp body limit. It matches the SDK's stdio * message cap (STDIO_DEFAULT_MAX_BUFFER_SIZE), so a tool call that fits on one * transport fits on the other. refusePayloadTooLarge answers a body over it, * refuseMalformedJson a body that is not JSON, and refuseUnreadableBody every * other body parser error, all as JSON-RPC errors instead of Express's HTML * error page, which carries a stack trace. */ import type { ErrorRequestHandler, RequestHandler } from "express"; /** 10 MiB: the largest JSON-RPC message /mcp accepts, the same as stdio. */ export declare const MAX_MCP_MESSAGE_BYTES: number; export declare function refuseForeignOrigins(allowedOrigins: string[]): RequestHandler; export declare function requireBearerToken(token: string): RequestHandler; /** Turns the body parser's 413 into a JSON-RPC error; other errors pass through. */ export declare const refusePayloadTooLarge: ErrorRequestHandler; /** Turns the body parser's JSON syntax error into a JSON-RPC parse error (-32700); other errors pass through. */ export declare const refuseMalformedJson: ErrorRequestHandler; /** * Answers every other body parser error as a JSON-RPC error with the parser's status: a body that does not * decompress (400), an unsupported Content-Encoding or charset (415). A status that is not a client error becomes * a 500 with no detail. Mounted last before the /mcp route, so it never passes an error on. */ export declare const refuseUnreadableBody: ErrorRequestHandler; export declare function isLoopbackAddress(address: string): boolean; /** The one line printed when the listener is reachable from other machines and has no token. */ export declare function openListenerWarning(address: string, tokenSet: boolean): string | undefined; //# sourceMappingURL=http-guard.d.ts.map