Skip to content

Commit 9f9eede

Browse files
committed
Fix: Use absolute path to uv executable when installing MCP server
1 parent c4beb3e commit 9f9eede

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/mcp/cli/claude.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import json
44
import os
5+
import platform
6+
import subprocess
57
import sys
68
from pathlib import Path
79
from typing import Any
@@ -13,6 +15,30 @@
1315
MCP_PACKAGE = "mcp[cli]"
1416

1517

18+
def find_uv_path() -> str | None:
19+
"""Find the full path to the 'uv' executable across platforms"""
20+
21+
system = platform.system()
22+
23+
if system == "Windows":
24+
try:
25+
result = subprocess.run(
26+
["where", "uv"], capture_output=True, text=True, check=True
27+
)
28+
paths = result.stdout.strip().split("\n")
29+
return paths[0] if paths else None
30+
except subprocess.CalledProcessError:
31+
return None
32+
else:
33+
try:
34+
result = subprocess.run(
35+
["which", "uv"], capture_output=True, text=True, check=True
36+
)
37+
return result.stdout.strip()
38+
except subprocess.CalledProcessError:
39+
return None
40+
41+
1642
def get_claude_config_path() -> Path | None:
1743
"""Get the Claude config directory based on platform."""
1844
if sys.platform == "win32":
@@ -117,7 +143,15 @@ def update_claude_config(
117143
# Add fastmcp run command
118144
args.extend(["mcp", "run", file_spec])
119145

120-
server_config: dict[str, Any] = {"command": "uv", "args": args}
146+
uv_path = find_uv_path()
147+
if uv_path:
148+
server_config: dict[str, Any] = {"command": uv_path, "args": args}
149+
logger.debug(f"Using full path to uv: {uv_path}")
150+
else:
151+
server_config: dict[str, Any] = {"command": "uv", "args": args}
152+
logger.warning(
153+
"Could not determine full path to uv executable, using without path"
154+
)
121155

122156
# Add environment variables if specified
123157
if env_vars:

0 commit comments

Comments
 (0)