Skip to content

fix(mcp): keep MCPClient importable when mcp import fails - #25

Open
tonycoder-hub wants to merge 1 commit into
mozilla-ai:mainfrom
tonycoder-hub:fix/mcp-import-nameerror-22
Open

tonycoder-hub wants to merge 1 commit into
mozilla-ai:mainfrom
tonycoder-hub:fix/mcp-import-nameerror-22

Conversation

@tonycoder-hub

Copy link
Copy Markdown

Description

mcp 2.x renamed streamablehttp_client to streamable_http_client. A fresh install of mozilla-ai-tinyagent resolves mcp>=2, the import in mcp_client.py fails, and class-body annotations then raise NameError: name 'MCPTool' is not defined before model_post_init can raise the intended ImportError.

This PR:

  1. Caps the dependency at mcp>=1.5.0,<2 so installs stay on the API this package uses.
  2. Binds annotation placeholders in the except ImportError branch so a missing/incompatible mcp degrades to the existing ImportError guard instead of a NameError.
  3. Adds a unit regression that simulates the mcp>=2 missing-name shape.

PR Type

  • Bug Fix

Relevant issues

Fixes #22

Checklist

  • I understand the code I am submitting.
  • I have added unit tests that prove my fix/feature works.
  • I have run this code locally and verified it fixes the issue.
  • New and existing tests pass locally.
  • Documentation was updated where necessary.
  • I have read and followed the contribution guidelines.
  • AI Usage:
    • No AI was used.
    • AI was used for drafting/refactoring.
    • This is fully AI-generated.

AI Usage Information

  • AI Model used: gemini-3.8-flash-high (via local CPA)

  • AI Developer Tool used: Cursor / F.R.I.D.A.Y. agent assist

  • Any other info you'd like to share: Fix direction matches the issue report (cap mcp<2 + ImportError placeholders). Verified import with mcp 2.2.0 raises ImportError instead of NameError, and with mcp 1.x the module loads cleanly.

  • I am an AI Agent filling out this form (check box if true).

Cap mcp at <2 (2.x renamed streamablehttp_client) and bind annotation
placeholders in the ImportError path so class body evaluation cannot
raise NameError before model_post_init's ImportError guard.

Fixes mozilla-ai#22

Signed-off-by: Tony Coder <407243179@qq.com>

This branch has not been deployed

No deployments
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.

import tinyagent raises NameError with mcp >= 2.0

1 participant