Skip to content

fix: remove_all_tools missing MCP and reasoning item types#2700

Draft
joaquinhuigomez wants to merge 3 commits intoopenai:mainfrom
joaquinhuigomez:fix/remove-all-tools-missing-types
Draft

fix: remove_all_tools missing MCP and reasoning item types#2700
joaquinhuigomez wants to merge 3 commits intoopenai:mainfrom
joaquinhuigomez:fix/remove-all-tools-missing-types

Conversation

@joaquinhuigomez
Copy link

Summary

  • _remove_tool_types_from_input (which filters raw input history dicts) was missing reasoning, mcp_call, mcp_list_tools, mcp_approval_request, and mcp_approval_response types. This meant MCP tool items and orphaned reasoning items leaked through the remove_all_tools handoff filter.
  • _remove_tools_from_items (which filters RunItem objects) was missing MCPListToolsItem, MCPApprovalRequestItem, and MCPApprovalResponseItem.
  • The two functions are now consistent: both filter all tool-related item types including MCP and reasoning.

Relates to #464 and #1167 (MCP tool handling), and partially addresses the data consistency aspect of #2151 (handoff filters producing inconsistent state).

Test plan

  • Updated existing test test_removes_tools_from_new_items_and_history to expect reasoning items filtered from raw input (was 3, now 2)
  • Added test_removes_reasoning_from_input_history - verifies orphaned reasoning items are removed from raw input
  • Added test_removes_mcp_items_from_input_history - verifies all 4 MCP item types removed from raw input
  • Added test_removes_mcp_run_items_from_new_items - verifies MCP RunItem types removed from pre_handoff_items and new_items
  • Added test_removes_mixed_mcp_and_function_items - end-to-end test mixing MCP, function, and reasoning items
  • All 34 tests in test_extension_filters.py pass

🤖 Generated with Claude Code

…put history

The `_remove_tool_types_from_input` function was missing several item types
that `_remove_tools_from_items` already handled for RunItem objects:
- `reasoning` items become orphaned when surrounding tool calls are stripped
- `mcp_call`, `mcp_list_tools`, `mcp_approval_request`, `mcp_approval_response`
  were not filtered, leaking MCP tool items through handoff boundaries

Also adds MCPListToolsItem, MCPApprovalRequestItem, and MCPApprovalResponseItem
to `_remove_tools_from_items` for consistency.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added the bug Something isn't working label Mar 17, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@seratch seratch marked this pull request as draft March 17, 2026 23:25
…filters

Assert items are not str before calling .get() to satisfy mypy's
union-attr check on the input_history item type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants