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
Copy file name to clipboardExpand all lines: README.md
+26Lines changed: 26 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1165,6 +1165,32 @@ The streamable HTTP transport supports:
1165
1165
- JSON or SSE response formats
1166
1166
- Better scalability for multi-node deployments
1167
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
+
1168
1194
### Mounting to an Existing ASGI Server
1169
1195
1170
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.
0 commit comments