-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmock_mcp.py
More file actions
33 lines (31 loc) · 1.34 KB
/
Copy pathmock_mcp.py
File metadata and controls
33 lines (31 loc) · 1.34 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
#!/usr/bin/env python3
"""Tiny MCP stdio server with one 'echo' tool — for testing Chad Code's MCP client."""
import json, sys
def send(obj):
sys.stdout.write(json.dumps(obj) + "\n")
sys.stdout.flush()
for line in sys.stdin:
line = line.strip()
if not line:
continue
msg = json.loads(line)
method, mid = msg.get("method"), msg.get("id")
if method == "initialize":
send({"jsonrpc": "2.0", "id": mid, "result": {
"protocolVersion": "2025-06-18",
"capabilities": {"tools": {}},
"serverInfo": {"name": "mock-mcp", "version": "1.0"}}})
elif method == "tools/list":
send({"jsonrpc": "2.0", "id": mid, "result": {"tools": [{
"name": "echo",
"description": "Echoes back the message you send.",
"inputSchema": {"type": "object",
"properties": {"message": {"type": "string"}},
"required": ["message"]}}]}})
elif method == "tools/call":
text = "MCP ECHO: " + msg["params"]["arguments"].get("message", "")
send({"jsonrpc": "2.0", "id": mid,
"result": {"content": [{"type": "text", "text": text}]}})
elif mid is not None: # unknown request
send({"jsonrpc": "2.0", "id": mid, "error": {"code": -32601, "message": "not found"}})
# notifications: ignore