Files
modelcontextprotocol--pytho…/examples/stories/middleware/client.py
T
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) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:10:27 +08:00

28 lines
1.2 KiB
Python

"""Prove the middleware wrapped both `tools/list` and the in-flight `tools/call`."""
from mcp.client import Client
from stories._harness import Target, run_client
async def main(target: Target, *, mode: str = "auto") -> None:
async with Client(target, mode=mode) as client:
listed = await client.list_tools()
assert [t.name for t in listed.tools] == ["audit_log"]
result = await client.call_tool("audit_log", {})
assert not result.is_error
assert result.structured_content is not None, result
# Era-neutral: legacy adds initialize + notifications/initialized; modern HTTP
# adds server/discover; modern in-memory adds nothing. Filter to the methods
# this client drove.
seen = [m for m in result.structured_content["result"] if m.startswith("tools/")]
# The tail ends at tools/call with no :done — the handler ran inside the
# middleware frame. Assert the tail (not the whole list) so a re-run against
# a long-lived server, whose log accumulates across clients, still passes.
assert seen[-3:] == ["tools/list", "tools/list:done", "tools/call"], seen
if __name__ == "__main__":
run_client(main)