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

fix(server) Avoid modifying path resolution for executables on MacOS #115

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jacksteamdev
Copy link
Contributor

@jacksteamdev jacksteamdev commented Dec 17, 2024

Motivation and Context

spawn-rx follows symlinks when resolving executables, which breaks version manager shims on macOS. For example, when using Volta, bun incorrectly resolves to volta-shim instead of the bun executable. This PR works around the issue by bypassing spawn-rx's path resolution on non-Windows platforms.

Closes #114

How Has This Been Tested?

  • Verified direct command execution works with Volta-managed bun on macOS
  • Confirmed Windows path resolution remains untouched

Breaking Changes

None. This restores expected behavior on macOS while maintaining existing Windows functionality.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

This could be a temporary fix while we investigate the underlying spawn-rx path resolution behavior. We may want to upstream a fix that handles Windows PATH resolution without affecting Unix shims.

To Reproduce

Steps to reproduce the behavior:

  1. On MacOS, use Volta or another Node version management tool that uses symlinks to install Node or Bun.
  2. In the MPC inspector UI, enter your command: bun or node.
  3. Use the MPC inspector to launch your server.
image

Expected behavior

The inspector should spawn the command as entered in the UI.

Logs

I'm getting this error:

Volta error: 'volta-shim' should not be called directly. Please use the existing shims provided by Volta (node, yarn, etc.) to run tools.

Note that the command bun is resolved incorrectly.

Stdio transport: command=/Users/jacksteam/.volta/bin/volta-shim, args=src/index.ts, env={"HOME":"/Users/jacksteam","LOGNAME":"jacksteam","PATH":"/Users/jacksteam/.npm/_npx/5a9d879542beca3a/node_modules/.bin:/Users/jacksteam/Documents/Cline/MCP/zettelkasten-server/node_modules/.bin:/Users/jacksteam/Documents/Cline/MCP/node_modules/.bin:/Users/jacksteam/Documents/Cline/node_modules/.bin:/Users/jacksteam/Documents/node_modules/.bin:/Users/jacksteam/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/Users/jacksteam/.volta/tools/image/node/20.16.0/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/Users/jacksteam/.volta/tools/image/node/20.16.0/bin:/Users/jacksteam/perl5/bin:/Users/jacksteam/Library/pnpm:/Users/jacksteam/.volta/bin:/opt/homebrew/opt/openjdk/bin:/Users/jacksteam/.jenv/shims:/Users/jacksteam/.jenv/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Users/jacksteam/Library/Application Support/Code/User/globalStorage/github.copilot-chat/debugCommand","SHELL":"/bin/zsh","TERM":"xterm-256color","USER":"jacksteam"}

Edit: rephrase to be more clear and concise, add additional context

@anaisbetts
Copy link
Contributor

Can you explain more about what is going on with spawn-rx? I'd rather actually just make it work correctly on all platforms

@jacksteamdev
Copy link
Contributor Author

jacksteamdev commented Dec 19, 2024

@anaisbetts Hi Ani! Looking at spawn-rx, I think I've identified the core issue: runDownPath follows symlinks with realpathSync, which breaks version manager shims on macOS.

For example with Volta-managed bun:

  • which bun/Users/jacksteam/.volta/bin/bun
  • runDownPath("bun")/Users/jacksteam/.volta/bin/volta-shim

The code comment suggests this was added for Windows PATH resolution. Would you mind sharing the original Windows issue this was solving? We might be able to handle that case specifically while preserving normal PATH behavior on Unix.


Edit: rephrase to be more concise

@jacksteamdev jacksteamdev changed the title fix(server) Differentiate command resolution by platform fix(server) Avoid modifying path resolution for executables on MacOS Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Path resolution library doesn't handle MacOS commands correctly
2 participants