Skip to content

fix: flag failed tool calls with MCP's isError - #122

Merged
joe4dev merged 1 commit into
mainfrom
fix/tool-errors-set-iserror
Nov 18, 2026
Merged

joe4dev merged 1 commit into
mainfrom
fix/tool-errors-set-iserror

Conversation

@joe4dev

@joe4dev joe4dev commented Nov 18, 2026

Copy link
Copy Markdown
Member

Summary

Tools reported a failure only through a ❌ prefix in the answer text, never through MCP's isError flag. Clients and test harnesses that read the flag treated every failure as a success. One result: expect(result).not.toBeToolError() in tests/mcp/direct.spec.mjs could never fail.

 src/core/response-builder.ts
+  ResponseBuilder.error(...) → { content, isError: true }
 src/core/analytics.ts  (withToolAnalytics)
+  a ❌-prefixed answer built by hand also gets isError: true

withToolAnalytics wraps every tool and already counts a ❌-prefixed answer as an error for analytics, so the flag follows the same rule. That covers the roughly 40 answers that tools build by hand, without touching their files. Answers that only mention ❌ further down, such as the logs-analysis tables, stay successes.

Split out of the review of #96: with this flag, an MCP-aware harness can tell that a tool call failed.

Evidence

  • yarn test: 419 passed, including 4 new cases in src/core/analytics.test.ts: ResponseBuilder.error, a hand-built ❌ answer, a success, and markdown with ❌ further down.
  • yarn test:mcp:direct: 12 passed. Two offline Azure tests now also assert toBeToolError().
  • With the two source changes reverted, those two Azure tests fail. So the new assertions check the flag that reaches the client over stdio.
  • tsc --noEmit and Prettier are clean.

Merge Danger

Door: two-way

Blast Radius: what MCP clients see when a tool fails

  • MCP clients now get isError: true on failed calls. Hosts may show these differently, for example as a tool error rather than a normal result. The text is unchanged.
  • tests/docker/validate-image.mjs already treats isError or a leading ❌ as an error, so it is unaffected.

🤖 Generated with Claude Code

Tools reported failures only through a ❌ text prefix, never through MCP's
isError flag. Clients and test harnesses that read the flag saw every failure
as a success, so `expect(result).not.toBeToolError()` could never fail.

ResponseBuilder.error now sets isError. withToolAnalytics, which every tool
passes through and which already treats a ❌-prefixed answer as an error, also
sets it on the answers that tools build by hand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@joe4dev
joe4dev merged commit af95ecc into main Nov 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant