refactor: move transport-specific parameters from FastMCP constructor to run() (#1898)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Marcelo Trylesinski 2026-01-16 16:16:20 +01:00 • committed by GitHub
commit 8adb5bdce8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,7 +13,7 @@ from starlette.routing import Mount
from mcp.server.fastmcp import FastMCP
# Create MCP server
mcp = FastMCP("My App", json_response=True)
mcp = FastMCP("My App")
@mcp.tool()
@ -30,9 +30,10 @@ async def lifespan(app: Starlette):
# Mount the StreamableHTTP server to the existing ASGI server
# Transport-specific options are passed to streamable_http_app()
app = Starlette(
routes=[
Mount("/", app=mcp.streamable_http_app()),
Mount("/", app=mcp.streamable_http_app(json_response=True)),
],
lifespan=lifespan,
)