Fix MCP server to work via npx without pre-installing#87
Conversation
Add 'opencode-codebase-index' as a second bin entry pointing to the same dist/cli.js, so that resolves the package on npm and starts the MCP server in one step -- no separate npm install required. The old bin is preserved for backwards compatibility; it auto-starts MCP mode without requiring the --mcp flag. The new bin requires --mcp to avoid accidentally launching the server when the user just runs the bare command.
| npx opencode-codebase-index-mcp (equivalent to --mcp) | ||
| `); | ||
| process.exit(0); | ||
| } |
There was a problem hiding this comment.
This breaks the advertised backward-compatibility path for opencode-codebase-index-mcp.
Under normal npm/npx execution, process.argv[0] and process.execPath point to the Node executable, not the invoked bin name, so this check stays false even when the user launched opencode-codebase-index-mcp.
That means the legacy bin will fall into the new --mcp usage error path instead of preserving the old behavior. Please detect the invoked bin from process.argv[1] or use a dedicated wrapper bin, and add a regression test for both entrypoints.
Helweg
left a comment
There was a problem hiding this comment.
Requesting changes because the new npx opencode-codebase-index --mcp flow looks fine, but the legacy opencode-codebase-index-mcp compatibility path appears broken. The current detection checks the Node executable path rather than the invoked bin name, so existing users may now hit the --mcp usage error. Once that detection is fixed and covered by a regression test for both entrypoints, this looks good to me.
The README currently tells users to run
npx opencode-codebase-index-mcp, but that package does not exist on npm. Theopencode-codebase-index-mcpbinary is only available after installing the mainopencode-codebase-indexpackage locally, which defeats the purpose of usingnpxin the first place.This fixes it by adding
opencode-codebase-indexas a second bin entry in package.json (pointing to the samedist/cli.js). Since the bin name now matches the npm package name,npx opencode-codebase-index --mcpresolves and runs in one step.Changes:
"opencode-codebase-index": "dist/cli.js"bin alias alongside the existingopencode-codebase-index-mcpentry--mcpflag (required for the new bin) and--helpflag. The oldopencode-codebase-index-mcpbin still works without--mcpfor backwards compatibility.The old
opencode-codebase-index-mcpbin and its existing behavior are unchanged.