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
Fix CORS middleware implementation to wrap entire application
- Change from add_middleware() to CORSMiddleware wrapper pattern
- Ensures 500 errors get proper CORS headers for browser clients
- Update both streamable HTTP example servers
- Fix README documentation to show complete example
Reported-by: Jerome
Copy file name to clipboardExpand all lines: README.md
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -718,11 +718,15 @@ The streamable HTTP transport supports:
718
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
719
720
720
```python
721
+
from starlette.applications import Starlette
721
722
from starlette.middleware.cors import CORSMiddleware
722
723
723
-
# Add CORS middleware to your Starlette app
724
-
app = CORSMiddleware(
725
-
app,
724
+
# Create your Starlette app first
725
+
starlette_app = Starlette(routes=[...])
726
+
727
+
# Then wrap it with CORS middleware
728
+
starlette_app = CORSMiddleware(
729
+
starlette_app,
726
730
allow_origins=["*"], # Configure appropriately for production
0 commit comments