1+ import json
2+ import subprocess
3+ from pathlib import Path
4+ from unittest .mock import patch
5+
6+ import pytest
7+
8+ from mcp .cli .claude import update_claude_config
9+
10+
11+ @pytest .fixture
12+ def temp_config_dir (tmp_path ):
13+ """Create a temporary Claude config directory."""
14+ config_dir = tmp_path / "Claude"
15+ config_dir .mkdir ()
16+ return config_dir
17+
18+ @pytest .fixture
19+ def mock_config_path (temp_config_dir ):
20+ """Mock get_claude_config_path to return our temporary directory."""
21+ with patch ('mcp.cli.claude.get_claude_config_path' , return_value = temp_config_dir ):
22+ yield temp_config_dir
23+
24+ def test_command_execution (mock_config_path ):
25+ """Test that the generated command can actually be executed."""
26+ # Setup
27+ server_name = "test_server"
28+ file_spec = "test_server.py:app"
29+
30+ # Update config
31+ success = update_claude_config (
32+ file_spec = file_spec ,
33+ server_name = server_name ,
34+ )
35+ assert success
36+
37+ # Read the generated config
38+ config_file = mock_config_path / "claude_desktop_config.json"
39+ config = json .loads (config_file .read_text ())
40+
41+ # Get the command and args
42+ server_config = config ["mcpServers" ][server_name ]
43+ command = server_config ["command" ]
44+ args = server_config ["args" ]
45+
46+ test_args = [command ] + args + ["--help" ]
47+
48+ result = subprocess .run (
49+ test_args ,
50+ capture_output = True ,
51+ text = True ,
52+ timeout = 5
53+ )
54+
55+ assert result .returncode == 0
56+ assert "usage" in result .stdout .lower ()
0 commit comments