-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmcp-server.py
More file actions
executable file
·44 lines (42 loc) · 1.4 KB
/
mcp-server.py
File metadata and controls
executable file
·44 lines (42 loc) · 1.4 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
import sys, json
echo_tool = {
"name": "echo",
"description": "Echo back a message",
"inputSchema": {
"type": "object",
"properties": {"message": {"type": "string"}},
"required": ["message"],
"additionalProperties": False,
},
}
for line in sys.stdin:
line = line.strip()
if not line:
continue
try:
msg = json.loads(line)
except json.JSONDecodeError:
continue
method = msg.get("method")
if method == "initialize":
resp = {
"jsonrpc": "2.0",
"id": msg.get("id"),
"result": {
"protocolVersion": msg.get("params", {}).get("protocolVersion"),
"capabilities": {"tools": {}},
"serverInfo": {"name": "EchoPy", "version": "1.0.0"},
},
}
sys.stdout.write(json.dumps(resp) + "\n")
sys.stdout.flush()
elif method == "tools/list":
resp = {"jsonrpc": "2.0", "id": msg.get("id"), "result": {"tools": [echo_tool]}}
sys.stdout.write(json.dumps(resp) + "\n")
sys.stdout.flush()
elif method == "tools/call":
args = msg.get("params", {}).get("arguments", {})
text = args.get("message", "")
resp = {"jsonrpc": "2.0", "id": msg.get("id"), "result": {"content": [{"type": "text", "text": text}]}}
sys.stdout.write(json.dumps(resp) + "\n")
sys.stdout.flush()