fix: skip npx prefix for globally installed binaries in MCP registration#115
Open
fix: skip npx prefix for globally installed binaries in MCP registration#115
Conversation
When a CLI is installed globally (e.g. `npm i -g`), `process.argv[1]`
resolves outside `node_modules/`. The MCP registration now detects this
and registers the bare command name instead of wrapping it in npx/pnpx/bunx.
Also replaces naive `command.split(' ')` in registerAmp with a
quote-aware tokenizer so command paths containing spaces are handled
correctly.
commit: |
Replace duplicate node_modules/ regex checks with a single nodeModulesRoot() helper that returns the path prefix or null. Both register() and detectPackageSpecifier() now call the same function.
418d75f to
2938f99
Compare
CI uses pnpm so detectRunner() returns pnpx, not npx. Match any valid runner (npx, pnpx, bunx) instead of hardcoding npx.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #115 +/- ##
=======================================
Coverage ? 93.03%
=======================================
Files ? 23
Lines ? 2857
Branches ? 1159
=======================================
Hits ? 2658
Misses ? 166
Partials ? 33 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
npm i -g), MCP registration now detects thatprocess.argv[1]is outsidenode_modules/and registers the bare command name (e.g.my-cli --mcp) instead of wrapping it innpxunnecessarilycommand.split(' ')inregisterAmpwith a quote-aware tokenizer so paths containing spaces (e.g."/path/to my/cli" --mcp) split correctlynode_modules/heuristic into a singlenodeModulesRoot()helper shared by bothregister()anddetectPackageSpecifier()Test plan
my-cli --mcp(no runner prefix)node_modulesinstall still producesnpx my-cli --mcp