Revert "fix: make MCP package import optional to prevent errors when not installed"#1098
Revert "fix: make MCP package import optional to prevent errors when not installed"#1098MervinPraison wants to merge 1 commit intomainfrom
Conversation
π WalkthroughWalkthroughThis PR removes conditional import guards for MCP (Model Context Protocol) components across three modules, converting them from optional to unconditional imports. The accompanying test module validating optional import behavior is deleted, reflecting the architectural shift away from optional MCP support. Changes
Estimated code review effortπ― 3 (Moderate) | β±οΈ ~20 minutes Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touchesβ Passed checks (3 passed)
β¨ Finishing touches
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 |
Summary of ChangesHello @MervinPraison, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request performs a full revert of a previous change that aimed to make the Model Context Protocol (MCP) package an optional dependency. The core impact is that Highlights
π§ New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with π and π on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
PR Compliance Guide πBelow is a summary of compliance checks for this PR:
Compliance status legendπ’ - Fully Compliantπ‘ - Partial Compliant π΄ - Not Compliant βͺ - Requires Further Human Verification π·οΈ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions β¨Explore these optional code suggestions:
|
|||||||||
There was a problem hiding this comment.
Code Review
This pull request correctly reverts the optional import handling for the MCP package, making it a required dependency for the MCP-related modules. The changes simplify the code by removing conditional logic and flags, which improves clarity and maintainability. The updated aiohttp import handling to fail faster is also a good improvement. The deletion of the test file for the removed optional import functionality is appropriate. One thing to consider for a follow-up is the lazy-loading mechanism in praisonaiagents/__init__.py. Currently, it catches the ImportError when mcp is not installed and causes from praisonaiagents import MCP to assign None to MCP. This can lead to a less clear TypeError when a user tries to instantiate MCP(). To make mcp a truly required dependency at the package level, you might want to let the ImportError propagate from __init__.py as well. Overall, the changes in this PR are solid and a good step towards simplifying the dependency management.
There was a problem hiding this comment.
Actionable comments posted: 0
π§Ή Nitpick comments (1)
src/praisonai-agents/praisonaiagents/mcp/mcp_http_stream.py (1)
19-23: MCP and aiohttp are now required dependencies.The unconditional import of
ClientSessionand the ImportError for missingaiohttpestablish these as mandatory dependencies. The error message provides helpful installation guidance.Optional: Follow exception chaining best practice
Per static analysis, use
raise ... from Noneto suppress exception context when the ImportError is intentional:try: import aiohttp except ImportError: - raise ImportError("aiohttp is required for HTTP Stream transport. Install with: pip install praisonaiagents[mcp]") + raise ImportError("aiohttp is required for HTTP Stream transport. Install with: pip install praisonaiagents[mcp]") from NoneThis clarifies that the new exception is not caused by the caught ImportError but is an intentional error message.
π Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
π Files selected for processing (4)
src/praisonai-agents/praisonaiagents/mcp/mcp.pysrc/praisonai-agents/praisonaiagents/mcp/mcp_http_stream.pysrc/praisonai-agents/praisonaiagents/mcp/mcp_sse.pysrc/praisonai-agents/tests/test_mcp_optional_import.py
π€ Files with no reviewable changes (1)
- src/praisonai-agents/tests/test_mcp_optional_import.py
π§° Additional context used
π Path-based instructions (2)
src/praisonai-agents/praisonaiagents/**/*.py
π CodeRabbit inference engine (src/praisonai-agents/CLAUDE.md)
Support async execution using
await workflow.astart()andawait agent.aexecute(task)for asynchronous task processing
Files:
src/praisonai-agents/praisonaiagents/mcp/mcp_sse.pysrc/praisonai-agents/praisonaiagents/mcp/mcp_http_stream.pysrc/praisonai-agents/praisonaiagents/mcp/mcp.py
src/praisonai-agents/praisonaiagents/mcp/**/*.py
π CodeRabbit inference engine (src/praisonai-agents/CLAUDE.md)
Use MCP (Model Context Protocol) server with Server-Sent Events (SSE) support for distributed tool execution and real-time communication
Files:
src/praisonai-agents/praisonaiagents/mcp/mcp_sse.pysrc/praisonai-agents/praisonaiagents/mcp/mcp_http_stream.pysrc/praisonai-agents/praisonaiagents/mcp/mcp.py
π§ Learnings (1)
π Learning: 2025-12-30T16:10:06.589Z
Learnt from: CR
Repo: MervinPraison/PraisonAI PR: 0
File: src/praisonai-agents/CLAUDE.md:0-0
Timestamp: 2025-12-30T16:10:06.589Z
Learning: Applies to src/praisonai-agents/praisonaiagents/mcp/**/*.py : Use MCP (Model Context Protocol) server with Server-Sent Events (SSE) support for distributed tool execution and real-time communication
Applied to files:
src/praisonai-agents/praisonaiagents/mcp/mcp_sse.pysrc/praisonai-agents/praisonaiagents/mcp/mcp_http_stream.pysrc/praisonai-agents/praisonaiagents/mcp/mcp.py
πͺ Ruff (0.14.10)
src/praisonai-agents/praisonaiagents/mcp/mcp_http_stream.py
23-23: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
23-23: Avoid specifying long messages outside the exception class
(TRY003)
β° Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Cursor Bugbot
- GitHub Check: test-core (3.11)
- GitHub Check: Run tests and collect coverage
- GitHub Check: quick-test
- GitHub Check: quick-test
π Additional comments (2)
src/praisonai-agents/praisonaiagents/mcp/mcp_sse.py (1)
14-15: LGTM - Consistent with the revert.These unconditional imports align with the architectural change making MCP a required dependency across all transport implementations.
src/praisonai-agents/praisonaiagents/mcp/mcp.py (1)
14-15: The mcp submodule requires the mcp package to be installed, despite it being an optional dependency.Lines 14-15 have unconditional imports from the mcp package. Since
mcp/__init__.pyalso unconditionally imports frommcp.py(line 13), any attempt to use the mcp submodule will fail with ImportError if the mcp package is not installed, even though mcp is defined as an optional dependency in pyproject.toml.This is a breaking change: users must install the
[mcp]extra to use any part of the mcp submodule. Without a try/except wrapper around lines 14-15 or lazy loading at the submodule level, the failure happens at import time rather than at usage time.Consider either:
- Wrapping the mcp imports with try/except and deferring initialization, or
- Ensuring documentation clearly states that mcp submodule requires
pip install praisonaiagents[mcp]
User description
Reverts #1096
PR Type
Bug fix
Description
Removes optional MCP import handling to require MCP package
Eliminates MCP_AVAILABLE flag checks from initialization
Converts aiohttp import error to immediate failure in HTTP Stream
Deletes test suite for optional MCP import functionality
Diagram Walkthrough
File Walkthrough
mcp.py
Remove optional MCP import handlingΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Βsrc/praisonai-agents/praisonaiagents/mcp/mcp.py
mcp_http_stream.py
Require MCP and aiohttp imports directlyΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Βsrc/praisonai-agents/praisonaiagents/mcp/mcp_http_stream.py
mcp_sse.py
Remove optional MCP import handlingΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Βsrc/praisonai-agents/praisonaiagents/mcp/mcp_sse.py
test_mcp_optional_import.py
Delete optional MCP import test suiteΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Βsrc/praisonai-agents/tests/test_mcp_optional_import.py
Note
Reverts optional-import behavior for MCP modules and makes MCP dependencies mandatory.
mcp.py,mcp_sse.py, andmcp_http_stream.py; removeMCP_AVAILABLEchecksmcp_http_stream.py, raise explicitImportErrorifaiohttpis missing and default endpoint handling for/mcptests/test_mcp_optional_import.pythat validated optional MCP importsImpact: importing MCP modules now requires
mcp(andaiohttpfor HTTP stream); apps without these deps will error on import.Written by Cursor Bugbot for commit 6505f6a. This will update automatically on new commits. Configure here.
Summary by CodeRabbit
Refactor
Tests
βοΈ Tip: You can customize this high-level summary in your review settings.