Skip to content

Commit 688b4ed

Browse files
author
LittleCoinCoin
committed
test: extend test data infrastructure for MCP host configuration
Add MCPHostConfigTestDataLoader class to existing test utilities for comprehensive MCP-specific test data management. Features: - Host configuration templates for all supported host types - Inheritance pattern templates (Claude family, Cursor family, Independent) - Corrected environment data structure templates (v2) - Consolidated MCPServerConfig templates (local and remote) - Automatic template generation with realistic test data Templates include: - Claude family: Absolute path requirements and Anthropic-specific settings - Cursor family: Flexible path handling and shared configuration format - Independent strategies: Unique formats for VSCode and Gemini - Environment data: Single-server-per-package constraint validation - Server configs: Local (command-based) and remote (URL-based) variants Extends existing TestDataLoader infrastructure while maintaining compatibility with current test patterns and organizational standards.
1 parent 61681be commit 688b4ed

File tree

7 files changed

+317
-0
lines changed

7 files changed

+317
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "multi_host_environment",
3+
"description": "Environment with single server configured across multiple hosts",
4+
"created_at": "2025-09-21T10:00:00.000000",
5+
"packages": [
6+
{
7+
"name": "file-manager",
8+
"version": "2.0.0",
9+
"type": "hatch",
10+
"source": "github:user/file-manager",
11+
"installed_at": "2025-09-21T10:00:00.000000",
12+
"configured_hosts": {
13+
"claude-desktop": {
14+
"config_path": "~/Library/Application Support/Claude/claude_desktop_config.json",
15+
"configured_at": "2025-09-21T10:00:00.000000",
16+
"last_synced": "2025-09-21T10:00:00.000000",
17+
"server_config": {
18+
"command": "/usr/local/bin/python",
19+
"args": [
20+
"file_manager.py"
21+
],
22+
"env": {
23+
"DEBUG": "true"
24+
}
25+
}
26+
},
27+
"cursor": {
28+
"config_path": "~/.cursor/mcp.json",
29+
"configured_at": "2025-09-21T10:00:00.000000",
30+
"last_synced": "2025-09-21T10:00:00.000000",
31+
"server_config": {
32+
"command": "python",
33+
"args": [
34+
"file_manager.py"
35+
],
36+
"env": {
37+
"DEBUG": "true"
38+
}
39+
}
40+
}
41+
}
42+
}
43+
]
44+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "test_environment",
3+
"description": "Test environment with corrected MCP structure",
4+
"created_at": "2025-09-21T10:00:00.000000",
5+
"packages": [
6+
{
7+
"name": "weather-toolkit",
8+
"version": "1.0.0",
9+
"type": "hatch",
10+
"source": "github:user/weather-toolkit",
11+
"installed_at": "2025-09-21T10:00:00.000000",
12+
"configured_hosts": {
13+
"claude-desktop": {
14+
"config_path": "~/Library/Application Support/Claude/claude_desktop_config.json",
15+
"configured_at": "2025-09-21T10:00:00.000000",
16+
"last_synced": "2025-09-21T10:00:00.000000",
17+
"server_config": {
18+
"command": "/usr/local/bin/python",
19+
"args": [
20+
"weather.py"
21+
],
22+
"env": {
23+
"API_KEY": "weather_key"
24+
}
25+
}
26+
}
27+
}
28+
}
29+
]
30+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"command": "python",
3+
"args": [
4+
"server.py",
5+
"--port",
6+
"8080"
7+
],
8+
"env": {
9+
"API_KEY": "test",
10+
"DEBUG": "true"
11+
}
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"command": "python",
3+
"args": [
4+
"minimal_server.py"
5+
]
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"url": "https://api.example.com/mcp",
3+
"headers": {
4+
"Authorization": "Bearer token",
5+
"Content-Type": "application/json"
6+
}
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"url": "https://minimal.example.com/mcp"
3+
}

