49b9bb6724
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
32 lines
860 B
Python
32 lines
860 B
Python
"""Example showing path configuration when mounting MCPServer.
|
|
|
|
Run from the repository root:
|
|
uvicorn examples.snippets.servers.streamable_http_path_config:app --reload
|
|
"""
|
|
|
|
from starlette.applications import Starlette
|
|
from starlette.routing import Mount
|
|
|
|
from mcp.server.mcpserver import MCPServer
|
|
|
|
# Create a simple MCPServer server
|
|
mcp_at_root = MCPServer("My Server")
|
|
|
|
|
|
@mcp_at_root.tool()
|
|
def process_data(data: str) -> str:
|
|
"""Process some data"""
|
|
return f"Processed: {data}"
|
|
|
|
|
|
# Mount at /process with streamable_http_path="/" so the endpoint is /process (not /process/mcp)
|
|
# Transport-specific options like json_response are passed to streamable_http_app()
|
|
app = Starlette(
|
|
routes=[
|
|
Mount(
|
|
"/process",
|
|
app=mcp_at_root.streamable_http_app(json_response=True, streamable_http_path="/"),
|
|
),
|
|
]
|
|
)
|