From 6194d06f6ccf976ee438de3d7d92a6a961db8882 Mon Sep 17 00:00:00 2001 From: samefarrar <67292186+samefarrar@users.noreply.github.com> Date: Sun, 29 Dec 2024 14:57:34 +0000 Subject: [PATCH 1/2] test: Add test that uv command inserted into config can run "with --help" --- tests/client/test_config.py | 56 +++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/client/test_config.py diff --git a/tests/client/test_config.py b/tests/client/test_config.py new file mode 100644 index 00000000..2a8273e3 --- /dev/null +++ b/tests/client/test_config.py @@ -0,0 +1,56 @@ +import json +import subprocess +from pathlib import Path +from unittest.mock import patch + +import pytest + +from mcp.cli.claude import update_claude_config + + +@pytest.fixture +def temp_config_dir(tmp_path): + """Create a temporary Claude config directory.""" + config_dir = tmp_path / "Claude" + config_dir.mkdir() + return config_dir + +@pytest.fixture +def mock_config_path(temp_config_dir): + """Mock get_claude_config_path to return our temporary directory.""" + with patch('mcp.cli.claude.get_claude_config_path', return_value=temp_config_dir): + yield temp_config_dir + +def test_command_execution(mock_config_path): + """Test that the generated command can actually be executed.""" + # Setup + server_name = "test_server" + file_spec = "test_server.py:app" + + # Update config + success = update_claude_config( + file_spec=file_spec, + server_name=server_name, + ) + assert success + + # Read the generated config + config_file = mock_config_path / "claude_desktop_config.json" + config = json.loads(config_file.read_text()) + + # Get the command and args + server_config = config["mcpServers"][server_name] + command = server_config["command"] + args = server_config["args"] + + test_args = [command] + args + ["--help"] + + result = subprocess.run( + test_args, + capture_output=True, + text=True, + timeout=5 + ) + + assert result.returncode == 0 + assert "usage" in result.stdout.lower() \ No newline at end of file From e65404aa05206400e9e1bc913758ceb463cbbe76 Mon Sep 17 00:00:00 2001 From: samefarrar <67292186+samefarrar@users.noreply.github.com> Date: Sun, 29 Dec 2024 15:01:25 +0000 Subject: [PATCH 2/2] fix: Install still runs the fastmcp command, which is now unecessary (/not installed). We can just run it with mcp. --- src/mcp/cli/claude.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mcp/cli/claude.py b/src/mcp/cli/claude.py index 9e2ef6c8..85223805 100644 --- a/src/mcp/cli/claude.py +++ b/src/mcp/cli/claude.py @@ -87,7 +87,7 @@ def update_claude_config( args = ["run"] # Collect all packages in a set to deduplicate - packages = {"fastmcp"} + packages = {"mcp"} if with_packages: packages.update(pkg for pkg in with_packages if pkg) @@ -107,7 +107,7 @@ def update_claude_config( file_spec = str(Path(file_spec).resolve()) # Add fastmcp run command - args.extend(["fastmcp", "run", file_spec]) + args.extend(["mcp", "run", file_spec]) server_config = { "command": "uv",