-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathecho_test.py
More file actions
71 lines (61 loc) · 2 KB
/
echo_test.py
File metadata and controls
71 lines (61 loc) · 2 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
#!/usr/bin/env python
import subprocess
import threading
import sys
import time
def main():
# Start the server
print("Starting MCP server...")
server_process = subprocess.Popen(
["cargo", "run"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
bufsize=1
)
# Thread for reading stdout
def read_stdout():
while True:
line = server_process.stdout.readline()
if not line:
break
print(f"SERVER STDOUT: {line.strip()}")
# Thread for reading stderr
def read_stderr():
while True:
line = server_process.stderr.readline()
if not line:
break
print(f"SERVER STDERR: {line.strip()}")
# Start stdout and stderr reader threads
stdout_thread = threading.Thread(target=read_stdout, daemon=True)
stderr_thread = threading.Thread(target=read_stderr, daemon=True)
stdout_thread.start()
stderr_thread.start()
# Wait for server to start
print("Waiting for server to start...")
time.sleep(3)
print("\n===== MCP SERVER ECHO TEST =====")
print("Type JSON-RPC requests to send to the server.")
print("Each line will be sent as a single request.")
print("Type 'exit' to quit.")
print("==================================\n")
try:
while True:
try:
user_input = input("> ")
if user_input.lower() == 'exit':
break
# Add newline to user input and send to server
server_process.stdin.write(user_input + "\n")
server_process.stdin.flush()
print(f"Sent: {user_input}")
except KeyboardInterrupt:
break
finally:
print("Terminating server...")
server_process.terminate()
print("Server terminated.")
if __name__ == "__main__":
main()