Skip to content

Bug: Tool output ignored by Claude Code model leading to infinite loops (Missing structuredContent) #159

@pandafeeeder

Description

@pandafeeeder

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:

  1. Claude Code calls the tool.
  2. The MCP server returns the data in the content field.
  3. The data is printed in the terminal.
  4. The model thinks the tool returned no data/empty response.
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions