Skip to content

Commit abd0153

Browse files
fegedbasunag
andauthored
test: include and exclude filter for mcp servers (#1246)
Signed-off-by: fege <fmosca@redhat.com> Co-authored-by: Debarati Basu-Nag <dbasunag@redhat.com>
1 parent 8287225 commit abd0153

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

tests/model_registry/mcp_servers/config/conftest.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
MCP_CATALOG_INVALID_SOURCE,
1313
MCP_CATALOG_SOURCE,
1414
MCP_CATALOG_SOURCE2,
15+
MCP_CATALOG_SOURCE_ID,
16+
MCP_CATALOG_SOURCE_NAME,
1517
MCP_SERVERS_YAML,
1618
MCP_SERVERS_YAML2,
19+
MCP_SERVERS_YAML_CATALOG_PATH,
1720
)
1821
from tests.model_registry.utils import (
1922
wait_for_mcp_catalog_api,
@@ -106,3 +109,64 @@ def mcp_invalid_yaml_configmap_patch(
106109
wait_for_model_catalog_pod_ready_after_deletion(
107110
client=admin_client, model_registry_namespace=model_registry_namespace
108111
)
112+
113+
114+
@pytest.fixture(scope="class")
115+
def mcp_included_excluded_configmap_patch(
116+
request: pytest.FixtureRequest,
117+
admin_client: DynamicClient,
118+
model_registry_namespace: str,
119+
mcp_catalog_rest_urls: list[str],
120+
model_registry_rest_headers: dict[str, str],
121+
) -> Generator[None]:
122+
"""
123+
Class-scoped fixture that patches the ConfigMap with an MCP source
124+
including includedServers/excludedServers filters.
125+
126+
Parametrized via request.param with a dict containing:
127+
- "includedServers": list[str] (optional)
128+
- "excludedServers": list[str] (optional)
129+
"""
130+
filter_params = request.param
131+
132+
source_config: dict = {
133+
"name": MCP_CATALOG_SOURCE_NAME,
134+
"id": MCP_CATALOG_SOURCE_ID,
135+
"type": "yaml",
136+
"enabled": True,
137+
"properties": {"yamlCatalogPath": MCP_SERVERS_YAML_CATALOG_PATH},
138+
"labels": [MCP_CATALOG_SOURCE_NAME],
139+
}
140+
if "includedServers" in filter_params:
141+
source_config["includedServers"] = filter_params["includedServers"]
142+
if "excludedServers" in filter_params:
143+
source_config["excludedServers"] = filter_params["excludedServers"]
144+
145+
catalog_config_map = ConfigMap(
146+
name=DEFAULT_CUSTOM_MODEL_CATALOG,
147+
client=admin_client,
148+
namespace=model_registry_namespace,
149+
)
150+
151+
current_data = yaml.safe_load(catalog_config_map.instance.data.get("sources.yaml", "{}") or "{}")
152+
if "mcp_catalogs" not in current_data:
153+
current_data["mcp_catalogs"] = []
154+
current_data["mcp_catalogs"].append(source_config)
155+
156+
patches = {
157+
"data": {
158+
"sources.yaml": yaml.dump(current_data, default_flow_style=False),
159+
"mcp-servers.yaml": MCP_SERVERS_YAML,
160+
}
161+
}
162+
163+
with ResourceEditor(patches={catalog_config_map: patches}):
164+
wait_for_model_catalog_pod_ready_after_deletion(
165+
client=admin_client, model_registry_namespace=model_registry_namespace
166+
)
167+
wait_for_mcp_catalog_api(url=mcp_catalog_rest_urls[0], headers=model_registry_rest_headers)
168+
yield
169+
170+
wait_for_model_catalog_pod_ready_after_deletion(
171+
client=admin_client, model_registry_namespace=model_registry_namespace
172+
)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from typing import Self
2+
3+
import pytest
4+
from simple_logger.logger import get_logger
5+
6+
from tests.model_registry.utils import execute_get_command
7+
8+
LOGGER = get_logger(name=__name__)
9+
10+
11+
@pytest.mark.tier2
12+
@pytest.mark.parametrize(
13+
"mcp_included_excluded_configmap_patch",
14+
[
15+
pytest.param(
16+
{"includedServers": ["weather-*", "file-*"], "excludedServers": ["file-*"]},
17+
id="combined_include_exclude",
18+
),
19+
],
20+
indirect=True,
21+
)
22+
@pytest.mark.usefixtures("mcp_included_excluded_configmap_patch")
23+
class TestMCPServerIncludedExcludedFiltering:
24+
"""Tests for includedServers/excludedServers glob pattern filtering (TC-LOAD-003, TC-LOAD-004, TC-LOAD-005)."""
25+
26+
def test_included_and_excluded_servers(
27+
self: Self,
28+
mcp_catalog_rest_urls: list[str],
29+
model_registry_rest_headers: dict[str, str],
30+
):
31+
"""Verify includedServers are loaded and excludedServers are not (TC-LOAD-003, TC-LOAD-004, TC-LOAD-005)."""
32+
response = execute_get_command(
33+
url=f"{mcp_catalog_rest_urls[0]}mcp_servers",
34+
headers=model_registry_rest_headers,
35+
)
36+
server_names = {server["name"] for server in response.get("items", [])}
37+
assert "weather-api" in server_names, f"Expected 'weather-api' in {server_names}"
38+
assert "file-manager" not in server_names, f"Expected 'file-manager' not in {server_names}"

0 commit comments

Comments
 (0)