@@ -63,66 +63,24 @@ def __init__(
6363 self .outputSchema = outputSchema
6464
6565
66- class TestMCPTool :
67- """Test suite for MCPTool class."""
66+ class TestMCPToolLegacy :
67+ """Legacy tests for MCPTool."""
68+
69+ @pytest .fixture (autouse = True )
70+ def disable_feature_flag (self ):
71+ with temporary_feature_override (
72+ FeatureName .JSON_SCHEMA_FOR_FUNC_DECL , False
73+ ):
74+ yield
6875
6976 def setup_method (self ):
70- """Set up test fixtures."""
7177 self .mock_mcp_tool = MockMCPTool ()
7278 self .mock_session_manager = Mock (spec = MCPSessionManager )
7379 self .mock_session = AsyncMock ()
7480 self .mock_session_manager .create_session = AsyncMock (
7581 return_value = self .mock_session
7682 )
7783
78- def test_init_basic (self ):
79- """Test basic initialization without auth."""
80- tool = MCPTool (
81- mcp_tool = self .mock_mcp_tool ,
82- mcp_session_manager = self .mock_session_manager ,
83- )
84-
85- assert tool .name == "test_tool"
86- assert tool .description == "Test tool description"
87- assert tool ._mcp_tool == self .mock_mcp_tool
88- assert tool ._mcp_session_manager == self .mock_session_manager
89-
90- def test_init_with_auth (self ):
91- """Test initialization with authentication."""
92- # Create real auth scheme instances instead of mocks
93- from fastapi .openapi .models import OAuth2
94-
95- auth_scheme = OAuth2 (flows = {})
96- auth_credential = AuthCredential (
97- auth_type = AuthCredentialTypes .OAUTH2 ,
98- oauth2 = OAuth2Auth (client_id = "test_id" , client_secret = "test_secret" ),
99- )
100-
101- tool = MCPTool (
102- mcp_tool = self .mock_mcp_tool ,
103- mcp_session_manager = self .mock_session_manager ,
104- auth_scheme = auth_scheme ,
105- auth_credential = auth_credential ,
106- )
107-
108- # The auth config is stored in the parent class _credentials_manager
109- assert tool ._credentials_manager is not None
110- assert tool ._credentials_manager ._auth_config .auth_scheme == auth_scheme
111- assert (
112- tool ._credentials_manager ._auth_config .raw_auth_credential
113- == auth_credential
114- )
115-
116- def test_init_with_empty_description (self ):
117- """Test initialization with empty description."""
118- mock_tool = MockMCPTool (description = None )
119- tool = MCPTool (
120- mcp_tool = mock_tool ,
121- mcp_session_manager = self .mock_session_manager ,
122- )
123-
124- assert tool .description == ""
125-
12684 def test_get_declaration (self ):
12785 """Test function declaration generation."""
12886 tool = MCPTool (
@@ -137,6 +95,25 @@ def test_get_declaration(self):
13795 assert declaration .description == "Test tool description"
13896 assert declaration .parameters is not None
13997
98+
99+ class TestMCPToolWithJsonSchema :
100+ """Tests for MCPTool with JSON_SCHEMA_FOR_FUNC_DECL enabled."""
101+
102+ @pytest .fixture (autouse = True )
103+ def enable_feature_flag (self ):
104+ with temporary_feature_override (
105+ FeatureName .JSON_SCHEMA_FOR_FUNC_DECL , True
106+ ):
107+ yield
108+
109+ def setup_method (self ):
110+ self .mock_mcp_tool = MockMCPTool ()
111+ self .mock_session_manager = Mock (spec = MCPSessionManager )
112+ self .mock_session = AsyncMock ()
113+ self .mock_session_manager .create_session = AsyncMock (
114+ return_value = self .mock_session
115+ )
116+
140117 def test_get_declaration_with_json_schema_for_func_decl_enabled (self ):
141118 """Test function declaration generation with json schema for func decl enabled."""
142119 tool = MCPTool (
@@ -202,6 +179,67 @@ def test_get_declaration_with_empty_output_schema_and_json_schema_for_func_decl_
202179 assert declaration .response is None
203180 assert not declaration .response_json_schema
204181
182+
183+ class TestMCPTool :
184+ """Test suite for MCPTool class."""
185+
186+ def setup_method (self ):
187+ """Set up test fixtures."""
188+ self .mock_mcp_tool = MockMCPTool ()
189+ self .mock_session_manager = Mock (spec = MCPSessionManager )
190+ self .mock_session = AsyncMock ()
191+ self .mock_session_manager .create_session = AsyncMock (
192+ return_value = self .mock_session
193+ )
194+
195+ def test_init_basic (self ):
196+ """Test basic initialization without auth."""
197+ tool = MCPTool (
198+ mcp_tool = self .mock_mcp_tool ,
199+ mcp_session_manager = self .mock_session_manager ,
200+ )
201+
202+ assert tool .name == "test_tool"
203+ assert tool .description == "Test tool description"
204+ assert tool ._mcp_tool == self .mock_mcp_tool
205+ assert tool ._mcp_session_manager == self .mock_session_manager
206+
207+ def test_init_with_auth (self ):
208+ """Test initialization with authentication."""
209+ # Create real auth scheme instances instead of mocks
210+ from fastapi .openapi .models import OAuth2
211+
212+ auth_scheme = OAuth2 (flows = {})
213+ auth_credential = AuthCredential (
214+ auth_type = AuthCredentialTypes .OAUTH2 ,
215+ oauth2 = OAuth2Auth (client_id = "test_id" , client_secret = "test_secret" ),
216+ )
217+
218+ tool = MCPTool (
219+ mcp_tool = self .mock_mcp_tool ,
220+ mcp_session_manager = self .mock_session_manager ,
221+ auth_scheme = auth_scheme ,
222+ auth_credential = auth_credential ,
223+ )
224+
225+ # The auth config is stored in the parent class _credentials_manager
226+ assert tool ._credentials_manager is not None
227+ assert tool ._credentials_manager ._auth_config .auth_scheme == auth_scheme
228+ assert (
229+ tool ._credentials_manager ._auth_config .raw_auth_credential
230+ == auth_credential
231+ )
232+
233+ def test_init_with_empty_description (self ):
234+ """Test initialization with empty description."""
235+ mock_tool = MockMCPTool (description = None )
236+ tool = MCPTool (
237+ mcp_tool = mock_tool ,
238+ mcp_session_manager = self .mock_session_manager ,
239+ )
240+
241+ assert tool .description == ""
242+
205243 @pytest .mark .asyncio
206244 async def test_run_async_impl_no_auth (self ):
207245 """Test running tool without authentication."""
0 commit comments