mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-23 22:14:18 +02:00
Fix CORS documentation example to properly handle preflight requests
The previous example only allowed GET methods, causing browser preflight requests to fail with "Disallowed CORS method" errors. Updated to include the required parameters for proper CORS support with MCP clients. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
a0242e1c68
commit
ac252fc28f
2 changed files with 13 additions and 2 deletions
|
|
@ -27,4 +27,9 @@ Only use HTTP transport when testing network-specific features. Prefer Streamabl
|
|||
# Only when network testing is required
|
||||
async with Client(transport=StreamableHttpTransport(server_url)) as client:
|
||||
result = await client.ping()
|
||||
```
|
||||
```
|
||||
|
||||
## Development Workflow
|
||||
|
||||
- You must always run pre-commit if you open a PR, because it is run as part of a required check.
|
||||
- When opening PRs, apply labels appropriately for bugs/breaking changes/enhancements/features. Generally, improvements are enhancements (not features) unless told otherwise.
|
||||
|
|
@ -96,7 +96,13 @@ mcp = FastMCP("MyServer")
|
|||
|
||||
# Define custom middleware
|
||||
custom_middleware = [
|
||||
Middleware(CORSMiddleware, allow_origins=["*"]),
|
||||
Middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["https://example.com", "https://app.example.com"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["GET", "POST", "OPTIONS"],
|
||||
allow_headers=["Content-Type", "Authorization"],
|
||||
),
|
||||
]
|
||||
|
||||
# Create ASGI app with custom middleware
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue