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_host_mounting.py
Normal file
28
examples/snippets/servers/streamable_http_host_mounting.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
"""
|
||||
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")
|
||||
|
||||
|
||||
@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()),
|
||||
]
|
||||
)
|
||||
Loading…
Reference in a new issue