Skip to content

Build Smart Agents with Docker MCP Server Toolkit & PydanticAI

Published: at 04:00 PM
Author: Sebastian Talamoni

As a developer, there are countless combinations available for building AI agents. From a wide array of agent frameworks to the temptation of using big-tech proprietary solutions, the choices can be overwhelming. My goal was to find a combination that truly fits the needs I’ve encountered in real projects. After several experiments, I found that this particular stack works remarkably well.

Build Smart Agents with Docker MCP Server & PydanticAI

Building intelligent agents is easier and faster than ever by combining the power of the MCP Toolkit for Docker Desktop with the flexibility of PydanticAI. This article provides a concise, high-quality guide to get you started quickly.

Definitions

What is the MCP Toolkit?

The Docker MCP Toolkit is a built-in feature of Docker Desktop that enables seamless setup, management, and execution of containerized MCP servers and their connections to AI agents. It removes friction from tool usage by offering secure defaults, one-click setup, and support for a growing ecosystem of LLM-based clients. Key features include:

Why Use the MCP Toolkit?

What is PydanticAI?

PydanticAI is a Python framework that combines AI agent capabilities with Pydantic’s powerful data validation and type management system. It provides a structured approach to building robust AI applications by:

This simplifies developing and maintaining robust, production-ready AI agents characterized by predictable behavior, strong data integrity, ease of integration, and a highly extensible ecosystem of tools and services.


Quickstart

This article assumes you have already Docker Desktop installed and using latest version. The MCP Toolkit was a Beta feature a month ago.

1. Enable the MCP Toolkit

  1. Open Docker Desktop and go to “Extensions”
  2. Search and install Docker MCP Toolkit alt text

2. Install an MCP Server

  1. In Docker Desktop, open the MCP Toolkit from the sidebar.
  2. Go to the Catalog tab to browse available MCP servers.
  3. Turn on (checkbox) to add a server (e.g., DuckDuckGo, Slack, Discord, Web API, etc.). In my example I have enabled DuckDuckGo .
  4. If required, configure the server in the Config tab (e.g., add tokens or credentials).

DockerMCPToolKit image

Example: Use the DuckDuckGo MCP Server

  1. In the Catalog, find the DuckDuckGo server and add it.
  2. If needed, configure the server in the Config tab. ( DuckDuckGo has no extra config)
  3. In the Clients tab, ensure your preferred client (e.g., Claude Desktop) is connected. In our example we will be using this server from python code and connecting to PydanticAI so keep reading.
  4. You can now send search or information requests to DuckDuckGo through your client, powered by the MCP server.

3. Define Your Agent with PydanticAI

Create a Python file for your agent. Even tough the usage of schemas is optional, to me is quite important feature, so i am including in article. Use Pydantic to define the input/output schemas:

Defining Rich Agent Schemas with Pydantic

Pydantic allows you to define complex, type-safe schemas for your agent’s inputs and outputs. This ensures that all data exchanged with your agent is validated at runtime, catching errors early and making your code more robust. Below is a more realistic example:

from pydantic import BaseModel, Field
from typing import List, Optional

class AgentInput(BaseModel):
    crop: str = Field(..., description="The crop to analyze, e.g. 'wheat'")
    location: str = Field(..., description="Geographical location, e.g. 'Iowa, USA'")
    planting_dates: List[str] = Field(..., description="List of possible planting dates")
    soil_ph: Optional[float] = Field(None, description="Measured soil pH value")

class AgentOutput(BaseModel):
    recommended_date: str
    expected_yield: float
    notes: Optional[str]

How Pydantic Validation Works:

For example, if you try to create an AgentInput without a crop or with a non-numeric soil_ph, Pydantic will immediately raise an error, ensuring only valid data reaches your agent logic.

4. Registering with PydanticAI

Below is a practical example of how to connect your Python agent to an MCP server running in Docker. This approach uses the MCPServerStdio class to bridge your agent with the Dockerized MCP server, and demonstrates how to securely load your OpenAI API key from environment variables:


server = MCPServerStdio(
    "docker",
    args=["run", "-i", "--rm", "alpine/socat", "STDIO", "TCP:host.docker.internal:8811"]
)

agent = Agent(
    model="openai:gpt-4.1-mini",
    mcp_servers=[server],
    input_schema=AgentInput,
    output_schema=AgentOutput,
    system_prompt='Be a helpful agent that can answer questions about agriculture and crop planting.'
)

This code snippet demonstrates how to:

This pattern allows you to flexibly connect your smart agent to any MCP server running in Docker, making it easy to experiment and scale with different MCP servers.

Examples of MCP Servers which you can use with 1 click

For the full and up-to-date list of available MCP servers, visit the official Docker MCP Catalog.

The MCP Toolkit supports a variety of MCP servers, making it easy to connect your smart agents to popular platforms and services. Here are five examples you can experiment with:

  1. DuckDuckGo MCP Server
    Create agents that leverage DuckDuckGo search for information retrieval and knowledge-based tasks.
  2. Slack MCP Server
    Build agents that interact with Slack channels for notifications, chatbots, and workflow automation.
  3. Discord MCP Server
    Deploy agents to manage Discord communities, moderate content, or provide real-time information.
  4. GitHub MCP Server
    Integrate agents with GitHub to automate repository management, issue tracking, and code reviews.
  5. Web API MCP Server
    Connect agents to any web API, enabling integration with countless online services and data sources.

These servers can be easily managed and deployed through the MCP Toolkit UI, allowing you to quickly prototype and scale your smart agent solutions.

Conclusion

By combining the MCP Toolkit for Docker Desktop with PydanticAI, you can rapidly prototype, validate, and deploy smart agents that have already existing tool requirements. This approach ensures reliability, scalability, and developer productivity.

Sources and further information


Next Post
Rethinking software tests: grouping by IO vs Not IO in Hexagonal Architecture