Skip to content

Fix: Use absolute path to uv executable in Claude Desktop config #440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/mcp/cli/claude.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import os
import shutil
import sys
from pathlib import Path
from typing import Any
Expand Down Expand Up @@ -30,6 +31,16 @@ def get_claude_config_path() -> Path | None:
return path
return None

def get_uv_path() -> str:
"""Get the full path to the uv executable."""
uv_path = shutil.which("uv")
if not uv_path:
logger.error(
"uv executable not found in PATH, falling back to 'uv'. "
"Please ensure uv is installed and in your PATH"
)
return "uv" # Fall back to just "uv" if not found
return uv_path

def update_claude_config(
file_spec: str,
Expand All @@ -54,6 +65,7 @@ def update_claude_config(
Claude Desktop may not be installed or properly set up.
"""
config_dir = get_claude_config_path()
uv_path = get_uv_path()
if not config_dir:
raise RuntimeError(
"Claude Desktop config directory not found. Please ensure Claude Desktop"
Expand Down Expand Up @@ -117,7 +129,7 @@ def update_claude_config(
# Add fastmcp run command
args.extend(["mcp", "run", file_spec])

server_config: dict[str, Any] = {"command": "uv", "args": args}
server_config: dict[str, Any] = {"command": uv_path, "args": args}

# Add environment variables if specified
if env_vars:
Expand Down
25 changes: 25 additions & 0 deletions tests/client/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,28 @@ def test_command_execution(mock_config_path: Path):

assert result.returncode == 0
assert "usage" in result.stdout.lower()


def test_absolute_uv_path(mock_config_path: Path):
"""Test that the absolute path to uv is used when available."""
# Mock the shutil.which function to return a fake path
mock_uv_path = "/usr/local/bin/uv"

with patch("mcp.cli.claude.get_uv_path", return_value=mock_uv_path):
# 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())

# Verify the command is the absolute path
server_config = config["mcpServers"][server_name]
command = server_config["command"]

assert command == mock_uv_path