python-sdk/examples/snippets/servers/streamable_http_basic_mounting.py
adam jones fcffa14b5b
Some checks failed
Main branch checks / checks (push) Has been cancelled
docs: Update examples to use stateless HTTP with JSON responses (#1499)
2025-11-20 15:06:37 +00:00

28 lines
625 B
Python

"""
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", json_response=True)
@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()),
]
)