mcp fix (+1 squashed commits)

Squashed commits:

[c5a959a07] mcp fix
This commit is contained in:
Concedo 2026-03-17 15:37:41 +08:00
parent 837fe9d832
commit e09ddc8fff

View file

@ -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