Skip to content

Conversation

cliffhall
Copy link
Member

@cliffhall cliffhall commented Oct 4, 2025

Description

  • In cli/src/index.ts
    • load package.json from ../ or ../../ depending on file existence in parent.
    • move the load of package.json into callMethod function, which is the only place it is used, and is closer to where it is referenced.

Motivation and Context

In #544, a change to cli/src/index.ts was introduced that reads package.json from one level up (../package.json). As reported in #834, It fails when running @modelcontextprotocol/inspector from the command line.

image
  • It works if the project is checked out locally, because the package.json of the workspace packages are present.
  • However, they are not included in the main inspector build, so it does not work in @modelcontextprotocol/inspector.
  • We can get that from two levels up (../../package.json) the in main inspector package.
  • But... if running the npm package @modelcontextprotocol/inspector-cli , the location of the workspace's package.json will be in ../ and ../../package.json will not exist.

Therefore, this PR reads ../package.json if present, otherwise it reads ../../package.json. One of the two will exist.

Location of index.js in main inspector package

image

No package.json in ../

Screenshot 2025-10-04 at 3 18 53 PM

Present at ../../package.json

image

Location of index.js in inspector-cli package

Screenshot 2025-10-04 at 3 20 13 PM

Present at../package.json

Screenshot 2025-10-04 at 3 22 49 PM

How Has This Been Tested?

Locally, running a CLI command

 node cli/build/cli.js --cli https://mcp.paypal.com/mcp --transport http --method tools/list --header "Authorization: Bearer <token>"

This is a problem that we only saw once published, but given the above known locations of the package.json in either published package, I'm confident it will work as expected. All tests still pass.

Breaking Changes

Nope.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Fixes #834

…ed that reads package.json from one level up. It works if the project is checked out locally, but not in the npm package, because the package.json of the workspace packages is not included in the inspector package. We can get that from one level up, the inpsector's own package, and so this change does that.
…lcontextprotocol/inspector or @modelcontextprotocol/inspector-cli the location of package.json will either be in ../ or ../../

* In cli/src/index.ts
  - load package.json from the parent folder or parent's parent depending on file existence in parent.
  - move the load of package.json into callMethod function, which is the only place it is used, and is closer to where it is referenced.
Copy link
Member

@olaservo olaservo left a comment

Choose a reason for hiding this comment

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

Thanks for resolving this!

@olaservo olaservo merged commit 69f1216 into modelcontextprotocol:main Oct 4, 2025
6 checks passed
@yigitkonur
Copy link

For those looking for a temporary fix, you can use npx @modelcontextprotocol/inspector-cli --cli ... instead of npx @modelcontextprotocol/inspector --cli ...

@richardkmichael
Copy link
Collaborator

Thanks @cliffhall , I'll look at adding a test for this.

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.

ERR_MODULE_NOT_FOUND: CLI fails to locate package.json when starting inspector with --cli flag
4 participants