Add CORS support to MCP HTTP transport#91
Merged
Conversation
Browsers block cross-origin requests to the MCP endpoint because no Access-Control-Allow-Origin header is present. This adds CORS headers to both ServeHTTP (OPTIONS preflight handling) and handlePost (response headers on POST requests) so browser-based MCP clients can connect. https://claude.ai/code/session_01CQTqZnS1nzqy955PBoxbLp
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.
Summary
Add Cross-Origin Resource Sharing (CORS) headers to the MCP HTTP transport layer to enable browser-based clients to communicate with the MCP server. This includes:
ServeHTTPhandlerAccess-Control-Allow-Origin,Access-Control-Allow-Methods,Access-Control-Allow-Headers) for both GET and POST requests*) to allow requests from any domainThis change enables web-based MCP clients to make cross-origin requests without browser CORS restrictions.
Validation
Testing
https://claude.ai/code/session_01CQTqZnS1nzqy955PBoxbLp