-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsimplest_test.py
More file actions
111 lines (92 loc) · 3.16 KB
/
simplest_test.py
File metadata and controls
111 lines (92 loc) · 3.16 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
#!/usr/bin/env python
import json
import subprocess
import time
import sys
import os
import threading
def main():
# First, make sure Paint is not running
os.system('taskkill /f /im mspaint.exe 2>nul')
time.sleep(1)
# Launch Paint
print("Launching MS Paint...")
paint_process = subprocess.Popen(["mspaint.exe"])
time.sleep(3) # Wait for Paint to start
# Start the server
print("Starting MCP server...")
server_process = subprocess.Popen(
["cargo", "run"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=None, # Don't capture stderr so it appears in console directly
text=True,
bufsize=1
)
try:
# Step 1: Initialize
print("Sending initialize request...")
init_request = {
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {}
}
send_request_and_wait(server_process, init_request, 3)
# Step 2: Connect
print("Sending connect request...")
connect_request = {
"jsonrpc": "2.0",
"id": 2,
"method": "connect",
"params": {
"client_id": "simplest_test",
"client_name": "Simplest Test Client"
}
}
send_request_and_wait(server_process, connect_request, 3)
# Step 3: Draw a large rectangle with lots of time for each step
print("Drawing a large rectangle...")
rectangle_request = {
"jsonrpc": "2.0",
"id": 3,
"method": "draw_shape",
"params": {
"shape_type": "rectangle",
"start_x": 50,
"start_y": 50,
"end_x": 500,
"end_y": 400
}
}
# Send request and wait longer for rectangle drawing to complete
send_request_and_wait(server_process, rectangle_request, 10)
print("Test completed. Rectangle should be drawn.")
print("Press Enter to close test and Paint...")
input()
except Exception as e:
print(f"Test failed with error: {e}")
finally:
# Terminate the server process
server_process.terminate()
print("Server process terminated")
# Terminate Paint
paint_process.terminate()
print("Paint process terminated")
def send_request_and_wait(process, request, wait_time=5):
"""Send a request to the server and wait a fixed time."""
request_str = json.dumps(request) + "\n"
print(f"SENDING: {request_str.strip()}")
process.stdin.write(request_str)
process.stdin.flush()
# Wait for response - simple approach with fixed wait time
print(f"Waiting {wait_time} seconds for operation to complete...")
# Read response
response_line = process.stdout.readline().strip()
if response_line:
print(f"RESPONSE: {response_line}")
# Wait additional time after response to ensure operation completes
time.sleep(wait_time)
return response_line
if __name__ == "__main__":
main()