Skip to content

Bug: npm spawn processes incorrectly use root directory instead of project directory #251

@gmaison

Description

@gmaison

Bug Description

When running an MCP server, the SDK attempts to spawn npm processes using absolute paths from the root directory (/) instead of the project directory. This causes ENOENT errors when trying to find package.json.

Current Behavior

  • The SDK attempts to find and execute package.json from the root directory (/)
  • Results in "spawn npm start ENOENT" errors
  • Makes it impossible to start the server using npm commands

Expected Behavior

  • The SDK should respect the project's directory when spawning npm processes
  • Should use relative paths or properly resolved absolute paths from the project root

Reproduction Steps

  1. Create a new MCP server project
  2. Install dependencies and build the project
  3. Attempt to start the server
  4. Observe errors in the logs showing attempts to access /package.json

Current Workarounds

Two temporary solutions have been found:

  1. Modify package.json scripts to use absolute paths:
    "start": "DEBUG=mcp:* node /full/path/to/project/dist/index.js"
2. Run the node process directly instead of using npm:
   DEBUG=mcp:* node dist/index.js

Environment
•  @modelcontextprotocol/sdk version: 1.8.0
•  Node.js version: v23.10.0
•  OS: macOS

Additional Context
This issue affects the development workflow as it prevents the standard npm scripts from working correctly. The workarounds above are functional but not ideal for distribution and deployment scenarios.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Significant bug affecting many users, highly requested featurebugSomething isn't workingready for workEnough information for someone to start working on

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions