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
26 lines
958 B
Python
26 lines
958 B
Python
"""One MCPServer factory that serves both the 2025 handshake era and the 2026 stateless era."""
|
|
|
|
from mcp_types.version import MODERN_PROTOCOL_VERSIONS
|
|
|
|
from mcp.server.mcpserver import Context, MCPServer
|
|
from stories._hosting import run_server_from_args
|
|
|
|
|
|
def build_server() -> MCPServer:
|
|
# The same factory serves both eras with no configuration. Which era a request is
|
|
# on is decided by the entry point / transport, never by the server.
|
|
mcp = MCPServer("dual-era-example", instructions="A small dual-era demo server.")
|
|
|
|
@mcp.tool()
|
|
async def greet(name: str, ctx: Context) -> str:
|
|
"""Greet the caller and report which protocol era served the request."""
|
|
pv = ctx.request_context.protocol_version
|
|
era = "modern" if pv in MODERN_PROTOCOL_VERSIONS else "legacy"
|
|
return f"Hello, {name}! (served on the {era} era at {pv})"
|
|
|
|
return mcp
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run_server_from_args(build_server)
|