3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Docker版n8nでホストPCのPlaywright MCPを使用する

Last updated at Posted at 2025-12-03

TL;DR

Docker Command

docker run -it --rm \
  --add-host="host.docker.internal:host-gateway" \
  -p 5678:5678 \
  docker.n8n.io/n8nio/n8n

Playwright Command

npx @playwright/mcp --allowed-hosts "host.docker.internal,host.docker.internal:8931" --port 8931 

発端

n8nでホストPCのPlaywrightをMCPで接続しようとしたが、ずっとエラーでつながりませんでした。
n8nのログを調べると、 Could not connect to your MCP server としか書いていなくて、誰の問題かさっぱりわかりませんでした。

方法

Docker側の設定

まず調べてわかったのは、Docker Containerからホストマシンのポートを使うには、--add-host="host.docker.internal:host-gateway"とオプションつけるといいです。

そうすれば、DockerコンテナからホストPCへ接続できるようになります。例えばホストPCの localhost:3000 が、コンテナ内の host.docker.internal:3000 にマッピングされます。

もちろんホスト名の host.docker.internal は任意です。 my.docker.host とかもOKです。

Playwright側の設定

Docker側の設定が完了したら、一旦自作のMCPへのアクセスができました。しかしPlaywright MCPには依然にエラーで弾かれます。

それがPlaywright MCPはセキュリティー上、デフォルトは localhostからの接続のみ許可しているからです。

--allowed-hosts "host.docker.internal,host.docker.internal:8931" とオプションつけたら、ようやくDockerコンテナから接続できるようになりました。

スクリーンショット 2025-11-21 3.57.57.png

参考

3
1
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?