Skip to content

[Bug Fix] Replace non-existent McpError with FastMCPError in MCP tools - #239

Merged
bruuuuuceliu merged 1 commit into
ANative-Lab:mainfrom
rawathemant246:fix/fastmcp-mcperror-import
Apr 15, 2026
Merged

bruuuuuceliu merged 1 commit into
ANative-Lab:mainfrom
rawathemant246:fix/fastmcp-mcperror-import

Conversation

@rawathemant246

Copy link
Copy Markdown
Contributor

Summary

Fixes #238

evoagentx/tools/mcp.py imports McpError from fastmcp.exceptions, but this class does not exist in any released version of fastmcp (tested 1.0 through 3.2.4). Since tools/__init__.py eagerly imports MCPToolkit, this ImportError cascades and breaks all core imports — agents, workflows, and prompts all fail.

Root Cause

The import chain that fails:

evoagentx.workflow (or .agents, .prompts)
  → evoagentx.prompts.template
    → evoagentx.tools.__init__    (line 9: from .mcp import MCPToolkit)
      → evoagentx.tools.mcp       (line 25: from fastmcp.exceptions import ClientError, McpError)
        → ImportError: cannot import name 'McpError'

fastmcp.exceptions exports FastMCPError as the base exception class — not McpError. Here's the actual exception hierarchy in fastmcp 2.2.0:

Exception Parent
FastMCPError Exception (base for all MCP errors)
ClientError Exception
ToolError FastMCPError
ResourceError FastMCPError
PromptError FastMCPError
ValidationError FastMCPError

Changes

File Change
evoagentx/tools/mcp.py McpError → FastMCPError (import on line 25, except clause on line 247)
docs/tutorial/mcp.md Updated import, except clause, and troubleshooting docs to match
pyproject.toml Pin fastmcp>=2.2.0,<3.0 (2.2.0 is the first version with both Client and ClientError)

Reproduction

pip install evoagentx==0.1.0
python -c "from evoagentx.workflow.workflow_graph import WorkFlowGraph"
# ImportError: cannot import name 'McpError' from 'fastmcp.exceptions'

Testing

After the fix:

python -c "from evoagentx.tools.mcp import MCPToolkit, MCPClient, MCPTool; print('OK')"
# OK

Compatibility

Tested across fastmcp versions:

Version Client ClientError FastMCPError Works after fix
< 2.2.0 No No No No (missing Client)
2.2.0 Yes Yes Yes Yes
2.2.x - 2.14.x Yes Yes Yes Yes
3.x API changed — — Excluded by pin

The pin >=2.2.0,<3.0 ensures a working range.

`McpError` does not exist in any released version of fastmcp (tested
1.0 through 3.2.4). This causes an ImportError in `tools/mcp.py` that
cascades through the entire package — because `tools/__init__.py`
eagerly imports MCPToolkit, every import touching agents, workflows,
or prompts fails with:

  ImportError: cannot import name 'McpError' from 'fastmcp.exceptions'

Changes:
- Replace `McpError` with `FastMCPError` (the actual base exception
  class in fastmcp) in `evoagentx/tools/mcp.py` (import + except)
- Update `docs/tutorial/mcp.md` to match
- Pin `fastmcp>=2.2.0,<3.0` in pyproject.toml — 2.2.0 is the first
  version that exports both `Client` and `ClientError`

Fixes ANative-Lab#238

@bruuuuuceliu bruuuuuceliu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FastMCPError is the right base class from fastmcp's own exception hierarchy — good fix to align with that. Thanks!

@bruuuuuceliu
bruuuuuceliu merged commit 52a0f93 into ANative-Lab:main Apr 15, 2026
2 of 4 checks passed
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] evoagentx.tools.mcp imports non-existent McpError from fastmcp — breaks all imports

2 participants