import { type AuthInfo } from "@modelcontextprotocol/server"; import type { Context, Env } from "hono"; /** Web-standard request handler. */ export type FetchHandler = (request: Request) => Promise; /** Onion middleware over a {@link FetchHandler} terminal. */ export type FetchMiddleware = (request: Request, next: () => Promise) => Promise; /** Per-request values stashed before the MCP handler runs. */ export interface RequestBag { /** Parsed JSON body when the JSON middleware ran first. */ parsedBody?: unknown; /** Verified OAuth identity forwarded to the SDK handler. */ authInfo?: AuthInfo; /** Hono context associated with this request while it traverses the app. */ honoContext?: Context; } /** * Mutable per-request bag; created on first access. * * @param request - Incoming request whose bag to read or create. */ export declare function getRequestBag(request: Request): RequestBag; /** * Compose middleware around a terminal handler (first listed runs outermost). * * @param terminal - Fallback handler when no middleware short-circuits. * @param middlewares - Middleware chain executed before `terminal`. */ export declare function composeFetch(terminal: FetchHandler, ...middlewares: FetchMiddleware[]): FetchHandler; /** * Return the pathname of a request URL. * * @param request - Request whose pathname to read. */ export declare function pathnameOf(request: Request): string; /** * Match a request pathname exactly. * * @param request - Request to test. * @param path - Exact pathname (for example `/mcp`). */ export declare function matchesPath(request: Request, path: string): boolean; /** * Match a request pathname prefix (prefix or `prefix/...`). * * @param request - Request to test. * @param prefix - Path prefix without a trailing wildcard. */ export declare function matchesPathPrefix(request: Request, prefix: string): boolean; /** * Append a framework-owned child path beneath an MCP base path. * * Unlike string interpolation, this keeps the root base path from producing * a double slash: `pathUnderBase("/", "inspector")` is `"/inspector"`. * * @param basePath - Valid MCP base path, including the root path `/`. * @param childPath - Relative child path, with or without a leading slash. * @returns Absolute pathname beneath `basePath`. * * @internal */ export declare function pathUnderBase(basePath: string, childPath: string): string; /** * Classify a request as explicit browser HTML navigation. * * Only GET and HEAD requests whose Accept header names `text/html` with a * non-zero quality value qualify. Wildcard-only and missing Accept headers * remain available to protocol and health probes. * * @param request - Incoming request to classify. * @returns Whether the request explicitly accepts HTML. * * @internal */ export declare function isHtmlNavigationRequest(request: Request): boolean; /** * Parse JSON bodies once and stash them in the request bag. */ export declare function jsonBodyMiddleware(): FetchMiddleware; /** * Reject requests whose `Host` header is not on the allowlist. * * @param hosts - Allowed hostnames (port-agnostic). */ export declare function hostValidationMiddleware(hosts: string[]): FetchMiddleware; /** * Reject requests whose `Origin` header is not on the allowlist. * * @param origins - Allowed origin hostnames (port-agnostic). * @param skipSafeMethods - When true, skip GET/HEAD (view asset GETs). * @param exempt - Optional predicate for requests that do their own request * validation, such as OAuth provider endpoints that browser-based clients * call cross-origin. */ export declare function originValidationMiddleware(origins: string[], skipSafeMethods?: boolean, exempt?: (request: Request) => boolean): FetchMiddleware;