-
Notifications
You must be signed in to change notification settings - Fork 476
Description
The Problem
I've encountered an issue where Claude Code (the CLI agent) successfully calls a tool from this MCP server and prints the result to the terminal console, but the underlying LLM model fails to "see" the response.
This results in an infinite loop:
- Claude Code calls the tool.
- The MCP server returns the data in the
contentfield. - The data is printed in the terminal.
- The model thinks the tool returned no data/empty response.
- The model tries to call the same tool again to get the missing information.
Root Cause Analysis
Recent versions of Claude Code have updated their protocol handling. It seems the client now prioritizes (or in some cases, strictly requires) the structuredContent field to pass data back into the LLM's context window.
If an MCP server only provides the standard content array (even with valid text), Claude Code displays it to the user but fails to inject it into the model's prompt, effectively making the AI "blind" to the tool's output.
The Fix
I have verified in my local environment that adding a structuredContent field to the CallToolResult (mirroring the data in content) completely resolves this issue.
Suggested Change:
When returning the tool result, ensure both content and structuredContent are populated. For example:
// Proposed fix for the response structure
return {
content: [
{
type: "text",
text: resultData
}
],
// Injecting structuredContent allows Claude Code to "see" the data
structuredContent: resultData,
isError: false
};Environment
- **Claude Code Version: v2.1.72
- **MCP Protocol: v1.3.4