[BUG] User-scoped MCP servers inherit session working directory, causing npm devEngines conflicts

Resolved 💬 4 comments Opened Jan 19, 2026 by mbeckenbach Closed Feb 28, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When Claude Code launches user-scoped MCP servers, it spawns the process with the current session's working directory as the cwd. This causes MCP servers to unexpectedly fail when the working directory contains a package.json with strict devEngines or packageManager constraints.

What Should Happen?

User-scoped MCP servers should launch from a neutral directory (e.g., $HOME or the plugin's own directory) rather than inheriting the session's working directory. A user-scoped plugin should not be affected by project-specific package.json constraints.

Error Messages/Logs

[DEBUG] MCP server "plugin:context7:context7": Starting connection with timeout of 30000ms
[ERROR] MCP server "plugin:context7:context7" Server stderr: npm error code EBADDEVENGINES
[ERROR] MCP server "plugin:context7:context7" Server stderr: npm error EBADDEVENGINES Invalid name "pnpm" does not match "npm" for "packageManager"

Steps to Reproduce

  1. Have a project with a package.json containing:

``json
{
"devEngines": {
"packageManager": {
"name": "pnpm"
}
},
"packageManager": "pnpm@10.x"
}
``

  1. Install any user-scoped MCP plugin that uses npx to start (e.g., Context7, or any custom MCP server)
  1. Open Claude Code in the project directory
  1. The MCP server fails to start with:

``
npm error code EBADDEVENGINES
npm error EBADDEVENGINES Invalid name "pnpm" does not match "npm" for "packageManager"
``

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

N/A

Claude Code Version

2.1.12 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

IntelliJ IDEA terminal

Additional Information

Suggested Fix

When spawning MCP server processes, set the cwd option to a neutral directory for user-scoped plugins:

  • Use $HOME or the plugin's cache directory as the working directory
  • Alternatively, allow MCP plugin configs to specify a cwd option

Workaround

Wrap the command to change directory before executing:

{
  "context7": {
    "command": "sh",
    "args": ["-c", "cd ~ && npx -y @upstash/context7-mcp"]
  }
}

Environment Details

  • npm: 10.9.3
  • Node: v22.18.0
  • OS: Darwin 25.2.0

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