Skip to content

Commit 0130f5b

Browse files
authored
Add streamable HTTP starlette example to Python SDK docs (#1111)
1 parent eb5146d commit 0130f5b

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,10 +943,35 @@ The streamable HTTP transport supports:
943943

944944
### Mounting to an Existing ASGI Server
945945

946-
> **Note**: SSE transport is being superseded by [Streamable HTTP transport](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http).
947-
948946
By default, SSE servers are mounted at `/sse` and Streamable HTTP servers are mounted at `/mcp`. You can customize these paths using the methods described below.
949947

948+
#### Streamable HTTP servers
949+
950+
The following example shows how to use `streamable_http_app()`, a method that returns a `Starlette` application object.
951+
You can then append additional routes to that application as needed.
952+
953+
```
954+
from starlette.routing import Route
955+
956+
mcp = FastMCP("My App")
957+
958+
app = mcp.streamable_http_app()
959+
# Additional non-MCP routes can be added like so:
960+
# app.router.routes.append(Route("/", endpoint=other_route_function))
961+
```
962+
963+
To customize the route from the default of "/mcp", either specify the `streamable_http_path` option for the `FastMCP` constructor,
964+
or set `FASTMCP_STREAMABLE_HTTP_PATH` environment variable.
965+
966+
Note that in Starlette and FastAPI (which is based on Starlette), the "/mcp" route will redirect to "/mcp/",
967+
so you may need to use "/mcp/" when pointing MCP clients at your servers.
968+
969+
For more information on mounting applications in Starlette, see the [Starlette documentation](https://www.starlette.io/routing/#submounting-routes).
970+
971+
#### SSE servers
972+
973+
> **Note**: SSE transport is being superseded by [Streamable HTTP transport](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http).
974+
950975
You can mount the SSE server to an existing ASGI server using the `sse_app` method. This allows you to integrate the SSE server with other ASGI applications.
951976

952977
```python

0 commit comments

Comments
 (0)