modelcontextprotocol / modelcontextprotocol/typescript-sdk

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

Open
#251 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug P1 potentially close ready for work
Dominant language
TypeScript
Stars
13.4k
Forks
2.2k
Avg merge
3d 15h
Merged PRs (30d)
4

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure while launching an MCP server through its npm start script, then inspect the SDK process-spawning path and how it resolves the project directory. Use the reported /package.json lookup and ENOENT error as the baseline; done means npm commands resolve the project package.json and start successfully without absolute-path workarounds.

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, typescript
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.