Skip to content

fix(smolagents): combine multiple text content blocks from MCP tools - #84

Open
syf2211 wants to merge 1 commit into
grll:mainfrom
syf2211:fix/67-combine-multiple-text-content
Open

fix(smolagents): combine multiple text content blocks from MCP tools#84
syf2211 wants to merge 1 commit into
grll:mainfrom
syf2211:fix/67-combine-multiple-text-content

Conversation

@syf2211

@syf2211 syf2211 commented Jun 27, 2026

Copy link
Copy Markdown

Summary

When an MCP tool returns multiple TextContent blocks, SmolAgentsAdapter previously logged a warning and returned only the first block. This change joins all text blocks with newlines so agents receive the full tool output.

Motivation

Fixes #67. Users wrapping MCP servers that emit multiple text parts (e.g. GraphQL introspection schemas split across blocks) were silently losing data beyond the first content item.

Changes

  • Add _combine_text_contents() helper in smolagents_adapter.py
  • In MCPAdaptTool.forward(), combine all-text multi-block responses instead of using only content[0]
  • Preserve existing behavior for single blocks, image/audio content, and mixed multi-content responses (warn + first item)
  • Add regression test test_multiple_text_content_blocks_are_combined

Tests

  • uv run --extra test pytest tests/test_smolagents_adapter.py -q10 passed
  • uv run ruff check src/mcpadapt/smolagents_adapter.py tests/test_smolagents_adapter.pypassed

Notes

  • Intentional behavior change: multiple TextContent blocks are now returned together (newline-separated) instead of first-only.
  • Reviewed with Composer-2.5 sub-agent: APPROVE.

When an MCP tool returns multiple TextContent blocks, SmolAgentsAdapter
previously logged a warning and returned only the first block. Join all
text blocks with newlines so agents receive the full tool output.

Fixes grll#67
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.

Tool returned multiple content, but MCPAdaptTool only returns the first

1 participant