From ac252fc28f97182c1794e70cbd1cf2687d85c81d Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Fri, 20 Jun 2025 12:18:51 -0400 Subject: [PATCH] Fix CORS documentation example to properly handle preflight requests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- CLAUDE.md | 7 ++++++- docs/deployment/asgi.mdx | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 24f9846b1..1da059260 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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() -``` \ No newline at end of file +``` + +## 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. \ No newline at end of file diff --git a/docs/deployment/asgi.mdx b/docs/deployment/asgi.mdx index 06da46374..56947cde9 100644 --- a/docs/deployment/asgi.mdx +++ b/docs/deployment/asgi.mdx @@ -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