quick_test_server.pyโข2.73 kB
#!/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())