Add story-style examples suite (27 stories + harness + CI) (#2957)
This commit is contained in:
parent
9dc8c5f02d
commit
4caa41f6d5
1 changed files with 6801 additions and 26 deletions
30
examples/stories/resources/client.py
Normal file
30
examples/stories/resources/client.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
"""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)
|
||||
Loading…
Reference in a new issue