@@ -502,3 +502,65 @@ def add(a: int, b: int) -> int:
502502 # Disable an already disabled tool (should not change state)
503503 await tool .disable ()
504504 assert tool .enabled is False
505+
506+ @pytest .mark .anyio
507+ async def test_list_tools_filters_disabled (self ):
508+ """Test that list_tools only returns enabled tools."""
509+
510+ def add (a : int , b : int ) -> int :
511+ """Add two numbers."""
512+ return a + b
513+
514+ def subtract (a : int , b : int ) -> int :
515+ """Subtract two numbers."""
516+ return a - b
517+
518+ manager = ToolManager ()
519+ tool1 = manager .add_tool (add )
520+ tool2 = manager .add_tool (subtract )
521+
522+ # Both tools should be listed initially
523+ tools = manager .list_tools ()
524+ assert len (tools ) == 2
525+ assert tool1 in tools
526+ assert tool2 in tools
527+
528+ # Disable one tool
529+ await tool1 .disable ()
530+
531+ # Only enabled tool should be listed
532+ tools = manager .list_tools ()
533+ assert len (tools ) == 1
534+ assert tool1 not in tools
535+ assert tool2 in tools
536+
537+ # Re-enable the tool
538+ await tool1 .enable ()
539+
540+ # Both tools should be listed again
541+ tools = manager .list_tools ()
542+ assert len (tools ) == 2
543+ assert tool1 in tools
544+ assert tool2 in tools
545+
546+ @pytest .mark .anyio
547+ async def test_call_disabled_tool_raises_error (self ):
548+ """Test that calling a disabled tool raises an error."""
549+
550+ def add (a : int , b : int ) -> int :
551+ """Add two numbers."""
552+ return a + b
553+
554+ manager = ToolManager ()
555+ tool = manager .add_tool (add )
556+
557+ # Tool should work normally when enabled
558+ result = await manager .call_tool ("add" , {"a" : 1 , "b" : 2 })
559+ assert result == 3
560+
561+ # Disable the tool
562+ await tool .disable ()
563+
564+ # Calling disabled tool should raise error
565+ with pytest .raises (ToolError , match = "Tool is disabled: add" ):
566+ await manager .call_tool ("add" , {"a" : 1 , "b" : 2 })
0 commit comments