DEV Community

Cover image for Docker AI Agent and Model Context Protocol (MCP) Server - Working Together
Ajeet Singh Raina
Ajeet Singh Raina

Posted on

Docker AI Agent and Model Context Protocol (MCP) Server - Working Together

You might wonder "What does Docker Desktop have to do with AI?" The answer lies in Ask Gordon, an innovative AI-powered assistant that's now integrated into both Docker Desktop and the Docker CLI. This integration represents a significant step forward in making the Docker ecosystem more accessible and efficient for developers.

What is Ask Gordon?

Image2

Ask Gordon is an AI assistant designed to streamline your Docker workflow by providing contextual assistance tailored to your local environment. Currently in Beta and available in Docker Desktop version 4.38.0 or later, Ask Gordon offers intelligent support for various Docker-related tasks.

Key Capabilities

docker-ai

Ask Gordon excels at:

  • Analyzing and troubleshooting crashed containers by examining logs and configurations
  • Providing guidance on container runtime configurations and best practices
  • Reviewing and suggesting improvements for Dockerfile optimization
  • Performing security assessments to identify potential vulnerabilities
  • Offering contextual recommendations based on your specific Docker environment

Understanding Model Context Protocol (MCP)

Model Context Protocol (MCP) is an open protocol introduced by Anthropic. It standardises how applications provide context to large language models. MCP functions as a client-server protocol, where the client (e.g., an application like Gordon) sends requests, and the server processes those requests to deliver the necessary context to the AI.

Gordon, along with other MCP clients like Claude Desktop, can interact with MCP servers running as containers. Docker has partnered with Anthropic to build container images for the reference implementations of MCP servers, available on Docker Hub under the mcp namespace.

The Model Context Protocol (MCP) is what enables Ask Gordon to understand and interact with your Docker environment effectively. When you use the docker ai command, Gordon looks for a gordon-mcp.yml file in your working directory. This file, essentially a Docker Compose configuration, defines which MCP servers Gordon should access in your current context.

Step-by-Step Setup Guide

To enable Model Context Protocol (MCP) for Ask Gordon in Docker Desktop, follow these steps:

enableai

  • Open Docker Desktop Settings
  • Navigate to "Features in development"
  • Check the "Enable Docker AI" checkbox
  • Accept the Docker AI terms of service
  • Apply the changes and restart Docker Desktop

Gordon goes YAM[A]L !!

Image2

Create a gordon-mcp.yml file in your working directory.
This file is a Docker Compose file that configures MCP servers for Gordon to access.

Add the desired MCP servers to your gordon-mcp.yml file. For example, to add the time server:

services:
  time:
    image: mcp/time
Enter fullscreen mode Exit fullscreen mode

You can now use the docker ai command in your terminal to interact with Gordon, and it will utilize the MCP servers specified in your gordon-mcp.yml file.

Testing the MCP Server

Now that you've added the mcp/time server to your gordon-mcp.yml file, you can ask Gordon time-related questions. Here's an example query you can run:

$ docker ai 'what time is it now in Tokyo?'
Enter fullscreen mode Exit fullscreen mode

You'll know that Gordon is using MCP when you see output indicating that it's calling the MCP server's tools. For example, you might see something like this in the response:

Calling get_current_time ✔️

  The current time in Tokyo is 10:18 AM on February 14, 2025.
Enter fullscreen mode Exit fullscreen mode

The "Calling get_current_time" line clearly shows that Gordon is utilizing the MCP server to answer the time-related question. This is how you can confirm that Gordon is indeed using the MCP capabilities you've enabled.

Using Postgres MCP Server

Let's start a Postgres container

$ docker run -d --name postgres2 -e POSTGRES_PASSWORD=dev -p 5433:5432 postgres:13
Enter fullscreen mode Exit fullscreen mode

Ensuring that Postgres container is up and running:

docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS                                                      NAMES
e671ed72e739   postgres:13    "docker-entrypoint.s…"   26 seconds ago   Up 24 seconds   0.0.0.0:5433->5432/tcp 
Enter fullscreen mode Exit fullscreen mode

Enter into Postgres database container with the following command:

psql -U postgres
Enter fullscreen mode Exit fullscreen mode

Let's create some dummy tables that includes users, orders and Products:

-- Create a table for Users
CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    email VARCHAR(100) UNIQUE NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Create a table for Orders
CREATE TABLE orders (
    id SERIAL PRIMARY KEY,
    user_id INT REFERENCES users(id) ON DELETE CASCADE,
    product_name VARCHAR(100) NOT NULL,
    price DECIMAL(10,2) NOT NULL,
    order_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Create a table for Products
CREATE TABLE products (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    description TEXT,
    price DECIMAL(10,2) NOT NULL,
    stock INT NOT NULL DEFAULT 0
);
Enter fullscreen mode Exit fullscreen mode

Let's see how Ask Gordon can interact with the underlying Postgres database container running on my Docker Desktop. Modify the gordon-mcp.yml file with the postgres entry:

services:
  time:
    image: mcp/time

  postgres:
    image: mcp/postgres
    command: postgresql://postgres:dev@host.docker.internal:5433/postgres
Enter fullscreen mode Exit fullscreen mode

Interacting with Gordon

docker ai "Run a SQL query to show me the version of PostgreSQL"

    • Calling query ✔️

  The version of PostgreSQL is:

  PostgreSQL 13.19 (Debian 13.19-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 
  12.2.0-14) 12.2.0, 64-bit
Enter fullscreen mode Exit fullscreen mode

If it's working, you should see something like "Calling query" in the response.

Note: The mcp/postgres Docker Hub page mentions that this server provides read-only access to PostgreSQL databases, so make sure you're only trying to perform read operations.

docker ai "show me the list of tables in my postgres"

    • Calling query ✔️

  Here is the list of tables in your PostgreSQL database:

    1. users
    2. orders
    3. products
Enter fullscreen mode Exit fullscreen mode

Conclusion

Enabling the Model Context Protocol Server for Ask Gordon in Docker Desktop represents a significant step toward more intelligent Docker tooling. By following this guide, you've unlocked a powerful AI assistant that can help streamline your Docker workflow and improve your development experience.

Top comments (0)