Skip to content

docs(csp-cors): document CORS headers for the MCP endpoint in browser-based hosts - #801

Open
sja-thedude wants to merge 1 commit into
modelcontextprotocol:mainfrom
sja-thedude:docs/cors-for-browser-hosts
Open

sja-thedude wants to merge 1 commit into
modelcontextprotocol:mainfrom
sja-thedude:docs/cors-for-browser-hosts

Conversation

@sja-thedude

Copy link
Copy Markdown

Summary

docs/csp-cors.md covers CORS for requests an app makes from its iframe, but not the other boundary: a browser-based host (examples/basic-host, web inspectors, web assistants) calling the MCP endpoint cross-origin. This adds a short section for that case.

Why

The Express examples use app.use(cors()), which reflects requested headers, so they work. Servers that hand-roll CORS around createMcpHandler (Cloudflare Workers, Deno, Bun) usually allow-list headers explicitly. On 2026-07-28 exchanges the TypeScript client also sends Mcp-Method and Mcp-Name (SEP-2243). If those are missing, the preflight fails with "Request header field mcp-method is not allowed by Access-Control-Allow-Headers", and a client using versionNegotiation: { mode: "auto" } silently falls back to the 2025 handshake or fails to connect. I hit this when a browser-based host connected to a Worker-hosted MCP Apps server.

Changes

  • A new "CORS for the MCP endpoint itself" section in docs/csp-cors.md: when it applies, a table of the request headers the client sends and when, and a minimal fetch-handler example.
  • Docs only, no code changes. Prettier passes.

Header names were checked against @modelcontextprotocol/client 2.1 (RESERVED_REQUEST_HEADER_NAMES and _applyBodyDerivedHeaders in the Streamable HTTP transport).

…-based hosts

Browser-based hosts (basic-host, web inspectors, web assistants) call the MCP
endpoint cross-origin. Servers that hand-roll CORS around createMcpHandler must
allow the SEP-2243 headers Mcp-Method and Mcp-Name, or the 2026-07-28 preflight
fails and clients fall back to the 2025 handshake.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant