@@ -313,6 +313,48 @@ async def test_stdio_server_connection(self, arithmetic_stdio_server):
313
313
await client .cleanup ()
314
314
print ("stdio server connection test completed" )
315
315
316
+ @pytest .mark .asyncio
317
+ async def test_initialize_with_invalid_config_type (self ):
318
+ """Test initializing MCP client with an invalid config type"""
319
+ try :
320
+ # Try to initialize with an invalid config type (integer)
321
+ await initialize_mcp_client (123 , "claude-3-7-sonnet-20250219" )
322
+ pytest .fail ("Should have raised ValueError for invalid config type" )
323
+ except ValueError as e :
324
+ # Ensure the error message mentions the invalid type
325
+ assert "must be a string path or dictionary" in str (e )
326
+ print (f"Correctly raised ValueError: { str (e )} " )
327
+
328
+ @pytest .mark .asyncio
329
+ async def test_initialize_with_invalid_config_dict (self ):
330
+ """Test initializing MCP client with an invalid config dictionary (missing mcpServers)"""
331
+ try :
332
+ # Create a dictionary without the mcpServers key
333
+ invalid_config = {"someOtherKey" : "value" }
334
+
335
+ # Try to initialize with an invalid config dictionary
336
+ await initialize_mcp_client (invalid_config , "claude-3-7-sonnet-20250219" )
337
+ pytest .fail ("Should have raised ValueError for missing mcpServers key" )
338
+ except ValueError as e :
339
+ # Ensure the error message mentions the missing key
340
+ assert "missing required 'mcpServers' key" in str (e )
341
+ print (f"Correctly raised ValueError: { str (e )} " )
342
+
343
+ @pytest .mark .asyncio
344
+ async def test_initialize_with_empty_mcpservers (self ):
345
+ """Test initializing MCP client with empty mcpServers dictionary"""
346
+ try :
347
+ # Create a dictionary with empty mcpServers
348
+ invalid_config = {"mcpServers" : {}}
349
+
350
+ # Try to initialize with empty mcpServers
351
+ await initialize_mcp_client (invalid_config , "claude-3-7-sonnet-20250219" )
352
+ pytest .fail ("Should have raised ValueError for empty mcpServers" )
353
+ except ValueError as e :
354
+ # Ensure the error message mentions empty mcpServers
355
+ assert "No MCP servers defined in config" in str (e )
356
+ print (f"Correctly raised ValueError: { str (e )} " )
357
+
316
358
@pytest .mark .asyncio
317
359
@pytest .mark .skipif (
318
360
not os .environ .get ("ANTHROPIC_API_KEY" ),
0 commit comments