Something went wrong. Try again.
mirror of github.com/PrefectHQ/fastmcp
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253"""Example: Client using resources-as-tools.
This client demonstrates calling the list_resources and read_resource toolsgenerated by the ResourcesAsTools transform.
Run with: uv run python examples/resources_as_tools/client.py"""
import asyncioimport 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())