mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-23 07:08:14 +00:00
Fix #2698: Implement MCP SSE server connection for tools
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
41
tests/integration/test_mcp_tools_integration.py
Normal file
41
tests/integration/test_mcp_tools_integration.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import os
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from crewai.tools import BaseTool, MCPToolConnector, Tool
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
class TestMCPToolsIntegration(unittest.TestCase):
|
||||
@pytest.mark.skipif(
|
||||
not os.environ.get("CREWAI_INTEGRATION_TEST"),
|
||||
reason="Integration test requires CREWAI_INTEGRATION_TEST=true"
|
||||
)
|
||||
@patch("crewai.tools.mcp_connector.SSEClient")
|
||||
def test_mcp_tool_connector_integration(self, mock_sse_client):
|
||||
def add(a: int, b: int) -> int:
|
||||
"""Add two numbers."""
|
||||
return a + b
|
||||
|
||||
calculator_tool = Tool(
|
||||
name="calculator_add",
|
||||
description="Add two numbers",
|
||||
func=add
|
||||
)
|
||||
|
||||
connector = MCPToolConnector(tools=[calculator_tool])
|
||||
|
||||
mock_sse = MagicMock()
|
||||
mock_sse_client.return_value = mock_sse
|
||||
|
||||
connector.connect()
|
||||
|
||||
tool_request_data = {
|
||||
"tool_name": "calculator_add",
|
||||
"arguments": {"a": 5, "b": 7},
|
||||
"request_id": "test-request-1"
|
||||
}
|
||||
|
||||
connector._handle_tool_request(tool_request_data)
|
||||
Reference in New Issue
Block a user