Skip to content

Inspector v0.21.2 --cli mode crashes when invoked via npx (CWD-relative package.json resolution) #1334

@brutus-gr

Description

@brutus-gr

Summary

Running npx @modelcontextprotocol/inspector --cli ... from any directory other than the inspector's own install dir crashes with Cannot find module '../package.json'. The CLI build resolves package.json via CWD-relative paths instead of import.meta.url-relative.

Reproduction

mkdir -p /tmp/inspector-cli-test && cd /tmp/inspector-cli-test
npx -y @modelcontextprotocol/inspector --cli \
  --transport sse \
  --server-url https://example.com/mcp/sse \
  --method tools/list

Crashes immediately with:

Error: Cannot find module '../package.json'
Require stack:
- /…/npm-cache/_npx/.../node_modules/@modelcontextprotocol/inspector/cli/build/index.js

Workaround that works

cd into the inspector's own install dir first:

cd $(npm root -g)/@modelcontextprotocol/inspector/cli/build
node index.js --cli --transport sse --server-url https://example.com/mcp/sse --method tools/list

From there, --cli mode works end-to-end (verified against a real MCP server: tools/list returned the expected tools, tools/call succeeded, JSON output was clean).

Root cause hypothesis

cli/build/index.js does something like require('../package.json') or reads path.resolve('../package.json'), both of which resolve against process.cwd() when called from npx's wrapper, not against the script's own location. The fix is to use new URL('../package.json', import.meta.url) (ESM) or path.resolve(__dirname, '../package.json') (CJS).

Impact

--cli mode is the only headless / scriptable path through the inspector. The CWD-relative bug means it can't be used from CI, smoke tests, or any directory other than the install path — which defeats its purpose as a non-UI verification tool.

Version

@modelcontextprotocol/inspector@0.21.2 (released 2026-04-14)

Filing because we hit this while building a third-party recipe that recommends the inspector as a smoke-test tool. Happy to PR if helpful — looks like a one-line change in the package.json resolution.

Lumetra

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions