#!/usr/bin/env python3
"""
Quick test to verify the MCP server is working properly
"""
import asyncio
import json
import sys
from pathlib import Path
# Add src to path
sys.path.insert(0, str(Path(__file__).parent / "src"))
async def quick_test():
"""Quick test of the MCP server."""
print("π§ͺ Quick MCP Server Test")
print("=" * 30)
try:
# Connect to server
print("π‘ Connecting to localhost:8000...")
reader, writer = await asyncio.open_connection("localhost", 8000)
print("β
Connected!")
# Send initialization
init_request = {
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {"name": "Test", "version": "1.0"}
}
}
print("π€ Sending initialization...")
writer.write(json.dumps(init_request).encode())
await writer.drain()
# Read response
data = await reader.read(1024)
response = json.loads(data.decode())
if "result" in response:
print("β
Initialization successful!")
# Test tools list
tools_request = {
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list",
"params": {}
}
print("π€ Sending tools/list...")
writer.write(json.dumps(tools_request).encode())
await writer.drain()
# Read response
data = await reader.read(1024)
if data:
response = json.loads(data.decode())
print("π₯ Tools response received!")
if "result" in response and "tools" in response["result"]:
tools = response["result"]["tools"]
print(f"β
Found {len(tools)} tools:")
for tool in tools:
print(f" - {tool.get('name', 'unknown')}")
else:
print("β οΈ No tools in response")
else:
print("β οΈ No response from tools/list")
else:
print("β Initialization failed!")
# Close connection
writer.close()
await writer.wait_closed()
print("β
Test completed!")
except Exception as e:
print(f"β Error: {e}")
if __name__ == "__main__":
asyncio.run(quick_test())