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
Summary
Running
npx @modelcontextprotocol/inspector --cli ...from any directory other than the inspector's own install dir crashes withCannot find module '../package.json'. The CLI build resolvespackage.jsonvia CWD-relative paths instead ofimport.meta.url-relative.Reproduction
Crashes immediately with:
Workaround that works
cdinto the inspector's own install dir first:From there,
--climode works end-to-end (verified against a real MCP server:tools/listreturned the expected tools,tools/callsucceeded, JSON output was clean).Root cause hypothesis
cli/build/index.jsdoes something likerequire('../package.json')or readspath.resolve('../package.json'), both of which resolve againstprocess.cwd()when called fromnpx's wrapper, not against the script's own location. The fix is to usenew URL('../package.json', import.meta.url)(ESM) orpath.resolve(__dirname, '../package.json')(CJS).Impact
--climode 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