From e09ddc8fff39f7df733cf07760b8a9532e1986b1 Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Tue, 17 Mar 2026 15:37:41 +0800 Subject: [PATCH] mcp fix (+1 squashed commits) Squashed commits: [c5a959a07] mcp fix --- koboldcpp.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/koboldcpp.py b/koboldcpp.py index dd6179643..3a832fe46 100755 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -588,15 +588,21 @@ class MCPStdioClient: 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: - self._pending[msg_id] = response_q - with self.lock: # write lock only now - if self.process.stdin.closed: - raise RuntimeError("MCP server stdin is closed") - self.process.stdin.write(line + "\n") - self.process.stdin.flush() + try: + with self._pending_lock: + if await_response and msg_id is not None: + self._pending[msg_id] = response_q + with self.lock: + if self.process.stdin.closed: + raise RuntimeError("MCP server stdin is closed") + self.process.stdin.write(line + "\n") + self.process.stdin.flush() + except Exception: + if await_response and msg_id is not None: + with self._pending_lock: + self._pending.pop(msg_id, None) + raise if not await_response: return None