Commit Graph

5 Commits

Author SHA1 Message Date
Devin AI
88c0950a6f fix: Fix async context manager in MCP test stubs
- Change fake_streamablehttp_client from async def to regular def
- async with expects an object with __aenter__/__aexit__, not a coroutine
- Add __path__ to make mcp modules look like packages
- Add last_kwargs tracking for header assertions
- Add proper assertions to verify headers are passed/not passed
- This fixes TypeError: 'coroutine' object does not support async context manager protocol

Co-Authored-By: João <joao@crewai.com>
2025-10-26 10:11:39 +00:00
Devin AI
9dfad32efe fix: Remove problematic patch() calls from MCP tests
- Remove all patch() calls for module-local names (streamablehttp_client, ClientSession)
- Rely solely on sys.modules stub fixture for mcp module imports
- Patch ClientSession.__init__ directly to configure mock behavior
- This fixes AttributeError issues where patch() tried to access non-existent module attributes

Co-Authored-By: João <joao@crewai.com>
2025-10-26 10:06:07 +00:00
Devin AI
3b77dd57d8 fix: Add sys.modules stub fixture for mcp modules in tests
- Add autouse fixture to stub mcp, mcp.client, and mcp.client.streamable_http modules
- Revert patch targets to module-local names (crewai.tools.mcp_tool_wrapper.*)
- This fixes ModuleNotFoundError in CI where mcp package is not installed
- The stub fixture ensures tests can run without requiring the actual mcp package

Co-Authored-By: João <joao@crewai.com>
2025-10-26 09:58:46 +00:00
Devin AI
99418b1160 fix: Correct test mocks for MCP progress and headers tests
- Fix event bus API: use register_handler instead of register
- Fix mock import paths: patch mcp.client.streamable_http.streamablehttp_client and mcp.ClientSession at their actual import locations

Co-Authored-By: João <joao@crewai.com>
2025-10-26 09:52:58 +00:00
Devin AI
873d501401 feat: Add MCP progress notifications and middleware headers support
Implements progress reporting and HTTP headers support for MCP tool integration
to address issue #3797.

Changes:
- Add MCPToolProgressEvent to event system for real-time progress tracking
- Extend MCPToolWrapper to support progress callbacks and event emission
- Add mcp_progress_enabled flag to Agent for opt-in progress notifications
- Add mcp_server_headers to Agent for middleware authentication/tracking
- Thread progress and headers configuration through Agent._get_external_mcp_tools
- Add comprehensive test coverage for progress and headers features
- Update MCP DSL documentation with progress and headers examples

Features:
- Progress notifications emitted as MCPToolProgressEvent via event bus
- Optional progress callback for custom progress handling
- HTTP headers passthrough for authentication and middleware integration
- Agent and task context included in progress events
- Opt-in design ensures backward compatibility

Tests:
- Unit tests for MCPToolWrapper progress and headers functionality
- Integration tests for Agent MCP configuration
- Mock-based tests to avoid network dependencies

Documentation:
- Added Progress Notifications section with examples
- Added Middleware Support with Headers section
- Included complete examples for common use cases

Fixes #3797

Co-Authored-By: João <joao@crewai.com>
2025-10-26 09:45:50 +00:00