Skip to content

fix(mcp): don't trip circuit breaker on business errors (isError) - #47898

Closed
blut-agent wants to merge 1 commit into
NousResearch:mainfrom
blut-agent:fix/mcp-circuit-breaker-20260617
Closed

fix(mcp): don't trip circuit breaker on business errors (isError)#47898
blut-agent wants to merge 1 commit into
NousResearch:mainfrom
blut-agent:fix/mcp-circuit-breaker-20260617

Conversation

@blut-agent

Copy link
Copy Markdown
Contributor

Problem

When an MCP tool returns isError: true with a business error message (e.g. validation failure, missing required field), the handler wraps it as {"error": "..."}. The circuit-breaker check at line ~2867 was treating this the same as a transport failure and calling _bump_server_error(), which caused the circuit breaker to trip after 3 consecutive business errors.

This blocks ALL tools on the server for ~60 seconds with a misleading message like:
"MCP server 'waw' is unreachable after 3 consecutive failures"

even though the server is perfectly healthy — the errors are just validation/business errors.

Refs: #47851

Fix

Reset the error counter for JSON responses containing an "error" key instead of bumping it. Business errors mean the server is healthy — the model should retry with corrected arguments.

Transport/auth failures are still properly handled by the outer except Exception block (line ~2876), which still calls _bump_server_error().

Changes

When an MCP tool returns isError=true with a business error message
(e.g. validation failure), the handler wraps it as {"error": "..."}.
The circuit-breaker check at line ~2867 was treating this the same as
a transport failure and bumping the error counter, which caused the
circuit breaker to trip after 3 consecutive business errors (NousResearch#47851).

Business errors mean the server is healthy — the model should retry
with corrected arguments. Only transport/auth failures (caught as
exceptions in the outer except block) should increment the counter.

Fix: reset the error counter for JSON responses containing an "error"
key instead of bumping it. Transport failures still bump via the outer
except Exception block.

Refs: NousResearch#47851
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint tool/mcp MCP client and OAuth P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels Jun 17, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #40951 — both patch the identical if "error" in parsed: branch in tools/mcp_tool.py (~line 2867) so a tool-level/business error (isError) no longer trips the circuit breaker. #40951 (open, filed 2026-06-07) is the earlier canonical version; it leaves the counter unchanged (pass) while this PR resets it (_reset_server_error) — a review nuance, same fix at the same line. Both resolve #47851. The bug is still live on main.

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Approved

Small, well-scoped fix. The change correctly distinguishes between MCP protocol business errors (isError flag in JSON response) and transport failures - only the latter should trip the circuit breaker. The comments clearly explain the rationale and reference the related issue.

Looks Good

  • Single-file change in tools/mcp_tool.py
  • Clear comments explaining the fix rationale
  • No security or performance concerns
  • No test changes needed (this is a runtime behavior fix for a rare edge case)

Reviewed by Hermes Agent

@blut-agent

Copy link
Copy Markdown
Contributor Author

Closing — duplicate of earlier PR #45651 or #33699/#32519. See the canonical PR for tracking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists tool/mcp MCP client and OAuth type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants