-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_server.py
More file actions
122 lines (103 loc) · 3.74 KB
/
Copy pathtest_server.py
File metadata and controls
122 lines (103 loc) · 3.74 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python3
"""
微信 MCP 服务器测试脚本
快速测试以验证服务器功能。
"""
import asyncio
import json
import sys
import os
# 将 src 添加到路径
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
from mcp_server import MCPServer
async def test_mcp_server():
"""测试 MCP 服务器功能。"""
print("🚀 Starting WeChat MCP Server Test")
print("=" * 50)
server = MCPServer()
# 测试 1:初始化
print("\n📋 Test 1: Initialize Server")
init_request = {
"jsonrpc": "2.0",
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "test-client",
"version": "1.0.0"
}
},
"id": 1
}
response = await server.handle_request(init_request)
print(f"✅ Initialize Response: {response.get('result', {}).get('serverInfo', {})}")
# 测试 2:列出工具
print("\n🔧 Test 2: List Available Tools")
tools_request = {
"jsonrpc": "2.0",
"method": "tools/list",
"params": {},
"id": 2
}
response = await server.handle_request(tools_request)
tools = response.get('result', {}).get('tools', [])
print(f"✅ Available Tools: {len(tools)} tools found")
for tool in tools:
print(f" - {tool['name']}: {tool['description']}")
# 测试 3:测试微信状态(不实际发送)
print("\n📱 Test 3: Check WeChat Status")
try:
from wechat_controller import WeChatController
controller = WeChatController()
status = controller.get_status()
print(f"✅ WeChat Status: {status}")
except Exception as e:
print(f"⚠️ WeChat Status Check Failed: {e}")
# 测试 4:模拟工具调用(试运行)
print("\n💬 Test 4: Simulate Message Send (Dry Run)")
call_request = {
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "send_wechat_message",
"arguments": {
"contact_name": "文件传输助手",
"message": "Test message from MCP server"
}
},
"id": 3
}
print("📤 Simulating message send...")
print(f" Contact: {call_request['params']['arguments']['contact_name']}")
print(f" Message: {call_request['params']['arguments']['message']}")
# 取消注释下一行以实际发送消息
# response = await server.handle_request(call_request)
# print(f"✅ Send Result: {response}")
print("⚠️ Actual sending skipped in test mode")
print(" To enable real sending, uncomment the lines in test_server.py")
print("\n" + "=" * 50)
print("🎉 MCP Server Test Completed!")
print("\n📝 Next Steps:")
print("1. Ensure WeChat is running and logged in")
print("2. Configure your AI assistant with this MCP server")
print("3. Try sending a real message through your AI assistant")
print("\n🔧 Configuration example for Claude Desktop:")
print(json.dumps({
"mcpServers": {
"wechat": {
"command": "python",
"args": [os.path.abspath("src/mcp_server.py")],
"env": {}
}
}
}, indent=2))
if __name__ == "__main__":
try:
asyncio.run(test_mcp_server())
except KeyboardInterrupt:
print("\n\n⏹️ Test interrupted by user")
except Exception as e:
print(f"\n\n❌ Test failed with error: {e}")
import traceback
traceback.print_exc()