Skip to content

Fix NameError when using tools without MCP package installed#262

Open
matthewojenkins wants to merge 1 commit intoandrewyng:mainfrom
matthewojenkins:fix/mcp-import-error
Open

Fix NameError when using tools without MCP package installed#262
matthewojenkins wants to merge 1 commit intoandrewyng:mainfrom
matthewojenkins:fix/mcp-import-error

Conversation

@matthewojenkins
Copy link

Problem

When using tools with client.chat.completions.create() without the MCP package installed, users get:

NameError: name 'is_mcp_config' is not defined

This occurs because the code in _process_mcp_configs tries to call is_mcp_config() to check if any tools are MCP configs (to provide a helpful error message), but the function was only imported when MCP was available.

Solution

Added a fallback is_mcp_config function in the except ImportError block that provides the same detection logic, allowing the code to:

  1. Detect if users are trying to use MCP configs without MCP installed
  2. Provide a helpful error message in that case
  3. Allow regular function tools to work without MCP installed

Changes

  • aisuite/client.py: Added fallback is_mcp_config function when MCP import fails
  • tests/client/test_mcp_fallback.py: Added tests for the fallback behavior

Testing

All existing tests pass, plus new tests specifically for the fallback behavior.

When the MCP package is not installed, the is_mcp_config function was not
defined, causing a NameError when using tools with chat completions:

    NameError: name 'is_mcp_config' is not defined

This occurred because the code in _process_mcp_configs tried to call
is_mcp_config() to check if any tools were MCP configs (to provide a
helpful error message), but the function was only imported when MCP
was available.

The fix adds a fallback is_mcp_config function in the except ImportError
block that provides the same detection logic, allowing the code to:
1. Detect if users are trying to use MCP configs without MCP installed
2. Provide a helpful error message in that case
3. Allow regular function tools to work without MCP installed

Added tests to verify the fallback behavior.
@alzin
Copy link

alzin commented Jan 23, 2026

Yes, this appears in some steps of execution (Research)!

Screenshot 2026-01-23 at 16 00 09

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.

3 participants