Skip to content

fix: cap mcp below 2.0 and stop a failed mcp import breaking import any_agent - #951

Merged
njbrake merged 1 commit into
mainfrom
fix/mcp-v2-import-break
Sep 21, 2026
Merged

njbrake merged 1 commit into
mainfrom
fix/mcp-v2-import-break

Conversation

@njbrake

@njbrake njbrake commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Description

mcp 2.0 renamed streamablehttp_client to streamable_http_client. The dependency was uncapped (mcp>=1.5.0), so a fresh install resolves mcp 2.x and import any_agent fails with NameError: name 'MCPTool' is not defined.

Two separate fixes:

  1. Cap at mcp>=1.5.0,<2. This is what unbreaks installs. Soft deprecation means no migration to mcp 2.x for now.
  2. mcp_client.py records missing_mcp_error and raises a readable ImportError from model_post_init, but that guard never ran: ClientSession and MCPTool appear in annotations evaluated at class creation, so import raised NameError first. Both now get placeholders in the except ImportError branch.

Fix 2 alone is not enough. mozilla-ai-tinyagent 0.1.1 has the identical bug and is imported first via any_agent.config, so the cap is what protects users today. Reported upstream at mozilla-ai/tinyagent#22.

Verified against a real mcp 2.2.0 install: with both copies guarded, import any_agent succeeds and MCPClient(...) raises the intended ImportError.

PR Type

  • Bug Fix

Relevant issues

Upstream: mozilla-ai/tinyagent#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.

Note on "existing tests pass": tests/unit gives 278 passed with 4 failures that are present on main before this change and unrelated to it (any-llm-sdk no longer has a gateway provider, plus two OpenAI-path tests).

AI Usage Information

  • AI Model used: Claude Opus 5

  • AI Developer Tool used: Claude Code

  • Any other info you'd like to share: Written under @njbrake's direction. The reasoning and decisions are his.

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

@codecov

codecov Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tests/unit/tools/mcp/test_mcp_import_guard.py 97.91% 0 Missing and 1 partial ⚠️
Files with missing lines Coverage Δ
src/any_agent/tools/mcp/mcp_client.py 77.94% <100.00%> (-3.41%) ⬇️
tests/unit/tools/mcp/test_mcp_import_guard.py 97.91% <97.91%> (ø)

... and 42 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…any_agent`

mcp 2.0 renamed `mcp.client.streamable_http.streamablehttp_client` to
`streamable_http_client`. The dependency was declared `mcp>=1.5.0` with no upper
bound, so a fresh install resolves mcp 2.x and `import any_agent` fails outright
with `NameError: name 'MCPTool' is not defined`.

Two separate problems, fixed separately:

1. Cap the dependency at `mcp>=1.5.0,<2`. This is what unbreaks installs.
   any-agent is in soft deprecation and is not migrating to mcp 2.x.

2. `mcp_client.py` already tries to degrade gracefully: it records
   `missing_mcp_error` and raises a readable ImportError from
   `model_post_init`. That guard never ran, because `ClientSession` and
   `MCPTool` are referenced in annotations evaluated at class-creation time,
   so the module raised NameError during import instead. Bind both names to
   placeholders in the except branch so the guard works as intended.

Note that (2) alone does not fix the import under mcp 2.x, because
mozilla-ai-tinyagent 0.1.1 carries the identical bug and is imported first via
`any_agent.config`. It needs the same fix upstream; the cap in (1) is what
protects any-agent users today.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@njbrake
njbrake force-pushed the fix/mcp-v2-import-break branch from d4410a2 to b842b7c Compare September 21, 2026 15:39
@njbrake
njbrake merged commit 968d94a into main Sep 21, 2026
3 of 10 checks passed
@njbrake
njbrake deleted the fix/mcp-v2-import-break branch September 21, 2026 15:48
@njbrake
njbrake restored the fix/mcp-v2-import-break branch September 21, 2026 15:48
@njbrake
njbrake deleted the fix/mcp-v2-import-break branch September 21, 2026 15:49
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.

1 participant