Jeremiah Lowin commited on
Commit
0c82b38
·
1 Parent(s): dce143d

Update test_tool_manager.py

Browse files
Files changed (1) hide show
  1. tests/tools/test_tool_manager.py +24 -9
tests/tools/test_tool_manager.py CHANGED
@@ -575,8 +575,8 @@ class TestCustomToolNames:
575
  # The tool should not be accessible via its original function name
576
  assert manager.get_tool("original_fn") is None
577
 
578
- def test_add_tool_object_with_custom_storage_name(self):
579
- """Test adding a Tool object with a custom storage name using add_tool()."""
580
 
581
  def fn(x: int) -> int:
582
  return x + 1
@@ -586,7 +586,7 @@ class TestCustomToolNames:
586
  manager = ToolManager()
587
  # Store it under a different name
588
  manager.add_tool(tool, key="proxy_tool")
589
- # The tool is accessible under the storage name
590
  stored = manager.get_tool("proxy_tool")
591
  assert stored is not None
592
  # But the tool's .name is unchanged
@@ -612,20 +612,35 @@ class TestCustomToolNames:
612
  with pytest.raises(ToolError):
613
  await manager.call_tool("multiply", {"a": 5, "b": 3})
614
 
615
- def test_tool_to_mcp_tool_with_custom_name(self):
616
- """Test that to_mcp_tool uses the storage name, not the internal name."""
617
 
618
  def some_function(x: int) -> int:
619
  return x
620
 
621
  manager = ToolManager()
622
- manager.add_tool_from_fn(some_function, name="api_function")
 
623
 
624
- # When listing tools for MCP, the custom name should be used
625
  mcp_tools = manager.list_mcp_tools()
626
  assert len(mcp_tools) == 1
627
  assert mcp_tools[0].name == "api_function"
628
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
629
  def test_import_tools_with_custom_names(self):
630
  """Test importing tools with custom names."""
631
 
@@ -675,7 +690,7 @@ class TestCustomToolNames:
675
  assert stored_tool.fn.__name__ == "replacement_fn"
676
 
677
  def test_mcp_tool_name_for_add_tool(self):
678
- """Test MCPTool name for add_tool (storage name != tool.name)."""
679
 
680
  def fn(x: int) -> int:
681
  return x + 1
@@ -688,7 +703,7 @@ class TestCustomToolNames:
688
  assert mcp_tools[0].name == "proxy_tool"
689
 
690
  def test_mcp_tool_name_for_add_tool_from_fn(self):
691
- """Test MCPTool name for add_tool_from_fn (storage name == tool.name)."""
692
 
693
  def fn(x: int) -> int:
694
  return x + 1
 
575
  # The tool should not be accessible via its original function name
576
  assert manager.get_tool("original_fn") is None
577
 
578
+ def test_add_tool_object_with_custom_key(self):
579
+ """Test adding a Tool object with a custom key using add_tool()."""
580
 
581
  def fn(x: int) -> int:
582
  return x + 1
 
586
  manager = ToolManager()
587
  # Store it under a different name
588
  manager.add_tool(tool, key="proxy_tool")
589
+ # The tool is accessible under the key
590
  stored = manager.get_tool("proxy_tool")
591
  assert stored is not None
592
  # But the tool's .name is unchanged
 
612
  with pytest.raises(ToolError):
613
  await manager.call_tool("multiply", {"a": 5, "b": 3})
614
 
615
+ def test_tool_to_mcp_tool(self):
616
+ """Test that to_mcp_tool uses the key, not the internal name."""
617
 
618
  def some_function(x: int) -> int:
619
  return x
620
 
621
  manager = ToolManager()
622
+ tool = Tool.from_function(some_function, name="api_function")
623
+ manager.add_tool(tool)
624
 
 
625
  mcp_tools = manager.list_mcp_tools()
626
  assert len(mcp_tools) == 1
627
  assert mcp_tools[0].name == "api_function"
628
 
629
+ def test_tool_to_mcp_tool_with_custom_key(self):
630
+ """Test that to_mcp_tool uses the key, not the internal name."""
631
+
632
+ def some_function(x: int) -> int:
633
+ return x
634
+
635
+ manager = ToolManager()
636
+ tool = Tool.from_function(some_function, name="api_function")
637
+ manager.add_tool(tool, key="custom-key")
638
+
639
+ # When listing tools for MCP, the key should be used
640
+ mcp_tools = manager.list_mcp_tools()
641
+ assert len(mcp_tools) == 1
642
+ assert mcp_tools[0].name == "custom-key"
643
+
644
  def test_import_tools_with_custom_names(self):
645
  """Test importing tools with custom names."""
646
 
 
690
  assert stored_tool.fn.__name__ == "replacement_fn"
691
 
692
  def test_mcp_tool_name_for_add_tool(self):
693
+ """Test MCPTool name for add_tool (key != tool.name)."""
694
 
695
  def fn(x: int) -> int:
696
  return x + 1
 
703
  assert mcp_tools[0].name == "proxy_tool"
704
 
705
  def test_mcp_tool_name_for_add_tool_from_fn(self):
706
+ """Test MCPTool name for add_tool_from_fn (key == tool.name)."""
707
 
708
  def fn(x: int) -> int:
709
  return x + 1