Skip to content

fix: log warning when native MCP config returns no tools#5160

Open
Aboudjem wants to merge 1 commit intocrewAIInc:mainfrom
Aboudjem:fix/native-mcp-no-tools-warning
Open

fix: log warning when native MCP config returns no tools#5160
Aboudjem wants to merge 1 commit intocrewAIInc:mainfrom
Aboudjem:fix/native-mcp-no-tools-warning

Conversation

@Aboudjem
Copy link
Copy Markdown

@Aboudjem Aboudjem commented Mar 29, 2026

Summary

  • Initialize tools_list = [] before the async event-loop block in _resolve_native() to prevent UnboundLocalError when asyncio.run() raises a RuntimeError that falls through without assignment
  • Add logger.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 when tool_filter removes all of them
  • Add 3 tests covering: empty server response, filter removing all tools, and the UnboundLocalError scenario

Closes #5116

Test plan

  • TestResolveNativeNoToolsWarning::test_logs_warning_when_server_returns_no_tools — verifies warning is logged when MCP server returns empty tool list
  • TestResolveNativeNoToolsWarning::test_logs_warning_when_tool_filter_removes_all_tools — verifies warning is logged when tool_filter rejects every tool
  • TestResolveNativeNoToolsWarning::test_no_unbound_local_error_on_failed_async_run — verifies no UnboundLocalError when asyncio.run() raises an unmatched RuntimeError

🤖 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 initializes tools_list defensively and logs a warning + returns empty when the server returns no tools (or when tool_filter removes 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 UnboundLocalError when async discovery fails.

Written by Cursor Bugbot for commit e973cab. This will update automatically on new commits. Configure here.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] MCPToolResolver does not log warning when native MCP config returns no tools

1 participant