fix: handle Pydantic TextContent objects in MCP response parser #14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes AttributeError in v1.0.3 where response parser couldn't handle MCP SDK's Pydantic
TextContentobjects, and refactors the architecture to establish proper separation of concerns.Problem
The MCP SDK returns Pydantic objects (e.g.,
TextContent), not plain dicts. In v1.0.3, response parsing logic was added that useditem.get("type")anditem.get("text"), which only works on dicts:This was a regression - v1.0.2 worked correctly.
Root Cause
The MCP adapter was passing MCP SDK-specific Pydantic objects directly to the generic response parser, violating protocol boundary separation. The parser had to handle both parsing AND protocol translation.
Solution
Architectural fix with proper separation of concerns:
mcp.py): Added_serialize_mcp_content()to convert Pydantic objects to plain dicts at the protocol boundaryresponse_parser.py): Simplified to only handle plain dicts, removed dual-mode helper functionBenefits
list[dict[str, Any]](no more| Any)Commits
get_field()helper (f29179b)Tests
Response Parser Tests:
Protocol Adapter Tests:
All tests passing (15/15 for affected modules).
Test plan
🤖 Generated with Claude Code