Skip to content

fix(mcp): support mcp Python SDK 2.x - #6764

Open
arimu1 wants to merge 1 commit into
crewAIInc:mainfrom
arimu1:fix/support-mcp-2.x
Open

fix(mcp): support mcp Python SDK 2.x#6764
arimu1 wants to merge 1 commit into
crewAIInc:mainfrom
arimu1:fix/support-mcp-2.x

Conversation

@arimu1

@arimu1 arimu1 commented Aug 1, 2026

Copy link
Copy Markdown

Summary

Fixes #6750 by allowing the MCP Python SDK 2.x line and adapting the small set of call sites that break on 2.0.

Dependency pins

  • crewai: mcp~=1.28.1mcp>=1.28.1,<3
  • crewai-tools[mcp]: mcp>=1.28.1,<2mcp>=1.28.1,<3
  • uv.lock upgraded to mcp==2.0.0 (still satisfies the lower bound for 1.28.x)

Code changes (mcp 1.x + 2.x compatible)

Centralized helpers in crewai.mcp._compat:

  1. Streamable HTTP — use streamable_http_client (both lines); normalize 3-tuple (1.x) vs 2-tuple (2.x) yields; pass headers via create_mcp_http_client / http_client= (required in 2.0).
  2. Tool schema / error flags — read input_schema / is_error with camelCase fallbacks so both SDKs work. CrewAI’s public tool-def dict key stays inputSchema.

Touched call sites: transports/http.py, tool_resolver.py, mcp_tool_wrapper.py, client.py, crewai_tools MCP adapter.

Notes

  • crewai-tools[mcp] still depends on third-party mcpadapt. That package does not yet declare a 2.x upper/lower policy; this PR unblocks install and fixes our direct SDK usage. Full adapter path quality with mcp 2.0 may still depend on mcpadapt.
  • Dual-compatible on purpose so existing 1.28 installs keep working.

Test plan

  • uv lock --upgrade-package mcpmcp==2.0.0
  • uv run pytest lib/crewai/tests/mcp/ -x -q40 passed
  • uv run pytest lib/crewai/tests/tools/test_tool_failure.py -k mcp -q3 passed
  • ruff check / ruff format on touched paths

@arimu1

arimu1 commented Aug 1, 2026

Copy link
Copy Markdown
Author

AI disclosure: This PR was produced with AI assistance (Cursor/Grok implementator) under human direction. Per CONTRIBUTING, the `llm-generated` label should be applied — I do not have permission to add labels on this repo from a fork. Maintainers: please add the `llm-generated` label if required for triage.

Tip: `0ce769a389d4dcbd8e37f69c768af31c49e46a9b`

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ce914ec3-8a36-4ec0-9146-592d09c19421

📥 Commits

Reviewing files that changed from the base of the PR and between 18c52c4 and 38e9405.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • lib/crewai-tools/pyproject.toml
  • lib/crewai-tools/src/crewai_tools/adapters/mcp_adapter.py
  • lib/crewai/pyproject.toml
  • lib/crewai/src/crewai/mcp/_compat.py
  • lib/crewai/src/crewai/mcp/client.py
  • lib/crewai/src/crewai/mcp/tool_resolver.py
  • lib/crewai/src/crewai/mcp/transports/http.py
  • lib/crewai/src/crewai/tools/mcp_tool_wrapper.py
🚧 Files skipped from review as they are similar to previous changes (8)
  • lib/crewai/pyproject.toml
  • lib/crewai-tools/pyproject.toml
  • lib/crewai/src/crewai/tools/mcp_tool_wrapper.py
  • lib/crewai/src/crewai/mcp/client.py
  • lib/crewai-tools/src/crewai_tools/adapters/mcp_adapter.py
  • lib/crewai/src/crewai/mcp/_compat.py
  • lib/crewai/src/crewai/mcp/transports/http.py
  • lib/crewai/src/crewai/mcp/tool_resolver.py

📝 Walkthrough

Walkthrough

The change adds MCP 1.x and 2.x compatibility helpers, broadens MCP dependency constraints, normalizes stream transport APIs, and updates schema and error-field access across CrewAI MCP integrations.

Changes

MCP compatibility support

