claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] MCP Error Responses Only Display First Content Block

Open cameroncooke opened this issue 6 months ago • 2 comments

Environment

  • Platform (select one):
    • [ ] Anthropic API
    • [ ] AWS Bedrock
    • [ ] Google Vertex AI
    • [x] Other: Claude Code CLI
  • Claude CLI version: 1.0.17 (Claude Code)
  • Operating System: macOS 14.5
  • Terminal: iTerm2

Bug Description

Claude Code only displays the first content block from MCP tool responses when isError: true, truncating all subsequent content blocks. This severely impacts error handling workflows where detailed error information is provided across multiple content blocks.

Steps to Reproduce

  1. Create a minimal MCP server that returns multiple content blocks in error responses
  2. Configure the MCP server in Claude Code
  3. Call a tool that returns a successful response with multiple content blocks
  4. Call a tool that returns an error response with multiple content blocks
  5. Compare the displayed output

Expected Behavior

When an MCP tool returns an error response with multiple content blocks, all content blocks should be displayed to provide complete error information, similar to how successful responses with multiple content blocks are handled.

Actual Behavior

Only the first content block is displayed for error responses. All subsequent content blocks are truncated and lost, while successful responses correctly show all content blocks.

Additional Context

Test Results

Success Response (test_multiblock):

Block 1: This is the first content blockBlock 2: This is the second content blockBlock 3: This is the third content block

✅ All 3 content blocks are displayed (though concatenated without separation)

Error Response (test_multiblock_error):

Error Block 1: This is the first error block

❌ Only the first content block is displayed, blocks 2 and 3 are truncated

Impact

  • Critical error details are hidden from users
  • Debugging becomes significantly more difficult
  • Users may assume operations succeeded when they actually failed
  • Error responses appear incomplete and unhelpful

MCP Response Structure

The MCP server correctly returns this response structure for errors:

{
  "content": [
    {
      "type": "text",
      "text": "Error Block 1: This is the first error block"
    },
    {
      "type": "text",
      "text": "Error Block 2: This is the second error block" 
    },
    {
      "type": "text",
      "text": "Error Block 3: This is the third error block"
    }
  ],
  "isError": true
}

But Claude Code only renders content[0] and ignores content[1] and content[2] when isError: true.

Minimal MCP Server Test Case

The following minimal MCP server demonstrates the issue:

#!/usr/bin/env node

import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';

const server = new McpServer(
  {
    name: 'test-multiblock-server',
    version: '1.0.0',
  },
  {
    capabilities: {
      tools: {},
    },
  }
);

// Register tools
server.tool('test_multiblock', 'Returns multiple content blocks in a successful response', {}, async () => {
  return {
    content: [
      {
        type: 'text',
        text: 'Block 1: This is the first content block'
      },
      {
        type: 'text', 
        text: 'Block 2: This is the second content block'
      },
      {
        type: 'text',
        text: 'Block 3: This is the third content block'
      }
    ]
  };
});

server.tool('test_multiblock_error', 'Returns multiple content blocks in an error response', {}, async () => {
  return {
    content: [
      {
        type: 'text',
        text: 'Error Block 1: This is the first error block'
      },
      {
        type: 'text',
        text: 'Error Block 2: This is the second error block' 
      },
      {
        type: 'text',
        text: 'Error Block 3: This is the third error block'
      }
    ],
    isError: true
  };
});

async function main() {
  const transport = new StdioServerTransport();
  await server.connect(transport);
}

main().catch((error) => {
  console.error('Server error:', error);
  process.exit(1);
});

Test Results

Success Response (test_multiblock):

Block 1: This is the first content blockBlock 2: This is the second content blockBlock 3: This is the third content block

✅ All 3 content blocks are displayed (though concatenated without separation)

Error Response (test_multiblock_error):

Error Block 1: This is the first error block

❌ Only the first content block is displayed, blocks 2 and 3 are truncated

Expected vs Actual MCP Response

The MCP server correctly returns this response structure:

{
  "content": [
    {
      "type": "text",
      "text": "Error Block 1: This is the first error block"
    },
    {
      "type": "text",
      "text": "Error Block 2: This is the second error block" 
    },
    {
      "type": "text",
      "text": "Error Block 3: This is the third error block"
    }
  ],
  "isError": true
}

But Claude Code only renders content[0] and ignores content[1] and content[2] when isError: true.

Environment

  • Claude Code interface
  • MCP Protocol SDK
  • Multiple content blocks in error responses

Reproduction Steps

  1. Create the minimal MCP server above
  2. Add it to Claude Code MCP configuration
  3. Call test_multiblock - observe all 3 blocks are shown
  4. Call test_multiblock_error - observe only first block is shown
  5. Compare with success response behavior

Root Cause

The Claude Code interface appears to have different rendering logic for success vs error responses, where error responses only render the first content block from the content array.

Fix Needed

Claude Code should render all content blocks consistently, regardless of the isError flag value.

cameroncooke avatar Jun 08 '25 21:06 cameroncooke

So this is becoming a major issue for my https://github.com/cameroncooke/XcodeBuildMCP MCP, as only the first error is being ingested by the agent, making it impossible for the agent to know what compiler errors there are as all the error content blocks are being truncated essentially.

cameroncooke avatar Jun 11 '25 22:06 cameroncooke

Is there an alternative way to fix this issue? Is it possible to use only one error block?

Aurazion avatar Jun 27 '25 09:06 Aurazion

This bug is a major blocker in using MCP to automate testing with Claude Code.

brianbowden avatar Jul 11 '25 21:07 brianbowden

I've implemented a workaround in XcodeBuildMCP but this really should be fixed.

cameroncooke avatar Aug 14 '25 07:08 cameroncooke

I got caught out by this ! Claude code should pass the entirety of a valid response to the agent

eastlondoner avatar Aug 26 '25 10:08 eastlondoner