Skip to content

Commit 24d4f58

Browse files
authored
test: add coverage for mcp tools (#1314)
--------- Signed-off-by: fege <fmosca@redhat.com>
1 parent 2f23786 commit 24d4f58

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

tests/model_registry/mcp_servers/test_data_integrity.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import pytest
44
import structlog
5+
from kubernetes.dynamic.exceptions import ResourceNotFoundError
56

67
from tests.model_registry.mcp_servers.constants import (
78
EXPECTED_MCP_SERVER_NAMES,
89
EXPECTED_MCP_SERVER_TIMESTAMPS,
10+
EXPECTED_MCP_SERVER_TOOL_COUNTS,
911
EXPECTED_MCP_SERVER_TOOLS,
1012
)
1113
from tests.model_registry.utils import execute_get_command
@@ -21,13 +23,50 @@ def test_mcp_servers_loaded(
2123
self: Self,
2224
mcp_servers_response: dict[str, Any],
2325
):
24-
"""Verify that all MCP servers are loaded from YAML with correct timestamps."""
26+
"""Verify MCP servers loaded with correct timestamps and tools excluded by default (TC-LOAD-001, TC-API-020)."""
2527
servers_by_name = {server["name"]: server for server in mcp_servers_response["items"]}
2628
assert set(servers_by_name) == EXPECTED_MCP_SERVER_NAMES
2729
for name, server in servers_by_name.items():
2830
expected = EXPECTED_MCP_SERVER_TIMESTAMPS[name]
2931
assert server["createTimeSinceEpoch"] == expected["createTimeSinceEpoch"]
3032
assert server["lastUpdateTimeSinceEpoch"] == expected["lastUpdateTimeSinceEpoch"]
33+
assert "tools" not in server or server["tools"] is None, (
34+
f"Server '{name}' should not include tools by default"
35+
)
36+
assert server["toolCount"] == EXPECTED_MCP_SERVER_TOOL_COUNTS[name]
37+
38+
@pytest.mark.xfail(reason="RHOAIENG-55737 - toolLimit query parameter has no effect on MCP listing endpoint")
39+
def test_mcp_server_tool_limit(
40+
self: Self,
41+
mcp_catalog_rest_urls: list[str],
42+
model_registry_rest_headers: dict[str, str],
43+
):
44+
"""Verify toolLimit caps returned tools array (TC-API-021)."""
45+
tool_limit = 1
46+
response = execute_get_command(
47+
url=f"{mcp_catalog_rest_urls[0]}mcp_servers",
48+
headers=model_registry_rest_headers,
49+
params={"includeTools": "true", "toolLimit": str(tool_limit)},
50+
)
51+
for server in response.get("items", []):
52+
name = server["name"]
53+
assert len(server["tools"]) <= tool_limit, (
54+
f"Server '{name}' returned {len(server['tools'])} tools, expected at most {tool_limit}"
55+
)
56+
57+
@pytest.mark.tier3
58+
def test_tool_limit_exceeding_maximum(
59+
self: Self,
60+
mcp_catalog_rest_urls: list[str],
61+
model_registry_rest_headers: dict[str, str],
62+
):
63+
"""Verify toolLimit exceeding maximum (100) is rejected (TC-API-023)."""
64+
with pytest.raises(ResourceNotFoundError):
65+
execute_get_command(
66+
url=f"{mcp_catalog_rest_urls[0]}mcp_servers",
67+
headers=model_registry_rest_headers,
68+
params={"includeTools": "true", "toolLimit": "101"},
69+
)
3170

3271
def test_mcp_server_tools_loaded(
3372
self: Self,

0 commit comments

Comments
 (0)