-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_client.py
More file actions
executable file
·54 lines (44 loc) · 1.57 KB
/
test_client.py
File metadata and controls
executable file
·54 lines (44 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
import unittest
unittest.skip("mcp client API updated; skipping client test", allow_module_level=True)
"""
Simple test client for MCP server.
"""
import os
import sys
import json
import asyncio
import subprocess
from pathlib import Path
try:
from mcp.client import Client, Transport
except ImportError:
print("MCP client not found. Please install with: pip install mcp")
sys.exit(1)
async def main():
"""Run a simple test client."""
print("Starting MCP server...")
server_path = os.path.join(os.path.dirname(__file__), "server.py")
print("Connecting to MCP server...")
client = Client(Transport.subprocess([sys.executable, server_path]))
# Initialize connection
await client.initialize()
# Get server info
capabilities = client.capabilities
print(f"Connected to: {capabilities.server_info.name}")
# List tools
tools = await client.list_tools()
print(f"Available tools: {', '.join(t.name for t in tools)}")
# Test the get_code tool with the server.py file itself
print(f"\nTesting get_code tool on {server_path}...")
try:
result = await client.call_tool("get_code", {"target_file": server_path})
print(f"Success! Found {len(result.get('referenced_files', []))} reference files")
print(f"Token count: {result.get('token_count', 0)}/{result.get('token_limit', 0)}")
except Exception as e:
print(f"Error calling tool: {e}")
# Clean up
await client.shutdown()
print("Test completed.")
if __name__ == "__main__":
asyncio.run(main())