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
@@ -1160,12 +1165,204 @@ The streamable HTTP transport supports:
1160
1165
- JSON or SSE response formats
1161
1166
- Better scalability for multi-node deployments
1162
1167
1168
+
#### CORS Configuration for Browser-Based Clients
1169
+
1170
+
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:
1171
+
1172
+
```python
1173
+
from starlette.applications import Starlette
1174
+
from starlette.middleware.cors import CORSMiddleware
1175
+
1176
+
# Create your Starlette app first
1177
+
starlette_app = Starlette(routes=[...])
1178
+
1179
+
# Then wrap it with CORS middleware
1180
+
starlette_app = CORSMiddleware(
1181
+
starlette_app,
1182
+
allow_origins=["*"], # Configure appropriately for production
- The MCP streamable HTTP transport uses the `Mcp-Session-Id` header for session management
1191
+
- Browsers restrict access to response headers unless explicitly exposed via CORS
1192
+
- Without this configuration, browser-based clients won't be able to read the session ID from initialization responses
1193
+
1163
1194
### Mounting to an Existing ASGI Server
1164
1195
1165
1196
By default, SSE servers are mounted at `/sse` and Streamable HTTP servers are mounted at `/mcp`. You can customize these paths using the methods described below.
1166
1197
1167
1198
For more information on mounting applications in Starlette, see the [Starlette documentation](https://www.starlette.io/routing/#submounting-routes).
1168
1199
1200
+
#### StreamableHTTP servers
1201
+
1202
+
You can mount the StreamableHTTP server to an existing ASGI server using the `streamable_http_app` method. This allows you to integrate the StreamableHTTP server with other ASGI applications.
> **Note**: SSE transport is being superseded by [Streamable HTTP transport](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http).
0 commit comments