mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-28 02:10:38 +02:00
docs: Add AWS Cognito resource server requirement and CORS guidance (#2149)
This commit is contained in:
parent
24e2b09d95
commit
09e899a699
3 changed files with 24 additions and 13 deletions
|
|
@ -407,6 +407,12 @@ app.mount("/mcp", mcp.http_app()) # Session manager won't initialize
|
|||
|
||||
If you're mounting an authenticated MCP server under a path prefix, see [Mounting Authenticated Servers](/deployment/http#mounting-authenticated-servers) for important OAuth routing considerations.
|
||||
|
||||
### CORS Middleware
|
||||
|
||||
If your FastAPI app uses `CORSMiddleware` and you're mounting an OAuth-protected FastMCP server, avoid adding application-wide CORS middleware. FastMCP and the MCP SDK already handle CORS for OAuth routes, and layering CORS middleware can cause conflicts (such as 404 errors on `.well-known` routes or OPTIONS requests).
|
||||
|
||||
If you need CORS on your own FastAPI routes, use the sub-app pattern: mount your API and FastMCP as separate apps, each with their own middleware, rather than adding top-level `CORSMiddleware` to the combined application.
|
||||
|
||||
### Combining Lifespans
|
||||
|
||||
If your FastAPI app already has a lifespan (for database connections, startup tasks, etc.), you can't simply replace it with the MCP lifespan. Instead, you need to create a new lifespan function that manages both contexts. This ensures that both your app's initialization logic and the MCP server's session manager run properly:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue