python-sdk/examples/snippets/servers/streamable_http_host_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
653 B
Python

"""
Example showing how to mount StreamableHTTP server using Host-based routing.
Run from the repository root:
uvicorn examples.snippets.servers.streamable_http_host_mounting:app --reload
"""
from starlette.applications import Starlette
from starlette.routing import Host
from mcp.server.fastmcp import FastMCP
# Create MCP server
mcp = FastMCP("MCP Host App", json_response=True)
@mcp.tool()
def domain_info() -> str:
"""Get domain-specific information"""
return "This is served from mcp.acme.corp"
# Mount using Host-based routing
app = Starlette(
routes=[
Host("mcp.acme.corp", app=mcp.streamable_http_app()),
]
)