Skip to content

feat(mcp): add CORS support for browser-based MCP clients#3549

Open
aditya520 wants to merge 1 commit intomainfrom
mcp/add-cors-support
Open

feat(mcp): add CORS support for browser-based MCP clients#3549
aditya520 wants to merge 1 commit intomainfrom
mcp/add-cors-support

Conversation

@aditya520
Copy link
Member

@aditya520 aditya520 commented Mar 13, 2026

Summary

  • Add permissive CORS headers (Access-Control-Allow-Origin: *) to the /mcp HTTP endpoint, matching monorepo precedent (Hermes/Argus use CorsLayer::permissive())
  • Handle OPTIONS preflight requests with a 204 response and appropriate CORS headers
  • Expose Mcp-Session-Id header for browser-based stateful MCP clients (e.g. Claude.ai)
  • Bump version 0.1.00.2.0

Context

The MCP server is being submitted to an MCP server directory. Browser-based clients making cross-origin requests to mcp.pyth.network require CORS headers — without them, browsers silently block all requests. The MCP SDK's deprecated allowedOrigins config only validates origins but does not set CORS response headers; SDK docs recommend external middleware.

Test plan

  • pnpm --filter @pythnetwork/mcp build passes
  • pnpm --filter @pythnetwork/mcp test:unit — all 132 tests pass
  • Manual curl verification against local dev server:
    • curl -X OPTIONS -H "Origin: https://claude.ai" http://localhost:8080/mcp -D - → 204 with CORS headers
    • curl -X POST -H "Origin: https://claude.ai" -H "Content-Type: application/json" -H "Accept: application/json" -d '{"jsonrpc":"2.0","method":"tools/list","id":1}' http://localhost:8080/mcp -D - → 200 with CORS headers

🤖 Generated with Claude Code


Open with Devin

Enable cross-origin requests to the /mcp endpoint so browser-based
clients (e.g. Claude.ai) can connect. Uses permissive CORS (Allow-Origin: *)
matching monorepo precedent (Hermes/Argus). Handles OPTIONS preflight
and exposes Mcp-Session-Id header for stateful clients.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@aditya520 aditya520 requested a review from a team as a code owner March 13, 2026 22:26
@vercel
Copy link

vercel bot commented Mar 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

7 Skipped Deployments
Project Deployment Actions Updated (UTC)
api-reference Skipped Skipped Mar 13, 2026 10:26pm
component-library Skipped Skipped Mar 13, 2026 10:26pm
developer-hub Skipped Skipped Mar 13, 2026 10:26pm
entropy-explorer Skipped Skipped Mar 13, 2026 10:26pm
insights Skipped Skipped Mar 13, 2026 10:26pm
proposals Skipped Skipped Mar 13, 2026 10:26pm
staking Skipped Skipped Mar 13, 2026 10:26pm

Request Review

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

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