Propagate tool failures as ToolExecutionException so MCP clients see isError - #1781
Merged
Conversation
…isError SpringToolCallbackAdapter.call used to encode every tool failure (Result.Error and thrown exceptions alike) as a plain "ERROR: ..." string. From the MCP client's point of view that looked like a successful call, so isError stayed false even when the tool genuinely failed (#1780). Both failure paths now throw ToolExecutionException instead, always wrapped around a RuntimeException so Spring AI's chat tool loop still converts it into a message for the model rather than rethrowing it. An already-thrown ToolExecutionException passes through unchanged. Signed-off-by: James Dunnam <7660553+jimador@users.noreply.github.com>
|
alexheifetz
self-requested a review
July 13, 2026 21:15
alexheifetz
approved these changes
Jul 13, 2026
alexheifetz
left a comment
Contributor
There was a problem hiding this comment.
Merging. Streaming Test will be added later.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #1780.
SpringToolCallbackAdapter.callswallowed bothTool.Result.Errorand thrown exceptions into"ERROR: ..."string results, so MCP clients received successfultools/callresponses withCallToolResult.isError = falsefor every tool failure — including access-control denials.What changed
ToolExecutionExceptionfor both failure kinds, always with aRuntimeExceptioncause carrying the intended message:Tool.Result.Error(message, cause)→ToolExecutionException(definition, RuntimeException(message, cause))— the error message survives verbatim on the wire.RuntimeException→ passed as the cause directly, preserving the concrete class (e.g.AccessDeniedException) for exception processors configured to rethrow specific types.RuntimeExceptionfirst. This matters:DefaultToolExecutionExceptionProcessorrethrows when the cause is not aRuntimeException, which would break the chat tool loop.Text,WithArtifact) unchanged;SpringToolCallbackWrapper(the reverse adapter) unchanged.Behavior after the change
McpToolUtilshandler catches the exception →isError = truewith the message as content.McpAwareGoalToolalready mapsAccessDeniedExceptiontoTool.Result.Error, so security denials become protocol-level errors with no further change.DefaultToolCallingManagercatches exactlyToolExecutionExceptionand its processor returns the message to the model — same visible behavior as before, minus the"ERROR: "prefix.On the issue's open question (soft vs hard errors): both
Result.Errorand exceptions map to protocol errors — a tool that returnsResult.Errorfailed, and clients branching onisErrorshould see it. No config surface added; easy to revisit if a use case needs split behavior.Testing
SpringToolCallbackAdapterTestupdated from string-prefix assertions toassertThrowswith message assertions.McpToolErrorMappingTestdrives the realMcpToolUtils.toSyncToolSpecificationhandler end to end:isError = truefor runtime,Result.Error, and checked-exception cases (asserting theRuntimeException-cause invariant); happy path stays non-error.embabel-agent-apisuite green (3907 tests, 0 failures).