client.pyโข2.05 kB
#!/usr/bin/env python3
"""
Simple FastMCP Client Test
Uses FastMCP's built-in Client to test your server
"""
import asyncio
import sys
from fastmcp import Client
async def test_server(server_url):
"""Test your FastMCP server"""
print(f"Testing server: {server_url}")
async with Client(server_url) as client:
print("โ
Connected!")
tools = await client.list_tools()
resources = await client.list_resources()
resource_templates = await client.list_resource_templates()
print(f"\n๐ฆ Found {len(tools)} tools:")
print(f"\n๐ฆ Found {len(resources)} resources:")
print(f"\n๐ฆ Found {len(resource_templates)} resource templates:")
for resource in resources:
print(f" ๐ {resource.name}: {resource.description}")
for tool in tools:
print(f" ๐ง {tool.name}: {tool.description}")
# Test the first tool with empty args
# if tools:
# tool = tools[0]
# print(f"\n๐งช Testing '{tool.name}'...")
#
# # Provide sample arguments based on tool name
# args = {}
# if tool.name == "process_data":
# args = {"uri": "https://example.com/sample.txt"}
#
# try:
# result = await client.call_tool(tool.name, args)
# print("โ
Success!")
# for content in result:
# print(f" ๐ {content}")
# except Exception as e:
# print(f"โ ๏ธ Error: {e}")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python client.py <host:port>")
print("Example: python client.py localhost:8000")
print("Example: python client.py http://localhost:8000")
sys.exit(1)
server_url = sys.argv[1]
# Add http:// if not present
if not server_url.startswith(('http://', 'https://', 'ws://', 'wss://')):
server_url = f"http://{server_url}"
asyncio.run(test_server(server_url))