Repository navigation
fix(secureenv): inherit user's interactive PATH so stdio servers find uvx/npx (closes #439) - #440
Merged
Merged
Conversation
… uvx/npx when launched from Finder/LoginItem (#439) When MCPProxy launches from a macOS .app bundle (Finder, Dock, Login Item), launchd hands the process PATH=/usr/bin:/bin:/usr/sbin:/sbin (4 entries). Stdio MCP servers then can't resolve uvx, npx, node, brew, etc., because none of those live on the system-bin set. The existing PATH-enhancement gate `len(pathParts) <= 2` blocked enhancement for the launchd 4-entry case. Drop that gate (EnhancePath is already an explicit opt-in for stdio in core/client.go) and merge in the user's interactive login-shell PATH via shellwrap.LoginShellPATH so non-standard installs (mise/asdf/Colima/custom shims) are also picked up. Also harden shellwrap.LoginShellPATH against rc-file banner contamination: bracket the captured $PATH with unique markers so welcome messages / oh-my-zsh updates / motd lines on stdout no longer get prepended onto the PATH value (they previously made exec.LookPath fail to resolve anything). Tests: - internal/secureenv/launchd_path_test.go — covers launchd-style 4-entry PATH, login-shell merge priority, fallback when login shell is broken, and the "already-comprehensive PATH" no-op path. - internal/shellwrap/shellwrap_test.go — TestLoginShellPATH_StripsBannerContamination verifies banner stdout is rejected by the marker parser. Verified locally: with env -i PATH=/usr/bin:/bin:/usr/sbin:/sbin on macOS, secureenv.BuildSecureEnvironment now produces a 14-entry PATH that resolves uvx, npx, node, python3, brew. Without the fix, the same env yields the unchanged 4-entry launchd PATH and the four GUI tools all fail to resolve. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Deploying mcpproxy-docs with
|
| Latest commit: |
04c4613
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://12e75339.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-issue-439-stdio-path-lau.mcpproxy-docs.pages.dev |
…PathEnhancement Post-#439 the buildEnhancedPath compose order is `login-shell PATH → discovered → existing`. On hosts where `bash -l -c '…'` does not enrich the ambient PATH (e.g. Linux CI runners — non-interactive bash does not read /etc/environment), the captured login-shell PATH equals the test's ambient `/usr/bin:/bin` and `/usr/local/bin` is added by static discovery *after* `/usr/bin`. The user-visible guarantee (`/usr/local/bin` is findable on PATH) is unchanged; only the implementation detail of strict position relative to `/usr/bin` differs. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Contributor
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 25151523103 --repo smart-mcp-proxy/mcpproxy-go
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #439. When MCPProxy launches from a macOS
.appbundle (Finder, Dock, Login Item), launchd hands the processPATH=/usr/bin:/bin:/usr/sbin:/sbin(4 entries). Stdio MCP servers then can't resolveuvx,npx,node,brew, etc., because none of those live on the system-bin set.The existing PATH-enhancement gate
len(pathParts) <= 2(ininternal/secureenv/manager.go) blocked enhancement for that 4-entry launchd PATH, so enhancement never triggered for the headline scenario in the issue. PR #420 was a related fix but only covered the PKG postinstall launch path.What this PR changes
len(pathParts) <= 2gate.EnhancePathis already an explicit opt-in (set only for stdio upstreams ininternal/upstream/core/client.go:155); the additional path-length condition was redundant and turned out to be the bug.shellwrap.LoginShellPATHso non-standard installs (mise/asdf/Colima/custom shims) get picked up — not just/usr/local/binand/opt/homebrew/bin. The login-shell capture is already cached process-wide viasync.Once.shellwrap.LoginShellPATHagainst rc-file banner contamination. Bracket the captured$PATHwith unique markers so welcome messages / oh-my-zsh updates / motd lines on stdout don't get prepended onto the value. Previously, banner output mixed with PATH madeexec.LookPathfail to resolve anything.The new compose order in
buildEnhancedPath: login-shell PATH → static-discovery → existing PATH. Static discovery acts as a deterministic floor when login-shell capture is unavailable / contaminated / shell-less. PATHs already containing/usr/local/binor/opt/homebrew/binare returned untouched (terminal launches stay clean).Test plan
go test ./internal/secureenv/... ./internal/shellwrap/... -count=1 -race— all green, including new testsgo test ./internal/upstream/...— greengo build ./cmd/mcpproxy(personal) andgo build -tags server ./cmd/mcpproxy(server) — both clean./scripts/run-linter.sh— 0 issuesenv -i PATH=/usr/bin:/bin:/usr/sbin:/sbin HOME=$HOME ./mcpproxy serve …with anpx-based stdio server connects + initializes. A focused demo program showsBuildSecureEnvironment()returns 14 PATH entries (resolvinguvx/npx/node/brew) under launchd-minimal input; onmainthe same scenario yields the unchanged 4-entry PATH and all four tools fail to resolve.New tests
internal/secureenv/launchd_path_test.go— launchd 4-entry PATH must be enhanced; login-shell entries rank ahead of launchd-minimal ones; static discovery still works when login-shell capture is empty; comprehensive PATH is left untouched.internal/shellwrap/shellwrap_test.go(TestLoginShellPATH_StripsBannerContamination) — banner stdout from rc files is rejected by the marker parser; only the bracketed$PATHvalue is returned.🤖 Generated with Claude Code