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) Waiting to run
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
"""The one-liner HTTP deploy (lowlevel API): Server.streamable_http_app(stateless_http=True)."""
|
|
|
|
from typing import Any
|
|
|
|
import mcp_types as types
|
|
from starlette.applications import Starlette
|
|
|
|
from mcp.server.context import ServerRequestContext
|
|
from mcp.server.lowlevel import Server
|
|
from stories._hosting import NO_DNS_REBIND, run_app_from_args
|
|
|
|
GREET_INPUT_SCHEMA: dict[str, Any] = {
|
|
"type": "object",
|
|
"properties": {"name": {"type": "string"}},
|
|
"required": ["name"],
|
|
}
|
|
|
|
|
|
def build_app() -> Starlette:
|
|
async def list_tools(
|
|
ctx: ServerRequestContext[Any], params: types.PaginatedRequestParams | None
|
|
) -> types.ListToolsResult:
|
|
return types.ListToolsResult(
|
|
tools=[
|
|
types.Tool(name="greet", description="A simple greeting tool.", input_schema=GREET_INPUT_SCHEMA),
|
|
]
|
|
)
|
|
|
|
async def call_tool(ctx: ServerRequestContext[Any], params: types.CallToolRequestParams) -> types.CallToolResult:
|
|
assert params.name == "greet" and params.arguments is not None
|
|
return types.CallToolResult(content=[types.TextContent(text=f"Hello, {params.arguments['name']}!")])
|
|
|
|
server = Server("stateless-legacy-example", on_list_tools=list_tools, on_call_tool=call_tool)
|
|
return server.streamable_http_app(stateless_http=True, transport_security=NO_DNS_REBIND)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run_app_from_args(build_app)
|