chore: import upstream snapshot with attribution
Deploy Docs / deploy-docs (push) Failing after 1s
Conformance Tests / client-conformance (push) Failing after 3s
Conformance Tests / server-conformance (push) Failing after 1s
GitHub Actions Security Analysis / zizmor (push) Failing after 1s
CI / checks (push) Failing after 59m20s
CI / all-green (push) Has been cancelled
Deploy Docs / deploy-docs (push) Failing after 1s
Conformance Tests / client-conformance (push) Failing after 3s
Conformance Tests / server-conformance (push) Failing after 1s
GitHub Actions Security Analysis / zizmor (push) Failing after 1s
CI / checks (push) Failing after 59m20s
CI / all-green (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
"""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
|
||||
"""
|
||||
|
||||
import contextlib
|
||||
|
||||
from starlette.applications import Starlette
|
||||
from starlette.routing import Host
|
||||
|
||||
from mcp.server.mcpserver import MCPServer
|
||||
|
||||
# Create MCP server
|
||||
mcp = MCPServer("MCP Host App")
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
def domain_info() -> str:
|
||||
"""Get domain-specific information"""
|
||||
return "This is served from mcp.acme.corp"
|
||||
|
||||
|
||||
# Create a lifespan context manager to run the session manager
|
||||
@contextlib.asynccontextmanager
|
||||
async def lifespan(app: Starlette):
|
||||
async with mcp.session_manager.run():
|
||||
yield
|
||||
|
||||
|
||||
# Mount using Host-based routing
|
||||
# Transport-specific options are passed to streamable_http_app()
|
||||
app = Starlette(
|
||||
routes=[
|
||||
Host("mcp.acme.corp", app=mcp.streamable_http_app(json_response=True)),
|
||||
],
|
||||
lifespan=lifespan,
|
||||
)
|
||||
Reference in New Issue
Block a user