nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] MCP tool results keep only the first content block

Open addyCooks opened this issue 1 month ago • 2 comments

Summary

MCPClient returns only result.content[0]. Text in later blocks is dropped, and a leading image block is returned to the model as raw base64 JSON.

Steps to reproduce

  1. Run a stdio MCP server (SDK 1.30) with two tools. multi returns text blocks BLOCK-ONE, BLOCK-TWO, BLOCK-THREE. imgfirst returns an image block (data: "AAAA") followed by a text block CAPTION.
  2. Connect with MCPClient.connectToServer(...).
  3. Call client.callTool('multi', {}) and client.callTool('imgfirst', {}).

Expected behaviour

All text blocks are returned. Non-text blocks are summarised, for example [image/png, 4 bytes], not dumped.

Actual behaviour

multi    -> "BLOCK-ONE"
imgfirst -> "{\"type\":\"image\",\"data\":\"AAAA\",\"mimeType\":\"image/png\"}"

A spec asserting all three blocks fails with t.true(out.includes('BLOCK-TWO')) -> false. The CAPTION text is lost.

Environment

Windows 11, Node v22.22.3, Nanocoder 1.31.0 (main at 948a4e74)

Suggested fix

  • source/mcp/mcp-client.ts:1172 (inside executeToolCall): loop over result.content. Join text blocks with a newline. Replace image and audio blocks with a short placeholder (type and size). Keep the existing Tool executed successfully (no output) message for empty results.
  • This is separate from PR #1926, which only adds isError handling.

addyCooks avatar Nov 02 '26 16:11 addyCooks

Hi @addyCooks, I'm picking this one up. Could you assign it to me? Thanks.

Mahdi-Hasan avatar Nov 04 '26 06:11 Mahdi-Hasan

Hi @addyCooks, I've opened #1960 for this. It formats every content block: text is joined, and image, audio and binary resources become a short [mime, N bytes] placeholder. Could you assign the issue to me when you get a chance? Thanks.

Mahdi-Hasan avatar Nov 05 '26 06:11 Mahdi-Hasan