Skip to content

Commit 2541bc9

Browse files
committed
CI: wait for each MCP reply instead of closing stdin early
1 parent 90fcc6f commit 2541bc9

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,23 @@ jobs:
2020
- name: MCP server starts and lists its tools
2121
run: |
2222
uv run python - <<'PY'
23-
import json, subprocess
24-
msgs = [
25-
{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2025-06-18", "capabilities": {}, "clientInfo": {"name": "ci", "version": "1"}}},
26-
{"jsonrpc": "2.0", "method": "notifications/initialized"},
27-
{"jsonrpc": "2.0", "id": 2, "method": "tools/list"},
28-
]
29-
out = subprocess.run([".venv/bin/booksy-mcp", "mcp"], input="\n".join(json.dumps(m) for m in msgs) + "\n",
30-
capture_output=True, text=True, timeout=60).stdout
31-
tools = next(json.loads(l)["result"]["tools"] for l in out.splitlines() if '"id":2' in l.replace(" ", ""))
23+
import json, subprocess, sys
24+
proc = subprocess.Popen([".venv/bin/booksy-mcp", "mcp"], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
25+
stderr=subprocess.PIPE, text=True)
26+
def ask(msg, want=None):
27+
proc.stdin.write(json.dumps(msg) + "\n")
28+
proc.stdin.flush()
29+
while want is not None:
30+
line = proc.stdout.readline()
31+
if not line:
32+
sys.exit("server exited: " + proc.stderr.read()[-2000:])
33+
reply = json.loads(line)
34+
if reply.get("id") == want:
35+
return reply
36+
ask({"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2025-06-18", "capabilities": {}, "clientInfo": {"name": "ci", "version": "1"}}}, 1)
37+
ask({"jsonrpc": "2.0", "method": "notifications/initialized"})
38+
tools = ask({"jsonrpc": "2.0", "id": 2, "method": "tools/list"}, 2)["result"]["tools"]
39+
proc.terminate()
3240
assert tools, "no tools"
3341
print(len(tools), "tools")
3442
PY

0 commit comments

Comments
 (0)