docs: clarify streamable_http_path configuration when mounting servers (#1172)
This commit is contained in:
parent
824ef8a281
commit
ff02c596a4
1 changed files with 302 additions and 0 deletions
28
examples/snippets/servers/streamable_http_basic_mounting.py
Normal file
28
examples/snippets/servers/streamable_http_basic_mounting.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
"""
|
||||
Basic example showing how to mount StreamableHTTP server in Starlette.
|
||||
|
||||
Run from the repository root:
|
||||
uvicorn examples.snippets.servers.streamable_http_basic_mounting:app --reload
|
||||
"""
|
||||
|
||||
from starlette.applications import Starlette
|
||||
from starlette.routing import Mount
|
||||
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
|
||||
# Create MCP server
|
||||
mcp = FastMCP("My App")
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
def hello() -> str:
|
||||
"""A simple hello tool"""
|
||||
return "Hello from MCP!"
|
||||
|
||||
|
||||
# Mount the StreamableHTTP server to the existing ASGI server
|
||||
app = Starlette(
|
||||
routes=[
|
||||
Mount("/", app=mcp.streamable_http_app()),
|
||||
]
|
||||
)
|
||||
Loading…
Reference in a new issue