Skip to content
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

feat: Add Support for Absolute Paths in MCP Server Configuration to Resolve NVM Issues (#64) #136

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v22.11.0
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,4 +480,4 @@ We are passionate about supporting contributors of all levels of experience and

## License

This project is licensed under the MIT License - see the LICENSE file for details.
This project is licensed under the MIT License - see the LICENSE file for details.
2 changes: 1 addition & 1 deletion examples/servers/simple-prompt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ from mcp.client.stdio import StdioServerParameters, stdio_client

async def main():
async with stdio_client(
StdioServerParameters(command="uv", args=["run", "mcp-simple-prompt"])
StdioServerParameters(command="/Users/username/.nvm/versions/node/v22.11.0/bin/node", args=["/Users/username/.nvm/versions/node/v22.11.0/lib/node_modules/@modelcontextprotocol/server-puppeteer/dist/index.js", "uv", "run", "mcp-simple-prompt"])
) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
Expand Down
2 changes: 1 addition & 1 deletion examples/servers/simple-resource/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ from mcp.client.stdio import StdioServerParameters, stdio_client

async def main():
async with stdio_client(
StdioServerParameters(command="uv", args=["run", "mcp-simple-resource"])
StdioServerParameters(command="/Users/username/.nvm/versions/node/v22.11.0/bin/node", args=["/Users/username/.nvm/versions/node/v22.11.0/lib/node_modules/@modelcontextprotocol/server-puppeteer/dist/index.js", "uv", "run", "mcp-simple-resource"])
) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
Expand Down
8 changes: 6 additions & 2 deletions src/mcp/cli/claude.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,13 @@ def update_claude_config(
# Add fastmcp run command
args.extend(["mcp", "run", file_spec])

# Use absolute paths for Node executable and server script
node_path = "/Users/username/.nvm/versions/node/v22.11.0/bin/node"
server_script_path = "/Users/username/.nvm/versions/node/v22.11.0/lib/node_modules/@modelcontextprotocol/server-puppeteer/dist/index.js"

server_config = {
"command": "uv",
"args": args,
"command": node_path,
"args": [server_script_path] + args,
}

# Add environment variables if specified
Expand Down
15 changes: 5 additions & 10 deletions src/mcp/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,14 @@ def dev(

uv_cmd = _build_uv_command(file_spec, with_editable, with_packages)

# Get the correct npx command
npx_cmd = _get_npx_command()
if not npx_cmd:
logger.error(
"npx not found. Please ensure Node.js and npm are properly installed "
"and added to your system PATH."
)
sys.exit(1)
# Use absolute paths for Node executable and server script
node_path = "/Users/username/.nvm/versions/node/v22.11.0/bin/node"
server_script_path = "/Users/username/.nvm/versions/node/v22.11.0/lib/node_modules/@modelcontextprotocol/server-puppeteer/dist/index.js"

# Run the MCP Inspector command with shell=True on Windows
shell = sys.platform == "win32"
process = subprocess.run(
[npx_cmd, "@modelcontextprotocol/inspector"] + uv_cmd,
[node_path, server_script_path] + uv_cmd,
check=True,
shell=shell,
env=dict(os.environ.items()), # Convert to list of tuples for env update
Expand All @@ -269,7 +264,7 @@ def dev(
sys.exit(e.returncode)
except FileNotFoundError:
logger.error(
"npx not found. Please ensure Node.js and npm are properly installed "
"Node executable not found. Please ensure Node.js and npm are properly installed "
"and added to your system PATH. You may need to restart your terminal "
"after installation.",
extra={"file": str(file)},
Expand Down