Files
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 12:10:27 +08:00

38 lines
1.0 KiB
Python

"""Tools primitive: register, list, call, structured output, annotations."""
from typing import Literal
from mcp_types import ToolAnnotations
from pydantic import BaseModel
from mcp.server.mcpserver import MCPServer
from stories._hosting import run_server_from_args
class CalcResult(BaseModel):
op: str
result: float
def build_server() -> MCPServer:
mcp = MCPServer("tools-example")
@mcp.tool(
title="Calculator",
description="Apply an arithmetic operation to two numbers.",
annotations=ToolAnnotations(read_only_hint=True, idempotent_hint=True),
)
def calc(op: Literal["add", "sub", "mul"], a: float, b: float) -> CalcResult:
result = a + b if op == "add" else a - b if op == "sub" else a * b
return CalcResult(op=op, result=result)
@mcp.tool(description="Echo the input back as plain text.", structured_output=False)
def echo(text: str) -> str:
return text
return mcp
if __name__ == "__main__":
run_server_from_args(build_server)