tests/test_data_utils.py

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,218 @@ def load_mock_response(response_name: str) -> Dict[str, Any]:
255255
def get_test_packages_dir() -> Path:
256256
"""Get test packages directory."""
257257
return test_data.get_test_packages_dir()
258+
259+
260+
class MCPHostConfigTestDataLoader(TestDataLoader):
261+
"""Specialized test data loader for MCP host configuration tests v2."""
262+
263+
def __init__(self):
264+
super().__init__()
265+
self.mcp_host_configs_dir = self.configs_dir / "mcp_host_test_configs"
266+
self.mcp_host_configs_dir.mkdir(exist_ok=True)
267+
268+
def load_host_config_template(self, host_type: str, config_type: str = "simple") -> Dict[str, Any]:
269+
"""Load host-specific configuration template."""
270+
config_path = self.mcp_host_configs_dir / f"{host_type}_{config_type}.json"
271+
if not config_path.exists():
272+
self._create_host_config_template(host_type, config_type)
273+
274+
with open(config_path, 'r') as f:
275+
return json.load(f)
276+
277+
def load_corrected_environment_data(self, data_type: str = "simple") -> Dict[str, Any]:
278+
"""Load corrected environment data structure (v2)."""
279+
config_path = self.mcp_host_configs_dir / f"environment_v2_{data_type}.json"
280+
if not config_path.exists():
281+
self._create_corrected_environment_data(data_type)
282+
283+
with open(config_path, 'r') as f:
284+
return json.load(f)
285+
286+
def load_mcp_server_config(self, server_type: str = "local") -> Dict[str, Any]:
287+
"""Load consolidated MCPServerConfig templates."""
288+
config_path = self.mcp_host_configs_dir / f"mcp_server_{server_type}.json"
289+
if not config_path.exists():
290+
self._create_mcp_server_config(server_type)
291+
292+
with open(config_path, 'r') as f:
293+
return json.load(f)
294+
295+
def _create_host_config_template(self, host_type: str, config_type: str):
296+
"""Create host-specific configuration templates with inheritance patterns."""
297+
templates = {
298+
# Claude family templates
299+
"claude-desktop_simple": {
300+
"mcpServers": {
301+
"test_server": {
302+
"command": "/usr/local/bin/python", # Absolute path required
303+
"args": ["server.py"],
304+
"env": {"API_KEY": "test"}
305+
}
306+
},
307+
"theme": "dark", # Claude-specific settings
308+
"auto_update": True
309+
},
310+
"claude-code_simple": {
311+
"mcpServers": {
312+
"test_server": {
313+
"command": "/usr/local/bin/python", # Absolute path required
314+
"args": ["server.py"],
315+
"env": {}
316+
}
317+
},
318+
"workspace_settings": {"mcp_enabled": True} # Claude Code specific
319+
},
320+
321+
# Cursor family templates
322+
"cursor_simple": {
323+
"mcpServers": {
324+
"test_server": {
325+
"command": "python", # Flexible path handling
326+
"args": ["server.py"],
327+
"env": {"API_KEY": "test"}
328+
}
329+
}
330+
},
331+
"cursor_remote": {
332+
"mcpServers": {
333+
"remote_server": {
334+
"url": "https://api.example.com/mcp",
335+
"headers": {"Authorization": "Bearer token"}
336+
}
337+
}
338+
},
339+
"lmstudio_simple": {
340+
"mcpServers": {
341+
"test_server": {
342+
"command": "python", # Inherits Cursor format
343+
"args": ["server.py"],
344+
"env": {}
345+
}
346+
}
347+
},
348+
349+
# Independent strategy templates
350+
"vscode_simple": {
351+
"mcp": {
352+
"servers": {
353+
"test_server": {
354+
"command": "python",
355+
"args": ["server.py"]
356+
}
357+
}
358+
}
359+
},
360+
"gemini_simple": {
361+
"mcpServers": {
362+
"test_server": {
363+
"command": "python",
364+
"args": ["server.py"]
365+
}
366+
}
367+
}
368+
}
369+
370+
template_key = f"{host_type}_{config_type}"
371+
config = templates.get(template_key, {"mcpServers": {}})
372+
config_path = self.mcp_host_configs_dir / f"{template_key}.json"
373+
with open(config_path, 'w') as f:
374+
json.dump(config, f, indent=2)
375+
376+
def _create_corrected_environment_data(self, data_type: str):
377+
"""Create corrected environment data templates (v2 structure)."""
378+
templates = {
379+
"simple": {
380+
"name": "test_environment",
381+
"description": "Test environment with corrected MCP structure",
382+
"created_at": "2025-09-21T10:00:00.000000",
383+
"packages": [
384+
{
385+
"name": "weather-toolkit",
386+
"version": "1.0.0",
387+
"type": "hatch",
388+
"source": "github:user/weather-toolkit",
389+
"installed_at": "2025-09-21T10:00:00.000000",
390+
"configured_hosts": {
391+
"claude-desktop": {
392+
"config_path": "~/Library/Application Support/Claude/claude_desktop_config.json",
393+
"configured_at": "2025-09-21T10:00:00.000000",
394+
"last_synced": "2025-09-21T10:00:00.000000",
395+
"server_config": {
396+
"command": "/usr/local/bin/python",
397+
"args": ["weather.py"],
398+
"env": {"API_KEY": "weather_key"}
399+
}
400+
}
401+
}
402+
}
403+
]
404+
},
405+
"multi_host": {
406+
"name": "multi_host_environment",
407+
"description": "Environment with single server configured across multiple hosts",
408+
"created_at": "2025-09-21T10:00:00.000000",
409+
"packages": [
410+
{
411+
"name": "file-manager",
412+
"version": "2.0.0",
413+
"type": "hatch",
414+
"source": "github:user/file-manager",
415+
"installed_at": "2025-09-21T10:00:00.000000",
416+
"configured_hosts": {
417+
"claude-desktop": {
418+
"config_path": "~/Library/Application Support/Claude/claude_desktop_config.json",
419+
"configured_at": "2025-09-21T10:00:00.000000",
420+
"last_synced": "2025-09-21T10:00:00.000000",
421+
"server_config": {
422+
"command": "/usr/local/bin/python",
423+
"args": ["file_manager.py"],
424+
"env": {"DEBUG": "true"}
425+
}
426+
},
427+
"cursor": {
428+
"config_path": "~/.cursor/mcp.json",
429+
"configured_at": "2025-09-21T10:00:00.000000",
430+
"last_synced": "2025-09-21T10:00:00.000000",
431+
"server_config": {
432+
"command": "python",
433+
"args": ["file_manager.py"],
434+
"env": {"DEBUG": "true"}
435+
}
436+
}
437+
}
438+
}
439+
]
440+
}
441+
}
442+
443+
config = templates.get(data_type, {"packages": []})
444+
config_path = self.mcp_host_configs_dir / f"environment_v2_{data_type}.json"
445+
with open(config_path, 'w') as f:
446+
json.dump(config, f, indent=2)
447+
448+
def _create_mcp_server_config(self, server_type: str):
449+
"""Create consolidated MCPServerConfig templates."""
450+
templates = {
451+
"local": {
452+
"command": "python",
453+
"args": ["server.py", "--port", "8080"],
454+
"env": {"API_KEY": "test", "DEBUG": "true"}
455+
},
456+
"remote": {
457+
"url": "https://api.example.com/mcp",
458+
"headers": {"Authorization": "Bearer token", "Content-Type": "application/json"}
459+
},
460+
"local_minimal": {
461+
"command": "python",
462+
"args": ["minimal_server.py"]
463+
},
464+
"remote_minimal": {
465+
"url": "https://minimal.example.com/mcp"
466+
}
467+
}
468+
469+
config = templates.get(server_type, {})
470+
config_path = self.mcp_host_configs_dir / f"mcp_server_{server_type}.json"
471+
with open(config_path, 'w') as f:
472+
json.dump(config, f, indent=2)

0 commit comments

Comments
 (0)