60e0ffc959
Upgrade checks / Notify on failure (push) Has been cancelled
Upgrade checks / Close issue on success (push) Has been cancelled
Schema Crash Test / Real-world schema crash test (232K schemas) (push) Has been cancelled
Run static analysis / static_analysis (push) Has been cancelled
Tests / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Tests / Tests with lowest-direct dependencies (push) Has been cancelled
Tests / MCP conformance tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
Tests / Package install smoke (push) Has been cancelled
Upgrade checks / Static analysis (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Upgrade checks / Integration tests (push) Has been cancelled
Update MCPServerConfig Schema / update-config-schema (push) Has been cancelled
Update SDK Documentation / update-sdk-docs (push) Has been cancelled
53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
"""Example: Client using resources-as-tools.
|
|
|
|
This client demonstrates calling the list_resources and read_resource tools
|
|
generated by the ResourcesAsTools transform.
|
|
|
|
Run with:
|
|
uv run python examples/resources_as_tools/client.py
|
|
"""
|
|
|
|
import asyncio
|
|
import json
|
|
|
|
from fastmcp.client import Client
|
|
|
|
|
|
async def main():
|
|
# Connect to the server
|
|
async with Client("examples/resources_as_tools/server.py") as client:
|
|
# List all available tools
|
|
print("=== Available Tools ===")
|
|
tools = await client.list_tools()
|
|
for tool in tools:
|
|
print(f" - {tool.name}: {tool.description}")
|
|
print()
|
|
|
|
# Use list_resources tool to see what's available
|
|
print("=== Listing Resources ===")
|
|
result = await client.call_tool("list_resources", {})
|
|
resources = json.loads(result.data)
|
|
for resource in resources:
|
|
if "uri" in resource:
|
|
print(f" Static: {resource['uri']}")
|
|
else:
|
|
print(f" Template: {resource['uri_template']}")
|
|
print(f" Name: {resource['name']}")
|
|
print(f" Description: {resource.get('description', 'N/A')}")
|
|
print()
|
|
|
|
# Read a static resource
|
|
print("=== Reading Static Resource ===")
|
|
result = await client.call_tool("read_resource", {"uri": "config://app"})
|
|
print(f"config://app content:\n{result.data}")
|
|
print()
|
|
|
|
# Read a templated resource
|
|
print("=== Reading Templated Resource ===")
|
|
result = await client.call_tool("read_resource", {"uri": "user://42/profile"})
|
|
print(f"user://42/profile content:\n{result.data}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|