Skip to content

Fix crash when parsing MCP server tool results#2

Merged
phiat merged 1 commit intomainfrom
fix/mcp-tool-result-parsing
Feb 27, 2026
Merged

Fix crash when parsing MCP server tool results#2
phiat merged 1 commit intomainfrom
fix/mcp-tool-result-parsing

Conversation

@phiat
Copy link
Copy Markdown
Owner

@phiat phiat commented Feb 27, 2026

Summary

  • MCP tools return tool_result.content as an array of content blocks ([{"type":"text","text":"..."}]), while built-in tools return a plain string. The ToolResult.Content field was typed as string, causing json.Unmarshal to fail on any MCP tool result — crashing the UI with a JSON parse error.
  • Changed Content to json.RawMessage and added extractToolResultContent() to handle both string and array formats gracefully.
  • Added tests for single-block and multi-block MCP tool results.

Test plan

  • All existing parser tests pass
  • New TestParseLine_MCPToolResult — single content block (MCP style)
  • New TestParseLine_MCPToolResultMultiBlock — multiple content blocks joined with newlines
  • Manual: run claude-esp while Claude invokes an MCP server (e.g., Context7) and verify output displays correctly

🤖 Generated with Claude Code

MCP tools return tool_result content as an array of content blocks
([{"type":"text","text":"..."}]) while built-in tools return a plain
string. The ToolResult.Content field was typed as string, causing
json.Unmarshal to fail on any MCP tool result.

Change Content to json.RawMessage and add extractToolResultContent()
to handle both formats.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@phiat phiat merged commit cb03aba into main Feb 27, 2026
1 check passed
@phiat phiat deleted the fix/mcp-tool-result-parsing branch February 27, 2026 16:34
@phiat phiat mentioned this pull request Feb 27, 2026
phiat added a commit that referenced this pull request Mar 20, 2026
…n output

- Fix show_text default (false → true) — text output was hidden with no toggle
- Add Text toggle (x key) in header
- Add solo mode (s key) — isolate a session/agent in tree view
- Remove destructive x/d delete — space toggle + solo covers filtering
- Show tool name on output headers (e.g., "Bash result (1.2s)")
- Fix dedup to key on (ToolID, Type) — input+output with same ID both kept
- Rename "Auto" to "Scroll" in header
- Update README keybindings

Based on phiat/claude-esp-rs#2 by @rdmontgomery

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant