fix(cli): detect direct run through npm bin symlinks#39
Merged
stevenobiajulu merged 2 commits intomainfrom Apr 20, 2026
Merged
Conversation
Both email-agent-mcp and @usejunior/email-mcp declare a bin named email-agent-mcp, and the sibling @usejunior/email-mcp entry wins when npm installs the wrapper. The installed bin is a symlink to dist/cli.js, so process.argv[1] ends with "email-agent-mcp" — not "cli.js". The suffix-based isDirectRun guard returned false in that case, the module loaded without calling runCli, and the process exited 0 with no output. That reproduced as the "npx email-agent-mcp --help silently exits" bug seen downstream. Replace the suffix check with a realpath-based comparison between process.argv[1] and the compiled cli.js path. Extract the predicate as isDirectCliRun so it can be covered by tests for both the symlink and wrapper cases.
Covers the npm bin symlink direct-run fix in the same release so a published 0.1.6 restores `npx email-agent-mcp` usability end-to-end.
ec0e7c9 to
f8f295f
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This was referenced Apr 20, 2026
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
npx email-agent-mcp <anything>was silently exiting 0 with no output — not just setup, even--help. Directnode .../bin/email-agent-mcp.jsalways worked, so the bug only surfaced through npm bin installs.email-agent-mcp(wrapper) and@usejunior/email-mcp(core) declare abinnamedemail-agent-mcp. When both are installed,@usejunior/email-mcpwins and~/.npm-global/bin/email-agent-mcpsymlinks todist/cli.js— not to the wrapper. That's fine except the auto-execute guard at the bottom ofcli.jswas a brittle suffix check (argv[1].endsWith('cli.js') || argv[1].endsWith('cli.ts')). Via the symlink,argv[1]ends withemail-agent-mcp, so the guard wasfalse,runClinever ran, and the module exited cleanly with no work done.realpathSync(argv[1]) === realpathSync(fileURLToPath(import.meta.url))comparison, so direct execution through npm bin symlinks is detected the same as direct-path invocation. Extracted the predicate as exportedisDirectCliRunfor testability.true, wrapper-path invocation returnsfalse.0.1.6in lockstep viascripts/bump_version.mjs.Follow-up (separate PR)
Belt-and-suspenders: drop the
binfield from@usejunior/email-mcp/package.jsonentirely, since the core package isn't meant to be run directly by end users. That would prevent the two packages from fighting over the same bin name at install time and remove this class of bug at the source. Not included here to keep the fix minimal.Test plan
npm run build(all workspaces)npm run test:run -w @usejunior/email-mcp→ 137 passed~/.npm-global/bin/email-agent-mcp0.1.6to npm and verify a freshnpx email-agent-mcp --helpfrom a clean shell prints help