|
6 | 6 | class TestMCPTool: |
7 | 7 | """Tests for MCPTool dataclass.""" |
8 | 8 |
|
9 | | - def test_namespaced_name(self): |
10 | | - """Test namespaced_name property.""" |
11 | | - tool = MCPTool( |
12 | | - name="create_order", |
13 | | - server_name="s4hana_procurement", |
14 | | - description="Create purchase order", |
15 | | - input_schema={"type": "object"}, |
16 | | - url="https://example.com/mcp", |
17 | | - ) |
18 | | - |
19 | | - assert tool.namespaced_name == "s4hana_procurement__create_order" |
20 | | - |
21 | | - def test_namespaced_name_with_special_chars(self): |
22 | | - """Test namespaced_name sanitizes invalid characters to underscores.""" |
23 | | - tool = MCPTool( |
24 | | - name="get-item", |
25 | | - server_name="my-server", |
26 | | - description="Get item", |
27 | | - input_schema={}, |
28 | | - url="https://example.com/mcp", |
29 | | - ) |
30 | | - |
31 | | - assert tool.namespaced_name == "my-server__get-item" |
32 | | - |
33 | | - def test_namespaced_name_sanitizes_dots_and_colons(self): |
34 | | - """Test that dots, colons, slashes are replaced with underscores.""" |
35 | | - tool = MCPTool( |
36 | | - name="get/data", |
37 | | - server_name="my.server:v1", |
38 | | - description="Get data", |
39 | | - input_schema={}, |
40 | | - url="https://example.com/mcp", |
41 | | - ) |
42 | | - |
43 | | - assert tool.namespaced_name == "my_server_v1__get_data" |
44 | | - |
45 | | - def test_namespaced_name_truncates_long_names(self): |
46 | | - """Test that names over 64 chars are truncated to 55 + hash suffix.""" |
47 | | - tool = MCPTool( |
48 | | - name="get_supplier_operational_eval_scores_by_region", |
49 | | - server_name="sales_order_mcp_demo", |
50 | | - description="Long name tool", |
51 | | - input_schema={}, |
52 | | - url="https://example.com/mcp", |
53 | | - ) |
54 | | - |
55 | | - result = tool.namespaced_name |
56 | | - assert len(result) == 64 |
57 | | - # First 55 chars are preserved from the sanitized name |
58 | | - assert result[:55] == "sales_order_mcp_demo__get_supplier_operational_eval_sco" |
59 | | - # Followed by underscore and 8-char hash |
60 | | - assert result[55] == "_" |
61 | | - assert len(result[56:]) == 8 |
62 | | - |
63 | | - def test_namespaced_name_short_names_unchanged(self): |
64 | | - """Test that short valid names pass through without modification.""" |
65 | | - tool = MCPTool( |
66 | | - name="list_orders", |
67 | | - server_name="myserver", |
68 | | - description="List orders", |
69 | | - input_schema={}, |
70 | | - url="https://example.com/mcp", |
71 | | - ) |
72 | | - |
73 | | - assert tool.namespaced_name == "myserver__list_orders" |
74 | | - |
75 | | - def test_namespaced_name_uniqueness_on_truncation(self): |
76 | | - """Test that two different long names produce different truncated results.""" |
77 | | - tool_a = MCPTool( |
78 | | - name="get_supplier_operational_eval_scores_by_region_east", |
79 | | - server_name="sales_order_mcp_demo", |
80 | | - description="Tool A", |
81 | | - input_schema={}, |
82 | | - url="https://example.com/mcp", |
83 | | - ) |
84 | | - tool_b = MCPTool( |
85 | | - name="get_supplier_operational_eval_scores_by_region_west", |
86 | | - server_name="sales_order_mcp_demo", |
87 | | - description="Tool B", |
88 | | - input_schema={}, |
89 | | - url="https://example.com/mcp", |
90 | | - ) |
91 | | - |
92 | | - assert tool_a.namespaced_name != tool_b.namespaced_name |
93 | | - assert len(tool_a.namespaced_name) == 64 |
94 | | - assert len(tool_b.namespaced_name) == 64 |
95 | | - |
96 | 9 | def test_create_tool_with_all_fields(self): |
97 | 10 | """Test MCPTool creation with all fields.""" |
98 | 11 | tool = MCPTool( |
|
0 commit comments