Skip to content

Commit d9fbef4

Browse files
docs: clarify streamable_http_path configuration when mounting servers
- Add StreamableHTTP servers section mirroring SSE servers structure - Start with simple mounting examples, then explain path composition - Document how to configure streamable_http_path for different scenarios - Add inline comments in Starlette mounting example This addresses confusion around endpoint paths when mounting FastMCP servers as sub-applications in ASGI frameworks.
1 parent 0b1b52b commit d9fbef4

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,11 @@ app = Starlette(
979979
],
980980
lifespan=lifespan,
981981
)
982+
983+
# Note: Clients connect to http://localhost:8000/echo/mcp and http://localhost:8000/math/mcp
984+
# To mount at the root of each path (e.g., /echo instead of /echo/mcp):
985+
# echo_mcp.settings.streamable_http_path = "/"
986+
# math_mcp.settings.streamable_http_path = "/"
982987
```
983988

984989
_Full example: [examples/snippets/servers/streamable_starlette_mount.py](https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/servers/streamable_starlette_mount.py)_
@@ -1002,6 +1007,57 @@ By default, SSE servers are mounted at `/sse` and Streamable HTTP servers are mo
10021007

10031008
For more information on mounting applications in Starlette, see the [Starlette documentation](https://www.starlette.io/routing/#submounting-routes).
10041009

1010+
#### StreamableHTTP servers
1011+
1012+
You can mount the StreamableHTTP server to an existing ASGI server using the `streamable_http_app` method. This allows you to integrate the StreamableHTTP server with other ASGI applications.
1013+
1014+
```python
1015+
from starlette.applications import Starlette
1016+
from starlette.routing import Mount, Host
1017+
from mcp.server.fastmcp import FastMCP
1018+
1019+
1020+
mcp = FastMCP("My App")
1021+
1022+
# Mount the StreamableHTTP server to the existing ASGI server
1023+
app = Starlette(
1024+
routes=[
1025+
Mount('/', app=mcp.streamable_http_app()),
1026+
]
1027+
)
1028+
1029+
# or dynamically mount as host
1030+
app.router.routes.append(Host('mcp.acme.corp', app=mcp.streamable_http_app()))
1031+
```
1032+
1033+
When mounting StreamableHTTP servers, be aware that the server's `streamable_http_path` setting (default: `/mcp`) is relative to where you mount the app. For example:
1034+
1035+
```python
1036+
from starlette.applications import Starlette
1037+
from starlette.routing import Mount
1038+
from mcp.server.fastmcp import FastMCP
1039+
1040+
# Create multiple MCP servers
1041+
api_mcp = FastMCP("API Server")
1042+
chat_mcp = FastMCP("Chat Server")
1043+
1044+
# Default behavior: endpoints will be at /api/mcp and /chat/mcp
1045+
app = Starlette(
1046+
routes=[
1047+
Mount("/api", app=api_mcp.streamable_http_app()),
1048+
Mount("/chat", app=chat_mcp.streamable_http_app()),
1049+
]
1050+
)
1051+
1052+
# To mount at the root of each path (e.g., /api instead of /api/mcp):
1053+
# Configure streamable_http_path before mounting
1054+
api_mcp.settings.streamable_http_path = "/"
1055+
chat_mcp.settings.streamable_http_path = "/"
1056+
1057+
# Or configure during initialization
1058+
mcp_at_root = FastMCP("My Server", streamable_http_path="/")
1059+
```
1060+
10051061
#### SSE servers
10061062

10071063
> **Note**: SSE transport is being superseded by [Streamable HTTP transport](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http).

0 commit comments

Comments
 (0)