feat(mcp): promote content-to-tool-result method to public API#2370
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
e832817 to
ab5325f
Compare
|
Assessment: Request Changes The core idea — promoting the private mapping method to a public extension point — is well-motivated and the implementation is clean for the simple case. However, there's a backwards compatibility gap that needs to be addressed before merge. Review Details
The scope and tests are appropriate for the change — just the compat bridge needs to be added. |
|
TL;DR: Right direction, but the deprecation shim is inverted — existing subclasses that override the old 🔴 The deprecation bug (blocking)The call site now dispatches through the new public name, and the old name is kept as a delegating wrapper: # call site:
mc := self.map_mcp_content_to_tool_result_content(content)
# old name delegates forward:
def _map_mcp_content_to_tool_result_content(self, content):
warnings.warn(...)
return self.map_mcp_content_to_tool_result_content(content)Today the only extension point is overriding ✅ Suggested fix — runtime override detectiondef map_mcp_content_to_tool_result_content(self, content):
cls = type(self)
if (
cls.map_mcp_content_to_tool_result_content is MCPClient.map_mcp_content_to_tool_result_content
and cls._map_mcp_content_to_tool_result_content is not MCPClient._map_mcp_content_to_tool_result_content
):
warnings.warn(
"Overriding _map_mcp_content_to_tool_result_content is deprecated. "
"Override map_mcp_content_to_tool_result_content instead.",
DeprecationWarning, stacklevel=2,
)
return cls._map_mcp_content_to_tool_result_content(self, content)
# ... real mapping logic ...This keeps legacy overrides working and emits a migration warning during the deprecation window. 🧪 Missing test coverageThe two new tests don't cover the actual breakage:
Neither tests the realistic case: a subclass that overrides the OLD name still gets invoked (with a warning). That's exactly where the bug lives — please add it. 💡 Bigger-picture (non-blocking)
|
|
Still discussing offline about the right direction to go in terms of when to make the breaking change |
ab5325f to
dc5fd46
Compare
Discussed offline, team is aligned with the breaking change of making this public without maintaining the deprecated method
|
Assessment: Request Changes Agreeing with the existing feedback from @opieter-aws and @agent-of-mkmeral — the backwards compatibility gap for existing subclass overrides of Additional observations on the latest revision
The direction and scope are good — just waiting on the backwards compat decision. |
7549cc7
into
strands-agents:main
Description
Renames
MCPClient._map_mcp_content_to_tool_result_contenttomap_mcp_content_to_tool_result_content, making subclass override an officially supported extension pattern for intercepting or transforming MCP content blocks before they reach the model.(Also maintains the underscored version with backwards compatibility with a
DeprecationWarning)Related Issues
Closes #2251
Type of Change
New feature
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
hatch run prepare, added a testChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.