From 837fe9d8328645e81f1fedf8099e45d23c16e9df Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Tue, 17 Mar 2026 15:34:05 +0800 Subject: [PATCH] mcp stdio fixes --- koboldcpp.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/koboldcpp.py b/koboldcpp.py index dd8f16dd4..dd6179643 100755 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -562,23 +562,31 @@ class MCPStdioClient: for line in self.process.stdout: if not line: break - msg = json.loads(line) + try: + msg = json.loads(line) + except Exception: + continue msg_id = msg.get("id") if msg_id is not None: with self._pending_lock: q = self._pending.get(msg_id) if q: q.put(msg) + else: + print(f"[MCP] Unexpected response id: {msg_id}") finally: self.alive = False with self._pending_lock: for q in self._pending.values(): - q.put(None) # unblock any waiting send() + q.put(None) def send(self, message: dict, await_response=True) -> dict: # Send JSON-RPC request and wait for response. line = json.dumps(message) msg_id = message.get("id") + if await_response and msg_id is None: + raise ValueError("Cannot await response for a message without an 'id' field") + response_q = queue.Queue() if await_response and msg_id is not None: with self._pending_lock: @@ -593,7 +601,9 @@ class MCPStdioClient: if not await_response: return None try: - response = response_q.get(timeout=30) + response = response_q.get(timeout=120) + except queue.Empty: + raise RuntimeError("MCP server timed out (no response in 120s)") finally: with self._pending_lock: self._pending.pop(msg_id, None)