You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add CORS configuration for browser-based MCP clients
- Add CORSMiddleware to streamable HTTP example servers
- Configure minimal CORS with Mcp-Session-Id exposed
- Add CORS documentation section to README
This enables browser-based clients to connect to MCP servers by properly
exposing the Mcp-Session-Id header required for session management.
Reported-by: Jerome
Copy file name to clipboardExpand all lines: README.md
+21Lines changed: 21 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -713,6 +713,27 @@ The streamable HTTP transport supports:
713
713
- JSON or SSE response formats
714
714
- Better scalability for multi-node deployments
715
715
716
+
#### CORS Configuration for Browser-Based Clients
717
+
718
+
If you'd like your server to be accessible by browser-based MCP clients, you'll need to configure CORS headers. The `Mcp-Session-Id` header must be exposed for browser clients to access it:
719
+
720
+
```python
721
+
from starlette.middleware.cors import CORSMiddleware
722
+
723
+
# Add CORS middleware to your Starlette app
724
+
app.add_middleware(
725
+
CORSMiddleware,
726
+
allow_origins=["*"], # Configure appropriately for production
- The MCP streamable HTTP transport uses the `Mcp-Session-Id` header for session management
734
+
- Browsers restrict access to response headers unless explicitly exposed via CORS
735
+
- Without this configuration, browser-based clients won't be able to read the session ID from initialization responses
736
+
716
737
### Mounting to an Existing ASGI Server
717
738
718
739
> **Note**: SSE transport is being superseded by [Streamable HTTP transport](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http).
0 commit comments