Better CORS defaults for SSE transport #187
Copy link
Copy link
Closed
Labels
P1Significant bug affecting many users, highly requested featureSignificant bug affecting many users, highly requested featureenhancementRequest for a new feature that's not currently supportedRequest for a new feature that's not currently supportedneeds decisionIssue is actionable, needs maintainer decision on whether to implementIssue is actionable, needs maintainer decision on whether to implement
Description
It's likely that most MCP servers accessible over SSE should be contactable by frontend web applications, which means the right CORS headers need to be set. The SDK should likely opt-in to this by default, with an opt-out available.
See also modelcontextprotocol/typescript-sdk#143.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P1Significant bug affecting many users, highly requested featureSignificant bug affecting many users, highly requested featureenhancementRequest for a new feature that's not currently supportedRequest for a new feature that's not currently supportedneeds decisionIssue is actionable, needs maintainer decision on whether to implementIssue is actionable, needs maintainer decision on whether to implement
Activity
panz2018 commentedon Mar 10, 2025
I have developed web servers that integrate MCP SSE functionality:
These servers can be extended with custom routes while retaining full MCP SSE capabilities. Thus, it is possible to add CORS or any other functions using FastAPI or Starlette functions.
ezyang commentedon Apr 12, 2025
Even if the default isn't changed, there should be some way to set it from
mcp run. Otherwise the built in serving commands are just fundamentally not serious for real use.ezyang commentedon Apr 13, 2025
It's so easy to just hard code your own SSE server though... the missed opportunity here is ensuring all MCP's have a standardized way to do the SSE server
ewfian commentedon Jun 22, 2025
Workaround
I've created a working solution by subclassing
FastMCPto add CORS middleware support for both SSE and StreamableHTTP transports:This approach:
Testing results:
This could serve as a reference for implementing CORS defaults in the SDK itself.
informatica92 commentedon Feb 10, 2026
I recently faced the same issue (trying to connect an "sse" server using the official MCP Inspector).
This workaround solves the issue.
Kludex commentedon Apr 22, 2026
I don't think CORS should be enabled by default.
informatica92 commentedon Apr 23, 2026
I totally agree with you. Anyway I think that CORS should be easly enabled using the SDK (with a dedicated method, parameter or whatever). Makes no much sense to me to force developers to always extend the FastMCP class as described above to enable them
Kludex commentedon Apr 23, 2026
You can retrieve the ASGI app and apply the
CORSMiddleware. If we don't have that documented, we should.