fix: correct special tool detection for MCP-prefixed tools #1281
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.
Features
_is_special_toolso that MCP-wrapped tools (named likemcp_{server_id}_{tool_name}) are correctly recognized as special tools.terminatetool is treated as special even when invoked via MCP, e.g.mcp_server_id_terminate._should_finish_executionlogic with MCP naming conventions so that calls to MCPterminatetools correctly finish the agent execution.Influence
Without this change, MCP
terminatetools are not recognized as special, so:_handle_special_toolis never invoked formcp_{server_id}_terminate.With the new detection logic:
terminatetools behave consistently with non-MCPterminatetools.Result
_is_special_toolnow correctly detects:terminate(and other special tools) by exact name.mcp_server_id_terminateby suffix match._should_finish_executionnow uses a lowercase name and supports bothterminateand names ending in_terminate, aligning with the MCP naming scheme.terminatetool still terminates the agent as before.terminatetool (e.g.mcp_test_terminate) correctly triggers special-tool handling and finishes execution.