Skip to content

Commit 5d2a4dc

Browse files
Refactor associated_tools structure to include name and displayName attributes
Signed-off-by: Arjav <[email protected]>
1 parent 5255409 commit 5d2a4dc

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

tests/integration/test_integration.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def auth_headers() -> dict[str, str]:
108108
id="tool-1",
109109
name="test_tool",
110110
original_name="test_tool",
111+
displayName="Test Tool",
111112
url="http://example.com/tools/test",
112113
description="demo",
113114
request_type="POST",
@@ -138,7 +139,13 @@ def auth_headers() -> dict[str, str]:
138139
created_at=datetime(2025, 1, 1),
139140
updated_at=datetime(2025, 1, 1),
140141
is_active=True,
141-
associated_tools=[MOCK_TOOL.id],
142+
associated_tools=[
143+
{
144+
"id": MOCK_TOOL.id,
145+
"name": MOCK_TOOL.name,
146+
"displayName": MOCK_TOOL.displayName,
147+
}
148+
],
142149
associated_resources=[],
143150
associated_prompts=[],
144151
metrics=MOCK_METRICS,
@@ -194,7 +201,7 @@ def test_server_with_tools_workflow(
194201
srv_req = {
195202
"name": "test_server",
196203
"description": "integration server",
197-
"associated_tools": [MOCK_TOOL.id],
204+
"associated_tools": [{"id": MOCK_TOOL.id, "name": MOCK_TOOL.name, "displayName": MOCK_TOOL.displayName}],
198205
}
199206
resp_srv = test_client.post("/servers/", json=srv_req, headers=auth_headers)
200207
assert resp_srv.status_code == 201

tests/unit/mcpgateway/services/test_server_service.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def capture_add(server):
173173
created_at="2023-01-01T00:00:00",
174174
updated_at="2023-01-01T00:00:00",
175175
is_active=True,
176-
associated_tools=["101"],
176+
associated_tools=[{"id": "101", "name": "test_tool", "displayName": "Test Tool"}],
177177
associated_resources=[201],
178178
associated_prompts=[301],
179179
metrics={
@@ -208,7 +208,7 @@ def capture_add(server):
208208
server_service._notify_server_added.assert_called_once()
209209

210210
assert result.name == "test_server"
211-
assert "101" in result.associated_tools
211+
assert [{'displayName': 'Test Tool', 'id': '101', 'name': 'test_tool'}] == result.associated_tools
212212
assert 201 in result.associated_resources
213213
assert 301 in result.associated_prompts
214214

@@ -278,7 +278,7 @@ async def test_list_servers(self, server_service, mock_server, test_db):
278278
created_at="2023-01-01T00:00:00",
279279
updated_at="2023-01-01T00:00:00",
280280
is_active=True,
281-
associated_tools=["101"],
281+
associated_tools=[{"id": "101", "name": "test_tool", "displayName": "Test Tool"}],
282282
associated_resources=[201],
283283
associated_prompts=[301],
284284
metrics={
@@ -312,7 +312,7 @@ async def test_get_server(self, server_service, mock_server, test_db):
312312
created_at="2023-01-01T00:00:00",
313313
updated_at="2023-01-01T00:00:00",
314314
is_active=True,
315-
associated_tools=["101"],
315+
associated_tools=[{"id": "101", "name": "test_tool", "displayName": "Test Tool"}],
316316
associated_resources=[201],
317317
associated_prompts=[301],
318318
metrics={
@@ -409,7 +409,7 @@ async def test_update_server(self, server_service, mock_server, test_db, mock_to
409409
created_at="2023-01-01T00:00:00",
410410
updated_at="2023-01-01T00:00:00",
411411
is_active=True,
412-
associated_tools=["102"],
412+
associated_tools=[{"id": "102", "name": "new_tool", "displayName": "New Tool"}],
413413
associated_resources=[202],
414414
associated_prompts=[302],
415415
metrics={
@@ -489,7 +489,7 @@ async def test_toggle_server_status(self, server_service, mock_server, test_db):
489489
created_at="2023-01-01T00:00:00",
490490
updated_at="2023-01-01T00:00:00",
491491
is_active=False,
492-
associated_tools=["101"],
492+
associated_tools=[{"id": "101", "name": "test_tool", "displayName": "Test Tool"}],
493493
associated_resources=[201],
494494
associated_prompts=[301],
495495
metrics={

tests/unit/mcpgateway/test_main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"created_at": "2023-01-01T00:00:00+00:00",
5656
"updated_at": "2023-01-01T00:00:00+00:00",
5757
"is_active": True,
58-
"associated_tools": ["101"],
58+
"associated_tools": [{"id": "101", "name": "test_tool", "displayName": "Test Tool"}],
5959
"associated_resources": [201],
6060
"associated_prompts": [301],
6161
"metrics": MOCK_METRICS,

tests/unit/mcpgateway/test_schemas.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,9 @@ def test_server_read(self):
756756
created_at=one_hour_ago,
757757
updated_at=now,
758758
is_active=True,
759-
associated_tools=["1", "2", "3"],
759+
associated_tools=[{"id": "1", "name": "tool_1", "displayName": "Tool 1"},
760+
{"id": "2", "name": "tool_2", "displayName": "Tool 2"},
761+
{"id": "3", "name": "tool_3", "displayName": "Tool 3"}],
760762
associated_resources=[4, 5],
761763
associated_prompts=[6],
762764
metrics=ServerMetrics(
@@ -778,7 +780,9 @@ def test_server_read(self):
778780
assert server.created_at == one_hour_ago
779781
assert server.updated_at == now
780782
assert server.is_active is True
781-
assert server.associated_tools == ["1", "2", "3"]
783+
assert server.associated_tools == [{"id": "1", "name": "tool_1", "displayName": "Tool 1"},
784+
{"id": "2", "name": "tool_2", "displayName": "Tool 2"},
785+
{"id": "3", "name": "tool_3", "displayName": "Tool 3"}]
782786
assert server.associated_resources == [4, 5]
783787
assert server.associated_prompts == [6]
784788
assert server.metrics.total_executions == 100
@@ -793,7 +797,10 @@ def test_server_read(self):
793797
created_at=one_hour_ago,
794798
updated_at=now,
795799
is_active=True,
796-
associated_tools=[Mock(id="10"), Mock(id="11")],
800+
associated_tools=[
801+
{"id": "10", "name": "test_tool", "displayName": "Test Tool"},
802+
{"id": "11", "name": "test_tool_1", "displayName": "Test Tool 1"},
803+
],
797804
associated_resources=[Mock(id=12)],
798805
associated_prompts=[Mock(id=13)],
799806
metrics=ServerMetrics(
@@ -804,7 +811,10 @@ def test_server_read(self):
804811
),
805812
)
806813

807-
assert server_with_objects.associated_tools == ["10", "11"]
814+
assert server_with_objects.associated_tools == [
815+
{"id": "10", "name": "test_tool", "displayName": "Test Tool"},
816+
{"id": "11", "name": "test_tool_1", "displayName": "Test Tool 1"},
817+
]
808818
assert server_with_objects.associated_resources == [12]
809819
assert server_with_objects.associated_prompts == [13]
810820

0 commit comments

Comments
 (0)