Claude DesktopでのBrave Search MCP Serverセットアップがasdf環境下で詰まった原因とその解決策
はじめに
こんにちは、某SIerでSEをやっているnekorush14です。
この記事ではasdf
でnodejs
をセットアップ済みの環境で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.json
のcommand
にnpx
のフルパス指定する -
claude_desktop_config.json
のenv
にasdf
のパス、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を起動すると、以下のようなエラーが発生していました。
ログを確認してみると、以下のようになっていました。
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リポジトリではセットアップ方法としてDocker
とnpx
の2通りが記載されていますが、今回はnpx
を使用します。
npx
を使用する場合のConfigは以下のような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
環境下でnpx
はasdf
のshims
にインストールされています。これを解決する方法はいくつか存在しますが、最も簡単な方法はcommand
で指定するnpx
をフルパス定義することです。
{
"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に指定する必要があります。
加えて、asdf
のnodejs
がnode
のバージョンをPATHはenv
に指定します。
最終的な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
環境下で発生するエラーに対してあまり情報がなかったので、同じような環境で詰まっている方の参考になれば幸いです。
Discussion