|
14 | 14 |
|
15 | 15 | from io import StringIO |
16 | 16 | import sys |
| 17 | +import unittest |
17 | 18 | from unittest.mock import AsyncMock |
18 | 19 | from unittest.mock import Mock |
19 | 20 | from unittest.mock import patch |
20 | 21 |
|
21 | | -from google.adk.agents.readonly_context import ReadonlyContext |
22 | 22 | from google.adk.auth.auth_credential import AuthCredential |
23 | | -from google.adk.auth.auth_schemes import AuthScheme |
24 | | -from google.adk.auth.auth_schemes import AuthSchemeType |
25 | | -from google.adk.tools.mcp_tool.mcp_session_manager import MCPSessionManager |
26 | | -from google.adk.tools.mcp_tool.mcp_session_manager import SseConnectionParams |
27 | | -from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams |
28 | | -from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPConnectionParams |
29 | | -from google.adk.tools.mcp_tool.mcp_tool import MCPTool |
30 | | -from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset |
31 | 23 | import pytest |
32 | 24 |
|
33 | | -# Import the real MCP classes for proper instantiation |
| 25 | +# Skip all tests in this module if Python version is less than 3.10 |
| 26 | +pytestmark = pytest.mark.skipif( |
| 27 | + sys.version_info < (3, 10), reason="MCP tool requires Python 3.10+" |
| 28 | +) |
| 29 | + |
| 30 | +# Import dependencies with version checking |
34 | 31 | try: |
| 32 | + from google.adk.tools.mcp_tool.mcp_session_manager import MCPSessionManager |
| 33 | + from google.adk.tools.mcp_tool.mcp_session_manager import SseConnectionParams |
| 34 | + from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams |
| 35 | + from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPConnectionParams |
| 36 | + from google.adk.tools.mcp_tool.mcp_tool import MCPTool |
| 37 | + from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset |
35 | 38 | from mcp import StdioServerParameters |
36 | | -except ImportError: |
37 | | - # Create a mock if MCP is not available |
38 | | - class StdioServerParameters: |
39 | | - |
40 | | - def __init__(self, command="test_command", args=None): |
41 | | - self.command = command |
42 | | - self.args = args or [] |
| 39 | +except ImportError as e: |
| 40 | + if sys.version_info < (3, 10): |
| 41 | + # Create dummy classes to prevent NameError during test collection |
| 42 | + # Tests will be skipped anyway due to pytestmark |
| 43 | + class DummyClass: |
| 44 | + pass |
| 45 | + |
| 46 | + class StdioServerParameters: |
| 47 | + |
| 48 | + def __init__(self, command="test_command", args=None): |
| 49 | + self.command = command |
| 50 | + self.args = args or [] |
| 51 | + |
| 52 | + MCPSessionManager = DummyClass |
| 53 | + SseConnectionParams = DummyClass |
| 54 | + StdioConnectionParams = DummyClass |
| 55 | + StreamableHTTPConnectionParams = DummyClass |
| 56 | + MCPTool = DummyClass |
| 57 | + MCPToolset = DummyClass |
| 58 | + else: |
| 59 | + raise e |
43 | 60 |
|
44 | 61 |
|
45 | 62 | class MockMCPTool: |
|
0 commit comments