やろうとしたこと
- Claude Desktop + Playwright MCPを試そうとした
- 手順に沿ってインストールしようとしたところ、エラーになった
原因はNodeに関する話題でした。
ここではPlaywright MCPのケースを記載しますが、Playwright MCPに限った話題ではないと思います。
画面に表示されたエラーメッセージ
画面に表示されたエラーメッセージ
MCP Playwright: write EPIPE
MCP playwright: Server disconnected. For troubleshooting guidance, please visit our debugging documentation
エラーログ上のエラーメッセージ
mcp-server-playwright.log
2025-05-05T04:20:26.693Z [playwright] [info] Initializing server...
2025-05-05T04:20:26.710Z [playwright] [info] Server started and connected successfully
env: node: No such file or directory
2025-05-05T04:20:26.714Z [playwright] [info] Message from client: {"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"claude-ai","version":"0.1.0"}},"jsonrpc":"2.0","id":0}
2025-05-05T04:20:26.714Z [playwright] [error] write EPIPE {"context":"connection","stack":"Error: write EPIPE\n at afterWriteDispatched (node:internal/stream_base_commons:161:15)\n at writeGeneric (node:internal/stream_base_commons:152:3)\n at Socket._writeGeneric (node:net:958:11)\n at Socket._write (node:net:970:8)\n at writeOrBuffer (node:internal/streams/writable:572:12)\n at _write (node:internal/streams/writable:501:10)\n at Writable.write (node:internal/streams/writable:510:10)\n at /Applications/Claude.app/Contents/Resources/app.asar/.vite/build/index.js:109:2240\n at new Promise (<anonymous>)\n at B$e.send (/Applications/Claude.app/Contents/Resources/app.asar/.vite/build/index.js:109:2095)"}
2025-05-05T04:20:26.715Z [playwright] [info] Server transport closed
2025-05-05T04:20:26.715Z [playwright] [info] Client transport closed
2025-05-05T04:20:26.715Z [playwright] [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-05-05T04:20:26.715Z [playwright] [error] Server disconnected. For troubleshooting guidance, please visit our [debugging documentation](https://modelcontextprotocol.io/docs/tools/debugging) {"context":"connection"}
2025-05-05T04:20:26.715Z [playwright] [info] Client transport closed
解決方法
ポイントはログに出力されているenv: node: No such file or directory
です。
画面に表示されるEPIPE
に目が行ってしまいますが、大事なのはNodeが見つからない方でした。
確認ポイント1: Node.jsが未インストールの場合、インストールする
Node.jsが必須ですので、インストールすることで解決します。
https://nodejs.org/ja
確認ポイント2: Nodeがインストール済みの場合、パスを疑う
私のマシンには元からNodeがインストール済みです。
node --version
でバージョンが表示されるにも関わらず、このエラーが発生しました。
調べていったところ、Claude DesktopがNodeにアクセスできない=パスが通っていないことが原因でした。
nodenvやnvmなどのNodeのバージョン管理ツールを使用している場合に起きやすいと思います。
私の場合はanyenv + nodenvの構成でした。
要はnpxのパスを通してあげればいいので、以下の方法で解決します。
手順1: npxのフルパスを取得する
% which npx
/Users/${ユーザー名}/.anyenv/envs/nodenv/shims/npx
※1 ここの結果はそれぞれの環境によって異なります。
※2 macの場合です。Windowsの場合はwhich
でなくwhere.exe
のようですが、環境がなく試してません。
手順2: npxコマンドを書き換える
claude_desktop_config.json
{
"mcpServers": {
"playwright": {
- "command": "npx",
+ "command": "/Users/${ユーザー名}/.anyenv/envs/nodenv/shims/npx",
"args": [
"@playwright/mcp@latest"
]
}
}
}
(備考) 環境情報
環境差異はないと思いますけれど一応。
- Mac (macOS Sequoia)
- Claude Desktop (Claude for Mac) 0.9.3
- Playwright MCP v0.0.20
- nodenv v1.5.0
- anyenv v1.1.4
- Node v20.14.0