Web handler
request is the framework’s Web Request. Use handler.matches(pathname) to determine whether the combined handler owns an MCP or metadata path before routing other traffic.
Options and ordering
path defaults to /mcp. allowedHosts contains exact authorities, optionally with ports; defaults allow loopback hosts. An empty list rejects all hosts. Schemes, paths, and wildcards are not valid entries. Both the public request URL and supplied Host authority must pass validation.
An absent Origin is allowed. A present Origin must match allowedOrigins, which defaults to an empty list. This validation is distinct from CORS: applications implement any preflight handling and response headers they require.
Host validation runs before routing, authorization, and body parsing for owned routes. Authorization runs before body parsing and tool work. Mount combined handlers at the application root before JSON middleware. Node middleware delegates unrelated paths to a supplied next callback without consuming the body. Without that callback, unmatched paths return 404.