#!/usr/bin/env python3
"""
Test the simple MCP server locally.
"""
import asyncio
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client
async def test_simple_mcp():
"""Test the simple MCP server."""
mcp_url = "http://localhost:8000/mcp"
headers = {}
print(f"Testing simple MCP server at: {mcp_url}")
try:
async with streamablehttp_client(
mcp_url,
headers,
timeout=120,
terminate_on_close=False
) as (read_stream, write_stream, _):
async with ClientSession(read_stream, write_stream) as session:
await session.initialize()
print("✅ Session initialized")
tool_result = await session.list_tools()
print(f"✅ Available tools: {len(tool_result.tools)}")
for tool in tool_result.tools:
print(f" - {tool.name}: {tool.description}")
# Test a tool
result = await session.call_tool("add_numbers", {"a": 5, "b": 3})
print(f"✅ add_numbers(5, 3) = {result.content[0].text}")
except Exception as e:
print(f"❌ Error: {e}")
if __name__ == "__main__":
asyncio.run(test_simple_mcp())