import { t as McpFetchHandler } from "./mcp-resource-server-C4RxIuQl.mjs"; import { McpHandlerRequestOptions } from "@modelcontextprotocol/server"; //#region src/security/mcp-http-security.d.ts declare const MCP_DEFAULT_MAX_BODY_BYTES = 1048576; declare const MCP_CORS_METHODS: readonly string[]; /** * Request headers the 2026-07-28 revision requires browser clients to send. * `Mcp-Method`/`Mcp-Name` make every modern MCP POST CORS-preflighted. */ declare const MCP_CORS_ALLOWED_HEADERS: readonly string[]; declare const MCP_CORS_EXPOSED_HEADERS: readonly string[]; interface McpCorsOptions { /** * Allows cookies/credentialed requests. Cookie-authenticated MCP endpoints * are CSRF-able; leave off unless required. When enabled, `allowedOrigins` * is mandatory and the grant matches the full origin exactly — never a bare * hostname — so a compromised sibling scheme or port cannot inherit it. */ readonly credentials?: boolean; /** * Full browser origins (e.g. `https://app.example.com`) permitted to make * credentialed requests. Required when `credentials` is true; ignored * otherwise (non-credentialed CORS reflects any origin the allowlist admits). */ readonly allowedOrigins?: readonly string[]; readonly maxAgeSeconds?: number; readonly additionalAllowedHeaders?: readonly string[]; readonly additionalExposedHeaders?: readonly string[]; } interface McpHttpSecurityOptions { /** Host-header allowlist (hostnames only). Defaults to off: proxies rewrite `Host`, and the Origin rung already blocks DNS rebinding. */ readonly allowedHostnames?: readonly string[] | false; /** * Origin-header allowlist (hostnames only). Defaults to localhost-class * origins, so routable browser origins are denied until configured. * Requests without an `Origin` header always pass. `false` disables the check. */ readonly allowedOriginHostnames?: readonly string[] | false; /** CORS handling for allowed origins. Defaults to on whenever origin validation is on. */ readonly cors?: McpCorsOptions | boolean; /** Request-body byte cap. Defaults to 1 MiB; `false` disables the cap. */ readonly maxBodyBytes?: number | false; } interface ResolvedCorsPolicy { readonly credentials: boolean; readonly maxAgeSeconds: number; readonly allowedHeaders: string; readonly allowedHeaderSet: ReadonlySet; readonly exposedHeaders: string; readonly methods: string; /** Exact-origin allowlist enforced only in credentialed mode. */ readonly allowedOrigins: ReadonlySet | undefined; } /** Reports a pre-dispatch rejection (status ≥ 400) to an outer observer. */ interface McpHardenHooks { readonly onRejected?: (status: number) => void; } interface McpHttpSecurityPolicy { readonly resolved: true; readonly allowedHostnames: readonly string[] | undefined; readonly allowedOriginHostnames: readonly string[] | undefined; readonly cors: ResolvedCorsPolicy | undefined; readonly maxBodyBytes: number | undefined; } /** Resolves and validates the declarative options into a frozen policy. */ declare function resolveMcpHttpSecurity(options?: McpHttpSecurityOptions): McpHttpSecurityPolicy; declare function isMcpHttpSecurityPolicy(value: unknown): value is McpHttpSecurityPolicy; /** * The pre-dispatch gate: Host validation, then Origin validation, then CORS * preflight. Returns a short-circuit `Response`, or `undefined` to proceed. * A preflight from a rejected origin gets the 403 with no CORS headers. */ declare function mcpHttpSecurityRejection(request: Request, policy: McpHttpSecurityPolicy): Response | undefined; /** * Decorates a response with CORS headers when the request carries an allowed * Origin. Rebuilds the response without buffering so streamed SSE bodies keep * streaming; a response that already carries an ACAO header is left untouched. */ declare function applyMcpCorsHeaders(request: Request, response: Response, policy: McpHttpSecurityPolicy): Response; /** * Enforces the body cap. Returns the request (re-wrapped when the stream had * to be counted) or a `413` response. Already-limited requests pass through * untouched so double wrapping never buffers twice. */ declare function limitMcpRequestBody(request: Request, policy: McpHttpSecurityPolicy): Promise; /** * Wraps any fetch-shaped handler with the full gate → cap → CORS pipeline. * The forwarded request is marked as secured so the runtime's *implicit* * default gate defers to this explicit layer (an outer override can loosen as * well as tighten). Explicit hardened layers still run — the mark suppresses * only the runtime's built-in default, never another constructed facade — so * composed policies intersect. */ declare function hardenMcpFetch(handler: { fetch(request: Request, options?: McpHandlerRequestOptions): Promise; }, policy: McpHttpSecurityPolicy, hooks?: McpHardenHooks): { fetch(request: Request, options?: McpHandlerRequestOptions): Promise; }; /** Hardened facade preserving the full `McpFetchHandler` face, like `McpValidatedServer`. */ declare class McpHardenedServer implements McpFetchHandler { #private; readonly notify: McpFetchHandler["notify"]; readonly bus: McpFetchHandler["bus"]; constructor(handler: McpFetchHandler, options?: McpHttpSecurityOptions | McpHttpSecurityPolicy, hooks?: McpHardenHooks); get policy(): McpHttpSecurityPolicy; fetch(request: Request, options?: McpHandlerRequestOptions): Promise; close(): Promise; } /** * The origin to echo in `Access-Control-Allow-Origin`, or `undefined` to omit. * Credentialed mode requires an exact full-origin match; non-credentialed mode * reflects any origin the hostname allowlist admits. */ declare function corsAllowedOrigin(request: Request, policy: McpHttpSecurityPolicy): string | undefined; //#endregion export { McpCorsOptions as a, McpHttpSecurityOptions as c, corsAllowedOrigin as d, hardenMcpFetch as f, resolveMcpHttpSecurity as g, mcpHttpSecurityRejection as h, MCP_DEFAULT_MAX_BODY_BYTES as i, McpHttpSecurityPolicy as l, limitMcpRequestBody as m, MCP_CORS_EXPOSED_HEADERS as n, McpHardenHooks as o, isMcpHttpSecurityPolicy as p, MCP_CORS_METHODS as r, McpHardenedServer as s, MCP_CORS_ALLOWED_HEADERS as t, applyMcpCorsHeaders as u }; //# sourceMappingURL=mcp-http-security-BXpPP1E-.d.mts.map