mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2026-01-09 08:54:20 +01:00
Add mount_path support for proper SSE endpoint routing with multiple FastMCP servers (#540)
Co-authored-by: ihrpr <inna.hrpr@gmail.com>
This commit is contained in:
37
README.md
37
README.md
@@ -410,6 +410,43 @@ app = Starlette(
|
||||
app.router.routes.append(Host('mcp.acme.corp', app=mcp.sse_app()))
|
||||
```
|
||||
|
||||
When mounting multiple MCP servers under different paths, you can configure the mount path in several ways:
|
||||
|
||||
```python
|
||||
from starlette.applications import Starlette
|
||||
from starlette.routing import Mount
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
|
||||
# Create multiple MCP servers
|
||||
github_mcp = FastMCP("GitHub API")
|
||||
browser_mcp = FastMCP("Browser")
|
||||
curl_mcp = FastMCP("Curl")
|
||||
search_mcp = FastMCP("Search")
|
||||
|
||||
# Method 1: Configure mount paths via settings (recommended for persistent configuration)
|
||||
github_mcp.settings.mount_path = "/github"
|
||||
browser_mcp.settings.mount_path = "/browser"
|
||||
|
||||
# Method 2: Pass mount path directly to sse_app (preferred for ad-hoc mounting)
|
||||
# This approach doesn't modify the server's settings permanently
|
||||
|
||||
# Create Starlette app with multiple mounted servers
|
||||
app = Starlette(
|
||||
routes=[
|
||||
# Using settings-based configuration
|
||||
Mount("/github", app=github_mcp.sse_app()),
|
||||
Mount("/browser", app=browser_mcp.sse_app()),
|
||||
# Using direct mount path parameter
|
||||
Mount("/curl", app=curl_mcp.sse_app("/curl")),
|
||||
Mount("/search", app=search_mcp.sse_app("/search")),
|
||||
]
|
||||
)
|
||||
|
||||
# Method 3: For direct execution, you can also pass the mount path to run()
|
||||
if __name__ == "__main__":
|
||||
search_mcp.run(transport="sse", mount_path="/search")
|
||||
```
|
||||
|
||||
For more information on mounting applications in Starlette, see the [Starlette documentation](https://www.starlette.io/routing/#submounting-routes).
|
||||
|
||||
#### Message Dispatch Options
|
||||
|
||||
Reference in New Issue
Block a user