Skip to content

Fix/bedrock empty tool result structured content#1620

Open
Devansh-jpg wants to merge 2 commits into
mcp-use:mainfrom
Devansh-jpg:fix/bedrock-empty-tool-result-structured-content
Open

Fix/bedrock empty tool result structured content#1620
Devansh-jpg wants to merge 2 commits into
mcp-use:mainfrom
Devansh-jpg:fix/bedrock-empty-tool-result-structured-content

Conversation

@Devansh-jpg

@Devansh-jpg Devansh-jpg commented Jun 4, 2026

Copy link
Copy Markdown

Changes

Fix _mcp_content_to_langchain crashing AWS Bedrock when an MCP server returns an empty content[] with data in structuredContent (MCP 2025-11-05 spec).

Implementation Details

  1. Changed _mcp_content_to_langchain to accept a full CallToolResult object instead of just the content list, so it can access both content and structuredContent.
  2. When content is empty, fall back to json.dumps(structuredContent) if available, otherwise return "(no content)" — both are non-empty strings that Bedrock accepts.
  3. Updated the call site to pass tool_result instead of tool_result.content.

Example Usage (Before)

# MCP server (2025-11-05 spec) returns:
# {"content": [], "structuredContent": {"success": true, "data": {...}}}
# → _mcp_content_to_langchain returns ""
# → Bedrock raises ValidationException: tool_use ids found without tool_result blocks

Example Usage (After)

# Same response from MCP server
# → _mcp_content_to_langchain returns json.dumps({"success": true, "data": {...}})
# → Bedrock accepts it, agent continues normally

Testing

- Updated 3 existing tests to pass CallToolResult instead of a raw list (required by new signature)
- Added test_empty_content_with_structured_content_returns_jsonconfirms structuredContent fallback works
- Added test_empty_content_without_structured_content_returns_placeholderconfirms "(no content)" is returned instead of "" when both fields are empty
- All 6 tests pass

Backwards Compatibility

No breaking change for existing users. The only behavioral difference is when content[] is emptypreviously returned "", now returns structured data or a placeholder. Both are non-empty strings compatible
with all LLM providers.

Related Issues

Closes #1604

@github-actions github-actions Bot added the Python label Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty tool result ('') causes Bedrock ValidationException when MCP server returns structuredContent with empty content[]

2 participants