fix: allow mcp-protocol-version request header in CORS preflight - #137
Open
shoemoney wants to merge 1 commit into
Open
fix: allow mcp-protocol-version request header in CORS preflight#137shoemoney wants to merge 1 commit into
shoemoney wants to merge 1 commit into
Conversation
The cors() options already expose mcp-protocol-version via exposedHeaders, but allowedHeaders omitted it. The official StreamableHTTPClientTransport sends mcp-protocol-version on every request after initialize, so any browser-based client permitted via ALLOWED_ORIGINS failed the CORS preflight once initialization completed. Add the header to allowedHeaders in the server and in the mirrored transport test fixture, and add a preflight regression test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The cors() options in src/http.ts list
mcp-protocol-versioninexposedHeadersbut omit it fromallowedHeaders, which only permitsContent-Typeandmcp-session-id. The official @modelcontextprotocol/sdk StreamableHTTPClientTransport sends themcp-protocol-versionheader on every request after initialization, so a browser-based client permitted via ALLOWED_ORIGINS (per SECURITY.md) completes initialize and then fails every subsequent request at the CORS preflight.Since
exposedHeadersalready lists the header, the intent to support it is clear. This adds it toallowedHeadersin the server and in the mirrored fixture in src/transport.test.ts, plus a preflight regression test in src/http.config.test.ts assertingAccess-Control-Allow-Headersincludesmcp-protocol-version.Full suite passes (90 tests) and tsc builds clean.