Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(mcp): count server failures once

Ruben Lütke659dd266b363
diff --git a/jarvis/mcp/client.py b/jarvis/mcp/client.py
index 5cd73fd6fc..e613df6981 100644
--- a/jarvis/mcp/client.py
+++ b/jarvis/mcp/client.py
@@ -233,16 +233,9 @@ class MCPClient:
) from exc
# MCP-SDK quirk: server-side tool exceptions do NOT propagate as
# Python exceptions; instead they arrive as a CallToolResult with
- # isError=True. The circuit breaker counts this as a failure.
+ # isError=True. Raise into the one shared failure counter below;
+ # counting here as well would make one server error count twice.
if getattr(result, "isError", False):
- self._circuit_breaker_failures += 1
- if self._circuit_breaker_failures >= _CB_THRESHOLD:
- self._disabled_until_ns = time.time_ns() + _CB_COOLDOWN_NS
- log.warning(
- "MCPClient[%s] circuit-breaker OPEN (60s) nach %d Fehlern",
- self.spec.name,
- self._circuit_breaker_failures,
- )
raise RuntimeError(
_extract_error_text(result)
or f"MCP tool {name} returned isError=True"
@@ -254,7 +247,7 @@ class MCPClient:
if self._circuit_breaker_failures >= _CB_THRESHOLD:
self._disabled_until_ns = time.time_ns() + _CB_COOLDOWN_NS
log.warning(
- "MCPClient[%s] circuit-breaker OPEN (60s) nach %d Fehlern",
+ "MCPClient[%s] circuit breaker OPEN (60s) after %d failures",
self.spec.name,
self._circuit_breaker_failures,
)
@@ -301,7 +294,7 @@ class MCPClient:
raw = list(self.spec.install_command)
if not raw:
- raise ValueError(f"{self.spec.name}: install_command ist leer")
+ raise ValueError(f"{self.spec.name}: install_command is empty")
def _expand(s: str) -> str:
return (
diff --git a/tests/integration/mcp/test_mcp_client_timeout.py b/tests/integration/mcp/test_mcp_client_timeout.py
index c11954b3d7..2082b65f68 100644
--- a/tests/integration/mcp/test_mcp_client_timeout.py
+++ b/tests/integration/mcp/test_mcp_client_timeout.py
@@ -19,6 +19,7 @@ timeout constants via monkeypatch so the tests stay fast and deterministic
from __future__ import annotations
import asyncio
+from types import SimpleNamespace
import pytest
@@ -49,6 +50,17 @@ class _HangingSession:
raise AssertionError("unreachable") # pragma: no cover
+class _ServerErrorSession:
+ """Return the MCP SDK's non-exceptional server-error shape."""
+
+ async def call_tool(self, name: str, args: dict) -> object: # noqa: ANN401
+ del name, args
+ return SimpleNamespace(
+ isError=True,
+ content=[SimpleNamespace(text="server rejected the operation")],
+ )
+
+
# ----------------------------------------------------------------------
# 1. Per-call timeout
# ----------------------------------------------------------------------
@@ -98,6 +110,18 @@ async def test_repeated_hangs_open_the_circuit_breaker(
assert session.calls == calls_before
+async def test_server_error_result_counts_exactly_once() -> None:
+ client = MCPClient(_spec())
+ client._session = _ServerErrorSession()
+
+ with pytest.raises(RuntimeError, match="server rejected"):
+ await client.call_tool("failing_tool", {})
+
+ assert client._circuit_breaker_failures == 1
+ assert client.is_healthy is True
+
+
# ----------------------------------------------------------------------
# 2. Per-start timeout (registry)
# ----------------------------------------------------------------------