Skip to content

Fix MCP server to work via npx without pre-installing#87

Open
mcowger wants to merge 1 commit into
Helweg:mainfrom
mcowger:fix/mcp-npx-bin-alias
Open

Fix MCP server to work via npx without pre-installing#87
mcowger wants to merge 1 commit into
Helweg:mainfrom
mcowger:fix/mcp-npx-bin-alias

Conversation

@mcowger
Copy link
Copy Markdown

@mcowger mcowger commented May 17, 2026

The README currently tells users to run npx opencode-codebase-index-mcp, but that package does not exist on npm. The opencode-codebase-index-mcp binary is only available after installing the main opencode-codebase-index package locally, which defeats the purpose of using npx in the first place.

This fixes it by adding opencode-codebase-index as a second bin entry in package.json (pointing to the same dist/cli.js). Since the bin name now matches the npm package name, npx opencode-codebase-index --mcp resolves and runs in one step.

Changes:

  • package.json: Added "opencode-codebase-index": "dist/cli.js" bin alias alongside the existing opencode-codebase-index-mcp entry
  • src/cli.ts: Added --mcp flag (required for the new bin) and --help flag. The old opencode-codebase-index-mcp bin still works without --mcp for backwards compatibility.
  • README.md: Updated all MCP examples to use the new command format

The old opencode-codebase-index-mcp bin and its existing behavior are unchanged.

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.
@github-actions github-actions Bot added dependencies Dependency updates documentation Documentation changes labels May 17, 2026
Comment thread src/cli.ts
npx opencode-codebase-index-mcp (equivalent to --mcp)
`);
process.exit(0);
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner

@Helweg Helweg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Dependency updates documentation Documentation changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants