|
| 1 | +from fastmcp import Client |
| 2 | +from mcp_debugger import mcp |
| 3 | +import asyncio |
| 4 | +import json |
| 5 | + |
| 6 | +async def main(): |
| 7 | + # client = Client(mcp) # This works according to overload signatures! |
| 8 | + |
| 9 | + # Using 'with' context manager for automatic connection/cleanup |
| 10 | + # Note: Client might be async. Let's assume standard usage pattern. |
| 11 | + # FastMCP client docs usually imply sync usage for simple scripts or async. |
| 12 | + # Given the __init__ signature didn't show async, but `run_async` did... |
| 13 | + # The overload `Client(transport: FastMCP)` returns a Client. |
| 14 | + |
| 15 | + print("Connecting to MCP Server...") |
| 16 | + async with Client(mcp) as client: |
| 17 | + print("\n--- Listing Tools ---") |
| 18 | + tools = await client.list_tools() |
| 19 | + for tool in tools: |
| 20 | + print(f"- {tool.name}: {tool.description}") |
| 21 | + |
| 22 | + print("\n--- Calling get_database_stats ---") |
| 23 | + result = await client.call_tool("get_database_stats") |
| 24 | + # FastMCP CallToolResult usually has 'content' or is iterable? |
| 25 | + # Let's print the raw result to see what we got |
| 26 | + print(f"Result type: {type(result)}") |
| 27 | + print(f"Result content: {result}") |
| 28 | + |
| 29 | + # If it has content, usually it's a list of TextContent or ImageContent path |
| 30 | + if hasattr(result, 'content'): |
| 31 | + for content in result.content: |
| 32 | + if hasattr(content, 'text'): |
| 33 | + print(content.text) |
| 34 | + |
| 35 | + print(f"\n--- Calling get_recent_events (limit=2) ---") |
| 36 | + result_events = await client.call_tool("get_recent_events", arguments={"limit": 2}) |
| 37 | + if hasattr(result_events, 'content'): |
| 38 | + for content in result_events.content: |
| 39 | + if hasattr(content, 'text'): |
| 40 | + print(content.text) |
| 41 | + |
| 42 | +if __name__ == "__main__": |
| 43 | + asyncio.run(main()) |
0 commit comments