fix: log warning when native MCP config returns no tools#5160
Open
Aboudjem wants to merge 1 commit intocrewAIInc:mainfrom
Open
fix: log warning when native MCP config returns no tools#5160Aboudjem wants to merge 1 commit intocrewAIInc:mainfrom
Aboudjem wants to merge 1 commit intocrewAIInc:mainfrom
Conversation
Initialize `tools_list = []` before the async event-loop block in `_resolve_native()` to prevent `UnboundLocalError` when `asyncio.run()` raises a `RuntimeError` that does not match the re-raise conditions. Add a warning log after tool listing and filtering, matching the existing pattern in `_resolve_external()`, so users get a clear diagnostic when their native MCP server (Stdio/HTTP/SSE) provides no tools or when `tool_filter` removes all of them. Closes crewAIInc#5116 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.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
tools_list = []before the async event-loop block in_resolve_native()to preventUnboundLocalErrorwhenasyncio.run()raises aRuntimeErrorthat falls through without assignmentlogger.warning()after tool listing + filtering in_resolve_native(), matching the existing pattern in_resolve_external(), so users get a clear diagnostic when their native MCP server (Stdio/HTTP/SSE) returns no tools or whentool_filterremoves all of themUnboundLocalErrorscenarioCloses #5116
Test plan
TestResolveNativeNoToolsWarning::test_logs_warning_when_server_returns_no_tools— verifies warning is logged when MCP server returns empty tool listTestResolveNativeNoToolsWarning::test_logs_warning_when_tool_filter_removes_all_tools— verifies warning is logged whentool_filterrejects every toolTestResolveNativeNoToolsWarning::test_no_unbound_local_error_on_failed_async_run— verifies noUnboundLocalErrorwhenasyncio.run()raises an unmatchedRuntimeError🤖 Generated with Claude Code
Note
Low Risk
Low risk: only adjusts native MCP tool discovery to handle empty results/edge-case errors more gracefully and adds tests; no protocol or execution-path changes when tools are present.
Overview
Native MCP tool resolution (
_resolve_native) now initializestools_listdefensively and logs a warning + returns empty when the server returns no tools (or whentool_filterremoves them all), aligning behavior with external MCP URL resolution.Adds tests to verify the warning is emitted for empty discovery, filter-all scenarios, and to prevent
UnboundLocalErrorwhen async discovery fails.Written by Cursor Bugbot for commit e973cab. This will update automatically on new commits. Configure here.