spring-projects / spring-projects/spring-ai

When the MCP calls a tool and returns an error message, it causes the entire process to be interrupted.

Open
#3,023 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 10h
Merged PRs (30d)
5

Description

Bug description
When the MCP calls a tool and returns an error message, it causes the entire process to be interrupted.

Environment
spring ai v1.0.0-M8

Steps to reproduce
When calling the mcp-server tool, if the tool returns a result with an error indicator.

Expected behavior
When encountering error messages returned by the mcp-server tool, the system can continue executing the operation, and the large language model will automatically attempt to fix the issue.

Code that caused the bug
org.springframework.ai
spring-ai-model
In this module, the class DefaultToolCallingManager has a corresponding method called executeToolCall, with the following code:
String toolResult; try { toolResult = toolCallback.call(toolInputArguments, toolContext); } catch (ToolExecutionException ex) { toolResult = toolExecutionExceptionProcessor.process(ex); }
The exception being caught here is ToolExecutionException. However, in another module
org.springframework.ai
spring-ai-mcp
The corresponding class SyncMcpToolCallback contains the following code:
public String call(String functionInput) { Map<String, Object> arguments = ModelOptionsUtils.jsonToMap(functionInput); // Note that we use the original tool name here, not the adapted one from // getToolDefinition CallToolResult response = this.mcpClient.callTool(new CallToolRequest(this.tool.name(), arguments)); if (response.isError() != null && response.isError()) { throw new IllegalStateException("Error calling tool: " + response.content()); } return ModelOptionsUtils.toJsonString(response.content()); }
When an error flag is returned, the exception thrown is IllegalStateException, which cannot be caught by the upper layer that only catches ToolExecutionException, leading to an unexpected interruption.

The suggestion
The lower-level module throws an IllegalStateException, but the upper layer only handles ToolExecutionException. As a result, the exception is unhandled and causes the process to break. Possible solutions include catching IllegalStateException at the upper layer or modifying the lower layer to throw a ToolExecutionException instead.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with DefaultToolCallingManager.executeToolCall in the spring-ai-model module and SyncMcpToolCallback.call in the spring-ai-mcp module. Reproduce an MCP tool call whose result has the error flag, then trace how the exception is handled. Done means the returned tool error is handled without interrupting the operation, allowing the language model to continue.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.