Skip to content

The agent that grows with you

fix(mcp): preserve application results after transport recovery

Dennis Hermsmeier5dca47a651a6
diff --git a/tests/tools/test_mcp_tool_session_expired.py b/tests/tools/test_mcp_tool_session_expired.py
index 046cec0f8c1..1320d9fd772 100644
--- a/tests/tools/test_mcp_tool_session_expired.py
+++ b/tests/tools/test_mcp_tool_session_expired.py
@@ -137,8 +137,9 @@ def _install_stub_server(name: str = "wpcom"):
],
ids=["stdio", "http"],
)
[email protected]("application_error", [False, True], ids=["success", "application-error"])
def test_call_tool_handler_rebuilds_configured_server_transport(
- monkeypatch, tmp_path, transport_config, expected_route
+ monkeypatch, tmp_path, transport_config, expected_route, application_error
):
"""The real server run loop selects and rebuilds its configured transport."""
from anyio import ClosedResourceError
@@ -160,7 +161,7 @@ def test_call_tool_handler_rebuilds_configured_server_transport(
if call_count["n"] == 1:
raise ClosedResourceError
result = MagicMock()
- result.is_error = False
+ result.is_error = application_error
result.content = [MagicMock(type="text", text="reconnected")]
result.structured_content = None
return result
@@ -202,7 +203,7 @@ def test_call_tool_handler_rebuilds_configured_server_transport(
assert parsed["outcome_uncertain"] is True, parsed
assert call_count["n"] == 1
else:
- assert parsed == {"result": "reconnected"}
+ assert parsed == {"error" if application_error else "result": "reconnected"}
assert call_count["n"] == 2
assert routes == [expected_route, expected_route]
assert configs == [transport_config, transport_config]
diff --git a/tools/mcp_tool_handlers.py b/tools/mcp_tool_handlers.py
index 240b6d78f15..dbb96f58111 100644
--- a/tools/mcp_tool_handlers.py
+++ b/tools/mcp_tool_handlers.py
@@ -133,14 +133,13 @@ def _lookup_reconnectable_server(server_name: str, require_loop: bool = False):
def _retry_once(server_name: str, retry_call, op_description: str, what: str):
"""Re-run ``retry_call`` after a recovery step. Returns the result (closing the breaker)
- when it is not an error payload; None when the retry raised or errored (caller falls through)."""
+ when the RPC completed; None when the retry raised (caller falls through)."""
try:
result = retry_call()
except Exception as retry_exc:
logger.warning("MCP %s/%s retry after %s failed: %s", server_name, op_description, what, retry_exc)
return None
- if _result_is_error(result):
- return None
+ # An application error still proves the recovered transport completed a round-trip.
_core._reset_server_error(server_name)
return result