1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

fnm ユーザー必見!Cursor の MCP サーバーで npx が見つからない原因と対処法

Last updated at Posted at 2025-12-22

対象

  • Windows ユーザー
  • fnm で Node.js を管理している方
  • Cursor で npx ベースのMCPサーバーを動かしたい方

問題

MCPサーバーの導入時、導入したい MCPサーバーの README を確認すると以下のような設定値が記載されていることがあります。

mcp.json
{
  "mcpServers": {
    "sequential-thinking": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-sequential-thinking"
      ]
    }
  }
}

この設定をしたあとに MCPサーバーを使用すると以下のようなエラーが出ることがあります

🚨 Error
'npx' is not recognized as an internal or external command,
operable program or batch file.

問題の考察

上記の mcp.json の設定は、以下のコマンドを実行するという設定です。

実行しようとしているコマンド
npx -y @modelcontextprotocol/server-sequential-thinking

この時に、fnm による PATH 設定が反映されず、npx が見つからないエラーが発生します。

解決策

mcp.jsoncommand で直接 npx を呼ぶのではなく、powershell を経由して実行直前に環境変数を更新(パスを解決)するように変更します。

{
  "mcpServers": {
    "sequential-thinking": {
      "command": "powershell",
      "args": [
        "-Command",
        "fnm env --use-on-cd | Out-String | Invoke-Expression; npx -y @modelcontextprotocol/server-sequential-thinking"
      ]
    }
  }
}

この書き方のポイント:

  • 環境の即時セットアップ: ;(セミコロン)の前の fnm env ... 部分で、そのプロセス内だけで有効な Node.js へのパスを動的に構成します
  • 技術的な仕組み: fnm env が出力する環境変数設定コマンドを Invoke-Expression で実行することで、その場限りの「Node.js が使える環境」を作り出しています
  • 確実な動作: これにより、Windows の非対話環境下であっても、グローバルな環境変数を汚染することなく、README 通りの本来実行したいコマンドを確実に再現できます
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?