fix: MCPToolResolver._resolve_native() UnboundLocalError when no tools found (#5116)#5118
Open
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Open
Conversation
… tools found Fixes #5116. MCPToolResolver._resolve_native() could raise UnboundLocalError when asyncio.run() raised a RuntimeError that didn't match the 'cancel scope' or 'task' conditions — the exception was silently swallowed leaving tools_list unbound. Changes: - Initialize tools_list to an empty list before the try block - Add early return with warning log when tools_list is empty (matching the existing behavior in _resolve_external) This covers three scenarios: 1. MCP server returns no tools 2. tool_filter removes all tools 3. RuntimeError swallowed without assigning tools_list Co-Authored-By: João <joao@crewai.com>
Contributor
Author
|
Prompt hidden (unlisted session) |
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: João <joao@crewai.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #5116.
MCPToolResolver._resolve_native()raisedUnboundLocalErrorontools_listwhen:tool_filterremoved all toolsRuntimeErrorwas caught but didn't match the"cancel scope"/"task"conditions, silently swallowing the exception and leavingtools_listunassignedChanges:
tools_list: list[dict[str, Any]] = []before the try block so it is always bound"warning"log whentools_listis empty after discovery + filtering — matching the existing behavior in_resolve_external()Three new tests cover: empty server response, filter-removes-all, and swallowed RuntimeError.
Review & Testing Checklist for Human
RuntimeErrorpaths (lines 367-381). Previously these crashed withUnboundLocalError; now they return([], []). Consider whether some of these errors (e.g. a genuine connection failure whose message doesn't contain"cancel scope"or"task") should instead propagate to the caller rather than being silently degraded to an empty tool list.tool_filterreturning nothing, run a task, and confirm a clear warning appears instead of a 500-level traceback.Notes
"No tools discovered from MCP server: {server_name}") is intentionally consistent with the existing message in_resolve_external().asyncioimport flagged in the initial review has been removed in a follow-up commit.Link to Devin session: https://app.devin.ai/sessions/7bfda4a03b3b49e780771f30d635512f