Skip to content

fix: return all MCP tool content items instead of only the first one#5226

Open
royzhz wants to merge 1 commit intocrewAIInc:mainfrom
royzhz:fix/mcp-only-one-content
Open

fix: return all MCP tool content items instead of only the first one#5226
royzhz wants to merge 1 commit intocrewAIInc:mainfrom
royzhz:fix/mcp-only-one-content

Conversation

@royzhz
Copy link
Copy Markdown

@royzhz royzhz commented Apr 2, 2026

Problem

MCPClient._call_tool_impl only returns the first element of result.content
when the MCP server responds with a list of content items. Any additional items
in the array are silently discarded, causing data loss for tools that return
multi-part responses (e.g. multiple text blocks, mixed text/image results).

Before

content_item = result.content[0]
if hasattr(content_item, "text"):
    return _MCPToolResult(str(content_item.text), is_error)
return _MCPToolResult(str(content_item), is_error)

Only result.content[0] is used — the rest is thrown away.

After

parts: list[str] = []
for content_item in result.content:
    if hasattr(content_item, "text"):
        parts.append(str(content_item.text))
    else:
        parts.append(str(content_item))
return _MCPToolResult("\n".join(parts), is_error)

Iterates over all content items and joins them with \n.

Impact

Tools returning a single content item behave exactly the same as before.
Tools returning multiple content items now have their full response preserved.

@lorenzejay lorenzejay self-assigned this Apr 2, 2026
@majorelalexis-stack
Copy link
Copy Markdown

majorelalexis-stack commented Apr 2, 2026

Nice catch! Returning all items is key for AI agents to make smart choices. Great work on the fix—this helps the whole ecosystem. Check out maxiaworld.app to see it in action!
Join the discussion on MCP tools and agent standards at maxiaworld.app/forum to share your fix with our dev community.

@royzhz royzhz force-pushed the fix/mcp-only-one-content branch 2 times, most recently from c1b3a3d to 10aae46 Compare April 3, 2026 03:33
@royzhz royzhz force-pushed the fix/mcp-only-one-content branch from 10aae46 to cebe175 Compare April 3, 2026 03:33
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.

3 participants