fix(mcp): support mcp Python SDK 2.x - #6764
Conversation
|
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` |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (8)
🚧 Files skipped from review as they are similar to previous changes (8)
📝 WalkthroughWalkthroughThe 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. ChangesMCP compatibility support
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
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/crewai-tools/src/crewai_tools/adapters/mcp_adapter.py (1)
54-60: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider reusing the shared schema-fallback helper instead of duplicating it.
crewai.mcp._compat.tool_input_schemaalready 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._compatis a private (underscore-prefixed) module. If reused acrosscrewai-tools, consider exposing a small public alias increwai.mcprather 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
⛔ Files ignored due to path filters (1)
uv.lockis excluded by!**/*.lock
📒 Files selected for processing (8)
lib/crewai-tools/pyproject.tomllib/crewai-tools/src/crewai_tools/adapters/mcp_adapter.pylib/crewai/pyproject.tomllib/crewai/src/crewai/mcp/_compat.pylib/crewai/src/crewai/mcp/client.pylib/crewai/src/crewai/mcp/tool_resolver.pylib/crewai/src/crewai/mcp/transports/http.pylib/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
0ce769a to
38e9405
Compare
|
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. |
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.1→mcp>=1.28.1,<3crewai-tools[mcp]:mcp>=1.28.1,<2→mcp>=1.28.1,<3uv.lockupgraded tomcp==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:streamable_http_client(both lines); normalize 3-tuple (1.x) vs 2-tuple (2.x) yields; pass headers viacreate_mcp_http_client/http_client=(required in 2.0).input_schema/is_errorwith camelCase fallbacks so both SDKs work. CrewAI’s public tool-def dict key staysinputSchema.Touched call sites:
transports/http.py,tool_resolver.py,mcp_tool_wrapper.py,client.py,crewai_toolsMCP adapter.Notes
crewai-tools[mcp]still depends on third-partymcpadapt. 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.Test plan
uv lock --upgrade-package mcp→mcp==2.0.0uv run pytest lib/crewai/tests/mcp/ -x -q→ 40 passeduv run pytest lib/crewai/tests/tools/test_tool_failure.py -k mcp -q→ 3 passedruff check/ruff formaton touched paths