Skip to content

Retain structured-only MCP tool error details - #424

Closed
sylvesterkaczmarek wants to merge 1 commit into
anthropics:mainfrom
sylvesterkaczmarek:fix/mcp-structured-error-content-20261005
Closed

sylvesterkaczmarek wants to merge 1 commit into
anthropics:mainfrom
sylvesterkaczmarek:fix/mcp-structured-error-content-20261005

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Fixes #423.

Serialize structured-only content once before selecting the success/error path. Errors now use that JSON in the existing AnthropicException; successes retain their existing string content. Nonempty regular content retains precedence, and serialization failures use the existing AnthropicInvalidDataException with its cause.

Validation

Tests invoke the public BetaMcp.mcpTool(...).runner with actual MCP result objects. Coverage includes structured-only success/failure, empty and nested objects, false/zero/null values, ordinary error-text precedence, empty errors and serialization failures.

  • New tests on unchanged main: 2 failed, 3 passed.
  • Complete MCP module after the fix: 32 passed.
  • Module formatting, Detekt main/test analysis, Kotlin lint and git diff --check passed.
./gradlew :anthropic-java-mcp:test :anthropic-java-mcp:detektMain :anthropic-java-mcp:detektTest :anthropic-java-mcp:lintKotlin

No public method signatures or dependencies change. This follows the diagnostic-preservation intent of anthropics/anthropic-sdk-csharp#287 and anthropics/anthropic-sdk-go#461 while retaining Java's exception-based tool-error contract.

Tested on macOS arm64 with JDK 21. The full SDK suite and live API/MCP services were not tested. Existing Gradle deprecation warnings remain.

Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
@sylvesterkaczmarek
sylvesterkaczmarek requested a review from a team as a code owner October 5, 2026 08:04
@sylvesterkaczmarek

Copy link
Copy Markdown
Author

All 32 MCP module tests pass locally, together with the module formatting, Detekt and Kotlin lint checks. Could a maintainer approve the pending CI workflow?

@tomer-ant

Copy link
Copy Markdown
Contributor

Closing along with #423. The reasoning is in #423 (comment).

@tomer-ant tomer-ant closed this Oct 14, 2026
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.

MCP tool errors with only structuredContent lose their diagnostic payload

2 participants