modelcontextprotocol / modelcontextprotocol/typescript-sdk
Bug: npm spawn processes incorrectly use root directory instead of project directory
Nobody has claimed this yet.
- 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
- Create a new MCP server project
- Install dependencies and build the project
- Attempt to start the server
- Observe errors in the logs showing attempts to access /package.json
Current Workarounds
Two temporary solutions have been found:
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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