Skip to content

fix(cli): resolve package metadata from module path#1337

Open
2830500285 wants to merge 1 commit into
modelcontextprotocol:mainfrom
2830500285:fix/cli-package-metadata-path
Open

fix(cli): resolve package metadata from module path#1337
2830500285 wants to merge 1 commit into
modelcontextprotocol:mainfrom
2830500285:fix/cli-package-metadata-path

Conversation

@2830500285
Copy link
Copy Markdown

Summary

Fixes CLI package metadata lookup so --cli mode resolves package.json relative to the built module instead of the process working directory.

Note: Inspector V2 is under development to address architectural and UX improvements. During this time, V1 contributions should focus on bug fixes and MCP spec compliance. See CONTRIBUTING.md for more details.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Refactoring (no functional changes)
  • Test updates
  • Build/CI improvements

Changes Made

  • Resolve the CLI client identity package metadata from import.meta.url-relative package.json URLs.
  • Preserve support for both package layouts:
    • @modelcontextprotocol/inspector-cli with ../package.json
    • @modelcontextprotocol/inspector with ../../package.json
  • Add a regression test that copies the built CLI into a published-package-like fixture without cli/package.json, then runs from a cwd where ../package.json exists.

Related Issues

Fixes #1334

Testing

  • Tested in UI mode
  • Tested in CLI mode
  • Tested with STDIO transport
  • Tested with SSE transport
  • Tested with Streamable HTTP transport
  • Added/updated automated tests
  • Manual testing performed

Test Results and/or Instructions

Passed locally on Windows with Node v24.13.0:

npm run build-cli
npx prettier --check cli/src/index.ts cli/__tests__/cli.test.ts cli/__tests__/helpers/cli-runner.ts
cd cli; npx vitest run __tests__/cli.test.ts -t "should resolve package metadata from a published package layout"
cd cli; npx vitest run __tests__/cli.test.ts -t "should execute tools/list successfully"

I also ran npm run test-cli; the full suite has existing Windows/Node 24 HTTP transport subprocess failures where the CLI prints the expected JSON but exits with Assertion failed: !(handle->flags & UV_HANDLE_CLOSING), file src\win\async.c, line 76. The new stdio regression test passes independently and avoids that unrelated Windows HTTP teardown path.

Checklist

  • Code follows the style guidelines (ran npm run prettier-fix equivalent on changed files)
  • Self-review completed
  • Code is commented where necessary
  • Documentation updated (README, comments, etc.)

Breaking Changes

None.

Additional Context

The previous existence check used cwd-relative strings (../package.json / ../../package.json) to decide which module-relative JSON import to perform. If a caller ran the published root package from a cwd where ../package.json existed, the CLI could choose ../package.json and then fail because that file is not included under cli/ in the root package layout.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant