火曜日, 7月 15, 2025
火曜日, 7月 15, 2025
- Advertisment -
ホームニューステックニュースDocker MCP Gatewayがすんばらしい👌 #AmazonQDeveloper - Qiita

Docker MCP Gatewayがすんばらしい👌 #AmazonQDeveloper – Qiita



Docker MCP Gatewayがすんばらしい👌 #AmazonQDeveloper - Qiita

DockerのMCP Gatewayを試しました。

ゲートウェイです。はい。

通常、MCPサーバーを利用する場合はこのような構成になると思います。

image.png

MCPホスト(クライアントアプリケーション)が増えると、こうなりますよね?

image.png

ゲートウェイがあると、こうなります。

image.png

MCPサーバーはすべてDockerコンテナとして動作します。それぞれが隔離された環境で動作するので、ローカル環境への影響を最小限に抑えつつ、また、いろんな環境で同じように動作します。

個人的には、PythonやNodeのバージョン、uvx/npxなどのMCPサーバーごとに乱立する動作環境を統一できるのも好みです。

Docker MCP GatewayはリモートMCP(SSEやStreamable HTTP)にも対応していますので、複数のPCから接続することもできます。

image.png

なんだか、便利そうでしょ?

さっそく、やってみました。

やってみた。

Docker MCP Gatewayを使用する方法は2つあります。

  • Docker MCP Plugin
  • Dockerイメージ(docker/mcp-gateway

今回はDocker MCP Pluginを使う方法で試しました。
環境はUbuntuです。

Docker MCP Pluginをインストール

Docker Composeのように、Dockerのプラグイン形式で提供されています。
本日時点でバージョンv0.9.8のプレリリースです。

Shell

wget https://github.com/docker/mcp-gateway/releases/download/v0.9.8/docker-mcp-linux-amd64.tar.gz
tar zxvf docker-mcp-linux-amd64.tar.gz 
mkdir -p ~/.docker/cli-plugins
mv docker-mcp ~/.docker/cli-plugins
chmod +x ~/.docker/cli-plugins/docker-mcp 

Docker MCP Pluginのコマンドはdocker mcp サブコマンドとなります。

バージョン確認

MCPカタログを確認

Docker MCP Gatewayは、MCPカタログからMCPサーバーを取得する仕組みになっています。
デフォルトでDocker社提供のDocker MCP Catalogが登録済みです。

Docker MCP Catalog
hub.docker.com_mcp.png

docker-mcp: Docker MCP Catalog

MCPカタログに登録されているMCPサーバーを一覧表示します。
試した時点で、135個のMCPサーバーが登録されています。

Ref: Ref powerful search tool connets your coding tools with documentation context. It includes an up-to-date index of public documentation and it can ingest your private documentation (eg. GitHub repos, PDFs) as well.
SQLite: Database interaction and business intelligence capabilities.
astra-db: An MCP server for Astra DB workloads.
atlan-mcp-server: MCP server for interacting with Atlan services including asset search, updates, and lineage traversal for comprehensive data governance and discovery.
atlas-docs: Provide LLMs hosted, clean markdown documentation of libraries and frameworks.
...

MCPサーバーを有効化

試しにfetch MCPサーバーを有効化します。有効化すると、MCP Gatewayで使用可能になります。

Shell

docker mcp server enable fetch
# 無効化したい場合は docker mcp server disable fetch

有効化済みMCPサーバーを取得します。

MCPサーバーに含まれるツールを取得します。

1 tools:
 - fetch - Fetches a URL from the internet and optionally extracts its contents as markdown.

詳細情報を取得するinspectコマンドもあります。

Shell

docker mcp server inspect fetch

MCPクライアントから接続

MCP Gatewayをstdioで起動するコマンドはdocker mcp gateway runです。これをMCPクライアントに登録します。

例えばAmazon Q Developer CLIの場合はこのようになります。

Shell

q mcp add --name MCP_DOCKER --command docker --args mcp,gateway,run

他のMCPクライアントの場合はこんな感じの設定ファイルを記述することになると思います。

JSON

{
  "mcpServers": {
    "MCP_DOCKER": {
      "command": "docker",
      "args": [
        "mcp",
        "gateway",
        "run"
      ],
      "env": {}
    }
  }
}

Amazon Q Developer CLIでMCP Gatewayを経由してMCPサーバーを呼び出してみます。

✓ mcp_docker loaded in 1.56 s


    ⢠⣶⣶⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣶⣿⣿⣿⣶⣦⡀⠀
 ⠀⠀⠀⣾⡿⢻⣿⡆⠀⠀⠀⢀⣄⡄⢀⣠⣤⣤⡀⢀⣠⣤⣤⡀⠀⠀⢀⣠⣤⣤⣤⣄⠀⠀⢀⣤⣤⣤⣤⣤⣤⡀⠀⠀⣀⣤⣤⣤⣀⠀⠀⠀⢠⣤⡀⣀⣤⣤⣄⡀⠀⠀⠀⠀⠀⠀⢠⣿⣿⠋⠀⠀⠀⠙⣿⣿⡆
 ⠀⠀⣼⣿⠇⠀⣿⣿⡄⠀⠀⢸⣿⣿⠛⠉⠻⣿⣿⠛⠉⠛⣿⣿⠀⠀⠘⠛⠉⠉⠻⣿⣧⠀⠈⠛⠛⠛⣻⣿⡿⠀⢀⣾⣿⠛⠉⠻⣿⣷⡀⠀⢸⣿⡟⠛⠉⢻⣿⣷⠀⠀⠀⠀⠀⠀⣼⣿⡏⠀⠀⠀⠀⠀⢸⣿⣿
 ⠀⢰⣿⣿⣤⣤⣼⣿⣷⠀⠀⢸⣿⣿⠀⠀⠀⣿⣿⠀⠀⠀⣿⣿⠀⠀⢀⣴⣶⣶⣶⣿⣿⠀⠀⠀⣠⣾⡿⠋⠀⠀⢸⣿⣿⠀⠀⠀⣿⣿⡇⠀⢸⣿⡇⠀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⢹⣿⣇⠀⠀⠀⠀⠀⢸⣿⡿
 ⢀⣿⣿⠋⠉⠉⠉⢻⣿⣇⠀⢸⣿⣿⠀⠀⠀⣿⣿⠀⠀⠀⣿⣿⠀⠀⣿⣿⡀⠀⣠⣿⣿⠀⢀⣴⣿⣋⣀⣀⣀⡀⠘⣿⣿⣄⣀⣠⣿⣿⠃⠀⢸⣿⡇⠀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠈⢿⣿⣦⣀⣀⣀⣴⣿⡿⠃
 ⠚⠛⠋⠀⠀⠀⠀⠘⠛⠛⠀⠘⠛⠛⠀⠀⠀⠛⠛⠀⠀⠀⠛⠛⠀⠀⠙⠻⠿⠟⠋⠛⠛⠀⠘⠛⠛⠛⠛⠛⠛⠃⠀⠈⠛⠿⠿⠿⠛⠁⠀⠀⠘⠛⠃⠀⠀⠘⠛⠛⠀⠀⠀⠀⠀⠀⠀⠀⠙⠛⠿⢿⣿⣿⣋⠀⠀
 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠿⢿⡧

╭─────────────────────────────── Did you know? ────────────────────────────────╮
│                                                                              │
│        Run /prompts to learn how to build & run repeatable workflows         │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯

/help all commands  •  ctrl + j new lines  •  ctrl + s fuzzy search
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🤖 You are chatting with claude-4-sonnet

MCPコマンドを実行してみます。

mcp_docker
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
✓ mcp_docker loaded in 1.56 s

TOOLSコマンドを実行してみます。

mcp_dockerというMCPサーバーとして認識され、fetchツールが存在することが確認できます。

Tool                    Permission
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔Built-in:
- execute_bash          * trust read-only commands
- fs_read               * trusted
- fs_write              * not trusted
- report_issue          * trusted
- use_aws               * trust read-only commands

mcp_docker (MCP):
- mcp_docker___fetch    * not trusted


Trusted tools will run without confirmation.
* Default settings

💡 Use /tools help to edit permissions.

fetchツールを呼び出してみます。

Shell

> www.yahoo.co.jpをfetchして
> I'll fetch the Yahoo Japan website for you using the available fetch tool.


🛠️  Using tool: fetch from mcp server mcp_docker
 ⋮ 
 ● Running fetch with the param:
 ⋮  {
 ⋮    "arguments": {
 ⋮      "url": "https://www.yahoo.co.jp"
 ⋮    },
 ⋮    "name": "fetch"
 ⋮  }

Allow this action? Use 't' to trust (always allow) this tool for the session. [y/n/t]:

うまく呼び出せました。

その他もろもろやってみた

2つ目のMCPサーバーを追加

MCP Gatewayに複数のMCPサーバーを登録できるので、fetchに加えてTavilyを追加(有効化)します。

docker mcp server enable tavily

ツールが増えたことを確認します。

5 tools:
 - fetch - Fetches a URL from the internet and optionally extracts its contents as markdown.
 - tavily-crawl - A powerful web crawler that initiates a structured web crawl starting from a specified base URL.
 - tavily-extract - A powerful web content extraction tool that retrieves and processes raw content from specified URLs, ideal for data collection, content analysis, and research tasks.
 - tavily-map - A powerful web mapping tool that creates a structured map of website URLs, allowing you to discover and analyze site structure, content organization, and navigation paths.
 - tavily-search - A powerful web search tool that provides comprehensive, real-time results using Tavily's AI search engine.

APIキーを環境変数で指定する

Tavily MCPサーバーの動作にはAPIキーが必要で、通常は環境変数TAVILY_API_KEYで指定します。

ただ、MCPカタログで公開されているTavily MCPサーバーの場合、微妙に環境変数のキー名が異なります。

正しい環境変数のキー名は、MCPカタログのサイトで公開されているTavilyのページで確認できます。

Configタブに、Secretsとして、tavily.api_tokenを使用すると載っています。
(こんなんだれがわかんねん。。)

hub.docker.com_mcp_server_tavily_overview.png

.envファイルにtavily.api_token=tvly-*****の書式で記述し、このファイルをdocker mcp gateway runコマンドのパラメーター--secretsとして渡します。これで無事、Tavily MCPサーバーにAPIキーを渡すことができます。

{
    "mcpServers": {
        "MCP_DOCKER": {
        "command": "docker",
        "args": [
            "mcp",
            "gateway",
            "run",
            "--secrets",
            "./.env"
        ],
        "env": {}
        }
    }
}

Docker Desktopを使用している場合は、docker mcp secretsコマンドが利用できます。このコマンドは、Docker Desktopのシークレット管理機能と連携し認証情報のやり取りができるようです。(未確認)

MCPサーバーのツールの一部を有効にする

さて、Tavily MCPサーバーには4つのツールが含まれていますが、この内一つだけを使用したいとします。
そんな場合は、--toolsパラメーターを使用します。

以下の例は、fetch MCPサーバーの全ツールと、Tavily MCPサーバーのtavily-searchだけを有効にする例です。

{
    "mcpServers": {
        "MCP_DOCKER": {
        "command": "docker",
        "args": [
            "mcp",
            "gateway",
            "run",
            "--secrets",
            "./.env",
            "--tools",
            "fetch:*",
            "--tools",
            "tavily:tavily-search"
        ],
        "env": {}
        }
    }
}

リモートMCP

トランスポート(ssestreaming)とポート番号を指定することで、リモートMCPサーバーとして起動することができます。

Shell

docker mcp gateway run --transport streaming --port 8080

独自のMCPカタログを作る

Docker社が提供するMCPカタログに未登録のMCPサーバーを使用したい場合は、独自のMCPカタログを作成することができます。

Yamlファイルを作成し、MCPサーバーの情報を記述します。(ファイル名は何でもいいです)

以下の例では、Docker Hubなどには登録のない、ローカル環境にだけ存在するmy-fetchを指定する例です。

my-catalog.yaml

version: 2
name: my-mcp-catalog
displayName: My MCP Catalog
registry: 
  myfetch:
    description: My Fetches a URL from the internet and extracts its contents as markdown.
    title: My Fetch (Reference)
    type: server
    image: my-fetch

この設定ファイルを--catalogパラメーターで指定することで、独自のMCPカタログを参照できます。

Shell

docker mcp gateway run --catalog ./my-mcp-catalog.yaml --servers myfetch

まとめ

まだプレリリースなので、微妙に整っていないところがあるように思いますが、ゲートウェイの構成自体は、私は好みです。
また、副産物として、stdioでしか提供されていないMCPサーバーも、MCPゲートウェイを経由することでリモートMCP化ができます。開発チームで一つMCPゲートウェイを用意し、みんなで同じMCPサーバーを使うとか、ありな気がします。





Source link

Views: 0

RELATED ARTICLES

返事を書く

あなたのコメントを入力してください。
ここにあなたの名前を入力してください

- Advertisment -