import asyncio import nest_asyncio from mcp import ClientSession from mcp.client.sse import sse_client nest_asyncio.apply() # Needed to run interactive python """ Make sure: 1. The server is running before running this script. 2. The server is configured to use SSE transport. 3. The server is listening on port 8050. To run the server: uv run server.py """ async def main(): # Connect to the server using SSE async with sse_client("http://localhost:8050/sse") as (read_stream, write_stream): async with ClientSession(read_stream, write_stream) as session: # Initialize the connection await session.initialize() # List available tools tools_result = await session.list_tools() print("Available tools:") for tool in tools_result.tools: print(f" - {tool.name}: {tool.description}") # List available prompts prompts_result = await session.list_prompts() print(f"\nAvailable prompts ({len(prompts_result.prompts)}):") for prompt in prompts_result.prompts: print(f" - {prompt.name}: {prompt.description}") # List available resources resources_result = await session.list_resources() print(f"\nAvailable resources ({len(resources_result.resources)}):") for resource in resources_result.resources: print(f" - {resource.uri}: {resource.name}") if resource.description: print(f" Description: {resource.description}") if hasattr(resource, 'mime_type') and resource.mime_type: print(f" MIME Type: {resource.mime_type}") # Test a simple tool call (if any tools are available) if tools_result.tools: print(f"\nTesting tool execution with '{tools_result.tools[0].name}':") try: # Try to call the first available tool with empty arguments to see what happens result = await session.call_tool(tools_result.tools[0].name, arguments={}) print(f"Tool result: {result.content[0].text if result.content else 'No content'}") except Exception as e: print(f"Tool execution failed: {e}") else: print("\nNo tools available to test.") if __name__ == "__main__": asyncio.run(main())