Skip to content

Enable CORS for browser-based auth on MCP HTTP server#55

Open
paulius-krutkis-dcd wants to merge 1 commit into
mainfrom
fix/mcp-cors
Open

Enable CORS for browser-based auth on MCP HTTP server#55
paulius-krutkis-dcd wants to merge 1 commit into
mainfrom
fix/mcp-cors

Conversation

@paulius-krutkis-dcd

@paulius-krutkis-dcd paulius-krutkis-dcd commented Jun 11, 2026

Copy link
Copy Markdown

Summary

  • Add CORS middleware to the HTTP server so browser clients (e.g. Claude Connector) can preflight and send Authorization headers to /mcp.
  • Allow claude.ai, anthropic.com, and local dev origins; deny unknown origins without returning 500.
  • Add unit and integration tests for the origin allowlist and middleware behavior.

Test plan

  • npm test -- --testPathPattern=cors
  • Start locally (npm run build && node build/server.js), then preflight: curl -sI -X OPTIONS http://localhost:3000/mcp -H "Origin: https://claude.ai" -H "Access-Control-Request-Method: POST" -H "Access-Control-Request-Headers: Authorization, Content-Type" — expect 204 with Access-Control-Allow-Origin and Authorization in allowed headers
  • After merge, deploy via GitLab mcp-server-deployer and confirm the same preflight against https://mcp.decodo.com/mcp

- Introduced CORS middleware in the server to handle cross-origin requests.
- Created a new `cors.ts` file to define CORS options and allowed origins.
- Added tests for CORS functionality, ensuring proper handling of allowed and disallowed origins.
- Updated package dependencies to include `cors` and `express`.
@paulius-krutkis-dcd paulius-krutkis-dcd changed the title Add CORS support and related tests Enable CORS for browser-based auth on MCP HTTP server Jun 11, 2026
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.

4 participants