Zenn
🛠️

Claude DesktopでのBrave Search MCP Serverセットアップがasdf環境下で詰まった原因とその解決策

2025/03/16に公開
2

はじめに

こんにちは、某SIerでSEをやっているnekorush14です。
この記事ではasdfnodejsをセットアップ済みの環境でBrave SearchのMCP Serverをセットアップする際に詰まったので、発生したとその解決策をまとめます。

環境

この記事は以下の環境を前提にしています。
()で示しているのはインストール方法です。

  • OS: macOS Sequoia 15.3.1
  • Claude Desktop: 0.8.0
  • asdf(Homebrew): 0.16.3
  • node(asdf): 22.14.0

TL;DR

  • claude_desktop_config.jsoncommandnpxのフルパス指定する
  • claude_desktop_config.jsonenvasdfのパス、nodejsのバージョンを追加する
  • claude_desktop_config.jsonは以下の通り
    claude_desktop_config.json
    {
      "brave-search": {
        "command": "<FULL_PATH_TO_NPX>",
        "args": [
          "-y",
          "@modelcontextprotocol/server-brave-search"
        ],
        "env": {
          "BRAVE_API_KEY": "YOUR_API_KEY_HERE",
          "PATH": "<PATH_TO_ASDF_SHIMS_DIR>:<PATH_TO_ASDF_BIN_DIR>:/usr/bin:/bin",
          "ASDF_NODEJS_VERSION": "<ASDF_NODEJS_VERSION>"
        }
      }
    }
    
    • <FULL_PATH_TO_NPX>which npxで確認できるフルパス
    • <PATH_TO_ASDF_SHIMS_DIR>which npxで確認できるパスの/npxを除いた部分
      • 例: /Users/<YOUR_USER_NAME>/.asdf/shims
    • <PATH_TO_ASDF_BIN_DIR>which asdfで確認できるパスの/asdfを除いた部分
      • 例: /opt/homebrew/bin
    • <ASDF_NODEJS_VERSION>asdf current nodejsで確認できるバージョン
      • 例: 22.14.0

今回発生した事象

Brave Search MCP ServerのGithubリポジトリに記載されたConfigを設定した状態でClaude Desktopを起動すると、以下のようなエラーが発生していました。

alt text

ログを確認してみると、以下のようになっていました。

2025-03-14T13:41:08.101Z [brave-search] [info] Initializing server...
2025-03-14T13:41:08.116Z [brave-search] [error] spawn npx ENOENT {"context":"connection","stack":"Error: spawn npx ENOENT\n    at ChildProcess._handle.onexit (node:internal/child_process:285:19)\n    at onErrorNT (node:internal/child_process:483:16)\n    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)"}
2025-03-14T13:41:08.117Z [brave-search] [error] spawn npx ENOENT {"stack":"Error: spawn npx ENOENT\n    at ChildProcess._handle.onexit (node:internal/child_process:285:19)\n    at onErrorNT (node:internal/child_process:483:16)\n    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)"}
2025-03-14T13:41:08.119Z [brave-search] [info] Server transport closed
2025-03-14T13:41:08.119Z [brave-search] [info] Client transport closed
2025-03-14T13:41:08.120Z [brave-search] [info] Server transport closed unexpectedly, this is likely due to the process exiting early. If you are developing this MCP server you can add output to stderr (i.e. `console.error('...')` in JavaScript, `print('...', file=sys.stderr)` in python) and it will appear in this log.
2025-03-14T13:41:08.120Z [brave-search] [error] Server disconnected. For troubleshooting guidance, please visit our [debugging documentation](https://modelcontextprotocol.io/docs/tools/debugging) {"context":"connection"}

どうやら、npxが見つからずにエラーとなっているようです。

Brave Search MCP ServerのGithubリポジトリではセットアップ方法としてDockernpxの2通りが記載されていますが、今回はnpxを使用します。
npxを使用する場合のConfigは以下のようなclaude_desktop_config.jsonとなります。

claude_desktop_config.json
{
  "mcpServers": {
    "brave-search": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-brave-search"
      ],
      "env": {
        "BRAVE_API_KEY": "YOUR_API_KEY_HERE"
      }
    }
  }
}

解決策

npxが見つからない原因はMCPが実行するShellの環境変数にasdfのパスが含まれていないためです。今回の環境ではasdfでインストールしたnodeを使用しているため、asdf環境下でnpxasdfshimsにインストールされています。これを解決する方法はいくつか存在しますが、最も簡単な方法はcommandで指定するnpxをフルパス定義することです。

claude_desktop_config.json
{
  "brave-search": {
    "command": "<FULL_PATH_TO_NPX>",
    "args": [
      "-y",
      "@modelcontextprotocol/server-brave-search"
    ],
    "env": {
      "BRAVE_API_KEY": "YOUR_API_KEY_HERE"
    }
  }
}

<FULL_PATH_TO_NPX>which npxで確認できるフルパスを指定します。また、Brave Search MCP Serverは内部でshを実行してるようなので/binなどもPATHに指定する必要があります。
加えて、asdfnodejsnodeのバージョンをPATHはenvに指定します。
最終的なclaude_desktop_config.jsonは以下のようになります。

claude_desktop_config.json
{
  "brave-search": {
    "command": "<FULL_PATH_TO_NPX>",
    "args": [
      "-y",
      "@modelcontextprotocol/server-brave-search"
    ],
    "env": {
      "BRAVE_API_KEY": "YOUR_API_KEY_HERE",
      "PATH": "<PATH_TO_ASDF_SHIMS_DIR>:<PATH_TO_ASDF_BIN_DIR>:/usr/bin:/bin",
      "ASDF_NODEJS_VERSION": "<ASDF_NODEJS_VERSION>"
    }
  }
}
  • <PATH_TO_ASDF_SHIMS_DIR>which npxで確認できるパスの/npxを除いた部分
    • 例: /Users/<YOUR_USER_NAME>/.asdf/shims
  • <PATH_TO_ASDF_BIN_DIR>which asdfで確認できるパスの/asdfを除いた部分
    • 例: /opt/homebrew/bin
  • <ASDF_NODEJS_VERSION>asdf current nodejsで確認できるバージョン
    • 例: 22.14.0

まとめ

今回はClaude DesktopでBrave SearchのMCP Serverをセットアップする際に発生したnpxが見つからないエラーについて、原因と解決策をまとめました。asdf環境下で発生するエラーに対してあまり情報がなかったので、同じような環境で詰まっている方の参考になれば幸いです。

参考資料

2

Discussion

ログインするとコメントできます