@@ -902,22 +902,23 @@ if __name__ == "__main__":
902902_ Full example: [ examples/snippets/servers/streamable_config.py] ( https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/servers/streamable_config.py ) _
903903<!-- /snippet-source -->
904904
905- You can mount multiple FastMCP servers in a FastAPI application:
905+ You can mount multiple FastMCP servers in a Starlette application:
906906
907- <!-- snippet-source examples/snippets/servers/streamable_fastapi_mount .py -->
907+ <!-- snippet-source examples/snippets/servers/streamable_starlette_mount .py -->
908908``` python
909- """ Example of mounting multiple FastMCP servers in a FastAPI application.
909+ """ Example of mounting multiple FastMCP servers in a Starlette application.
910910
911911This example shows how to create multiple MCP servers and mount them
912- at different endpoints in a single FastAPI application.
912+ at different endpoints in a single Starlette application.
913913
914914Run from the repository root:
915- uvicorn examples.snippets.servers.streamable_fastapi_mount :app --reload
915+ uvicorn examples.snippets.servers.streamable_starlette_mount :app --reload
916916"""
917917
918918import contextlib
919919
920- from fastapi import FastAPI
920+ from starlette.applications import Starlette
921+ from starlette.routing import Mount
921922
922923from mcp.server.fastmcp import FastMCP
923924
@@ -943,20 +944,24 @@ def add_two(n: int) -> int:
943944
944945# Create a combined lifespan to manage both session managers
945946@contextlib.asynccontextmanager
946- async def lifespan (app : FastAPI ):
947+ async def lifespan (app ):
947948 async with contextlib.AsyncExitStack() as stack:
948949 await stack.enter_async_context(echo_mcp.session_manager.run())
949950 await stack.enter_async_context(math_mcp.session_manager.run())
950951 yield
951952
952953
953- # Create the FastAPI app and mount the MCP servers
954- app = FastAPI(lifespan = lifespan)
955- app.mount(" /echo" , echo_mcp.streamable_http_app())
956- app.mount(" /math" , math_mcp.streamable_http_app())
954+ # Create the Starlette app and mount the MCP servers
955+ app = Starlette(
956+ routes = [
957+ Mount(" /echo" , echo_mcp.streamable_http_app()),
958+ Mount(" /math" , math_mcp.streamable_http_app()),
959+ ],
960+ lifespan = lifespan,
961+ )
957962```
958963
959- _ Full example: [ examples/snippets/servers/streamable_fastapi_mount .py] ( https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/servers/streamable_fastapi_mount .py ) _
964+ _ Full example: [ examples/snippets/servers/streamable_starlette_mount .py] ( https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/servers/streamable_starlette_mount .py ) _
960965<!-- /snippet-source -->
961966
962967For low level server with Streamable HTTP implementations, see:
0 commit comments