File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -404,6 +404,30 @@ mcp = FastMCP("StatelessServer", stateless_http=True)
404404mcp.run(transport = " streamable-http" )
405405```
406406
407+ You can mount multiple FastMCP servers in a FastAPI application:
408+
409+ ``` python
410+ # echo.py
411+ from mcp.server.fastmcp import FastMCP
412+
413+ mcp = FastMCP(name = " EchoServer" , stateless_http = True )
414+
415+ @mcp.tool (description = " A simple echo tool" )
416+ def echo (message : str ) -> str :
417+ return f " Echo: { message} "
418+
419+ # main.py
420+ from fastapi import FastAPI
421+ from routers import echo
422+
423+ app = FastAPI()
424+
425+ # Use the session manager's lifespan
426+ app = FastAPI(lifespan = lambda app : echo.mcp.session_manager.run())
427+ app.mount(" /echo" , echo.mcp.streamable_http_app())
428+
429+ ```
430+
407431For low level server with Streamable HTTP implementations, see:
408432- Stateful server: [ ` examples/servers/simple-streamablehttp/ ` ] ( examples/servers/simple-streamablehttp/ )
409433- Stateless server: [ ` examples/servers/simple-streamablehttp-stateless/ ` ] ( examples/servers/simple-streamablehttp-stateless/ )
You can’t perform that action at this time.
0 commit comments