Layer / File(s) Summary
Compatibility helpers and dependency ranges
lib/crewai/pyproject.toml, lib/crewai-tools/pyproject.toml, lib/crewai/src/crewai/mcp/_compat.py
MCP dependencies now allow versions below 3. Compatibility helpers normalize transport streams, create HTTP clients, manage contexts, and read schema and error fields across SDK versions.
HTTP transport lifecycle
lib/crewai/src/crewai/mcp/transports/http.py
HTTPTransport uses compatibility helpers and AsyncExitStack for connection setup, timeout handling, failure cleanup, and disconnection.
MCP tool and result integration
lib/crewai/src/crewai/mcp/client.py, lib/crewai/src/crewai/mcp/tool_resolver.py, lib/crewai/src/crewai/tools/mcp_tool_wrapper.py, lib/crewai-tools/src/crewai_tools/adapters/mcp_adapter.py
Tool discovery, execution, wrapping, and adaptation use normalized stream handling and support snake_case and camelCase MCP schema and error fields.

Sequence Diagram(s)

sequenceDiagram
  participant tool_resolver
  participant open_streamable_http
  participant MCPServer
  participant tool_input_schema
  tool_resolver->>open_streamable_http: open normalized HTTP streams
  open_streamable_http->>MCPServer: connect using streamable HTTP
  MCPServer-->>tool_resolver: return MCP tools
  tool_resolver->>tool_input_schema: read normalized tool schema
  tool_input_schema-->>tool_resolver: return schema
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The code covers the listed MCP 2.x changes, but uv.lock is excluded by !**/*.lock, so the mcp==2.0.0 lock update cannot be verified. Review uv.lock or provide lockfile evidence to verify that mcp==2.0.0 is recorded and satisfies the updated constraints.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes support for MCP Python SDK 2.x, which is the primary change.
Description check ✅ Passed The description explains the dependency updates, compatibility changes, affected call sites, and test plan.
Out of Scope Changes check ✅ Passed The reviewed changes are limited to MCP dependency updates and compatibility changes required by issue #6750.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
lib/crewai-tools/src/crewai_tools/adapters/mcp_adapter.py (1)

54-60: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider reusing the shared schema-fallback helper instead of duplicating it.

crewai.mcp._compat.tool_input_schema already implements this exact MCP 1.x/2.x schema-fallback rule. Duplicating the logic here risks the two implementations diverging if one is updated later.

Note that crewai.mcp._compat is a private (underscore-prefixed) module. If reused across crewai-tools, consider exposing a small public alias in crewai.mcp rather than importing the private module directly.

♻️ Proposed refactor
-            # mcp 1.x: inputSchema; mcp 2.x: input_schema (camelCase alias still parses)
-            input_schema = (
-                getattr(mcp_tool, "input_schema", None)
-                or getattr(mcp_tool, "inputSchema", None)
-                or {}
-            )
+            from crewai.mcp._compat import tool_input_schema
+
+            input_schema = tool_input_schema(mcp_tool)
             args_model = create_model_from_schema(input_schema)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/crewai-tools/src/crewai_tools/adapters/mcp_adapter.py` around lines 54 -
60, Update the MCP adapter’s schema lookup near create_model_from_schema to
reuse the shared crewai.mcp schema-fallback helper instead of duplicating
input_schema/inputSchema handling. Because _compat is private, expose or use a
public alias from crewai.mcp rather than importing the private module directly,
while preserving the existing empty-schema fallback.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@lib/crewai-tools/src/crewai_tools/adapters/mcp_adapter.py`:
- Around line 54-60: Update the MCP adapter’s schema lookup near
create_model_from_schema to reuse the shared crewai.mcp schema-fallback helper
instead of duplicating input_schema/inputSchema handling. Because _compat is
private, expose or use a public alias from crewai.mcp rather than importing the
private module directly, while preserving the existing empty-schema fallback.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d439992f-d6cf-4b2f-ace8-47981db9d957

📥 Commits

Reviewing files that changed from the base of the PR and between c8f441c and 0ce769a.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • lib/crewai-tools/pyproject.toml
  • lib/crewai-tools/src/crewai_tools/adapters/mcp_adapter.py
  • lib/crewai/pyproject.toml
  • lib/crewai/src/crewai/mcp/_compat.py
  • lib/crewai/src/crewai/mcp/client.py
  • lib/crewai/src/crewai/mcp/tool_resolver.py
  • lib/crewai/src/crewai/mcp/transports/http.py
  • lib/crewai/src/crewai/tools/mcp_tool_wrapper.py

Allow mcp>=1.28.1,<3 and adapt streamable HTTP + tool schema/error
field access for the 2.0 API while remaining compatible with 1.28.x.

Fixes crewAIInc#6750
@arimu1
arimu1 force-pushed the fix/support-mcp-2.x branch from 0ce769a to 38e9405 Compare August 6, 2026 00:58
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

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.

Support mcp 2.x (Python SDK): pin blocks mcp 2.0.0

1 participant