-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathclient.py
More file actions
41 lines (31 loc) · 1.92 KB
/
Copy pathclient.py
File metadata and controls
41 lines (31 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""Connect to the same server factory twice — once per era, so `main` takes `targets` — and assert both are served."""
import mcp_types as types
from mcp_types.version import LATEST_HANDSHAKE_VERSION, LATEST_MODERN_VERSION
from mcp.client import Client
from stories._harness import TargetFactory, run_client
async def main(targets: TargetFactory, *, mode: str = "auto") -> None:
# ── modern arm: the caller's mode (the real-user "auto" default) probes
# ``server/discover`` and adopts the result — no ``initialize`` handshake runs.
# The version/info/capabilities accessors are era-neutral.
async with Client(targets(), mode=mode) as modern:
assert modern.protocol_version == LATEST_MODERN_VERSION
assert modern.server_info.name == "dual-era-example"
assert modern.server_capabilities.tools is not None
listed = await modern.list_tools()
assert [t.name for t in listed.tools] == ["greet"]
result = await modern.call_tool("greet", {"name": "2026 client"})
first = result.content[0]
assert isinstance(first, types.TextContent)
assert first.text == f"Hello, 2026 client! (served on the modern era at {LATEST_MODERN_VERSION})"
# ── legacy arm: a fresh connection to the SAME server, pinned to the handshake era.
# The same accessors are populated identically — here by ``initialize``.
async with Client(targets(), mode="legacy") as legacy:
assert legacy.protocol_version == LATEST_HANDSHAKE_VERSION
assert legacy.server_info.name == "dual-era-example"
assert legacy.server_capabilities.tools is not None
result = await legacy.call_tool("greet", {"name": "2025 client"})
first = result.content[0]
assert isinstance(first, types.TextContent)
assert first.text == f"Hello, 2025 client! (served on the legacy era at {LATEST_HANDSHAKE_VERSION})"
if __name__ == "__main__":
run_client(main)