Files
modelcontextprotocol--pytho…/examples/stories/resources/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) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 12:10:27 +08:00

31 lines
1.1 KiB
Python

"""List resources and templates, then read both the static and templated URIs."""
from mcp_types import TextResourceContents
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_resources()
assert [r.uri for r in listed.resources] == ["config://app"]
templates = await client.list_resource_templates()
assert [t.uri_template for t in templates.resource_templates] == ["greeting://{name}"]
config = await client.read_resource("config://app")
entry = config.contents[0]
assert isinstance(entry, TextResourceContents)
assert entry.text == '{"feature": true}'
assert entry.mime_type == "application/json"
hello = await client.read_resource("greeting://world")
entry = hello.contents[0]
assert isinstance(entry, TextResourceContents)
assert entry.text == "Hello, world!"
if __name__ == "__main__":
run_client(main)