Fix NameError when using tools without MCP package installed#262
Open
matthewojenkins wants to merge 1 commit intoandrewyng:mainfrom
Open
Fix NameError when using tools without MCP package installed#262matthewojenkins wants to merge 1 commit intoandrewyng:mainfrom
matthewojenkins wants to merge 1 commit intoandrewyng:mainfrom
Conversation
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.
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.

Problem
When using tools with
client.chat.completions.create()without the MCP package installed, users get:This occurs because the code in
_process_mcp_configstries to callis_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_configfunction in theexcept ImportErrorblock that provides the same detection logic, allowing the code to:Changes
aisuite/client.py: Added fallbackis_mcp_configfunction when MCP import failstests/client/test_mcp_fallback.py: Added tests for the fallback behaviorTesting
All existing tests pass, plus new tests specifically for the fallback behavior.