Skip to content

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

@AmoyCherry

Description

@AmoyCherry

Description

MCPToolResolver._resolve_native() silently returns an empty tool list when:

The MCP server returns no tools, or
The tool_filter removes all tools.

The empty tools_list can trigger the error at tool_resolver.py", line 412:

for tool_def in tools_list:
                  ^^^^^^^^^^
UnboundLocalError: cannot access local variable 'tools_list' where it is not associated with a value

There is no warning logged, making it very hard for users to understand why their MCP server (Stdio / HTTP / SSE) is not providing any tools.
In contrast, _resolve_external() (for HTTPS URLs) does log a clear warning:

No tools discovered from MCP server: {server_url}

Affected Code

File: crewai/mcp/tool_resolver.py
Method: MCPToolResolver._resolve_native() (around line 412, right after tool filtering)

Steps to Reproduce

  1. Configure an agent with a native MCP server via MCPServerStdio, MCPServerHTTP, or MCPServerSSE that either has no tools or uses a tool_filter that returns nothing.
  2. Add it to the agent’s mcps list.
  3. Run the agent/task → zero tools are available and no warning appears in the logs.

Expected behavior

A clear warning should be logged when no tools are discovered after listing + filtering, exactly like the external resolver path. Instead of the current 500 Error.

Screenshots/Code snippets

            tools = []
            for tool_def in tools_list:
                tool_name = tool_def.get("name", "")
                original_tool_name = tool_def.get("original_name", tool_name)
                if not tool_name:
                    continue

Operating System

Ubuntu 20.04

Python Version

3.12

crewAI Version

latest

crewAI Tools Version

latest

Virtual Environment

Venv

Evidence

Traceback (most recent call last):
  File ".../python3.12/site-packages/crewai/mcp/tool_resolver.py", line 412, in _resolve_native
    for tool_def in tools_list:
                    ^^^^^^^^^^
UnboundLocalError: cannot access local variable 'tools_list' where it is not associated with a value

Possible Solution

            if not tools_list:
                self._logger.log(
                    "warning",
                    f"No tools discovered from MCP server: {server_name}",
                )
                return cast(list[BaseTool], []), []

Additional context

It's an apparent bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions