AI & ML DevOps

Understanding MCP — The Bridge Between AI and the Outside World

Understanding MCP — The Bridge Between AI and the Outside World

I've previously shared about MCP (Model Context Protocol)—a standard conversation protocol. It lets AI models (LLMs) speak with external tools and data sources in the same way. Previously, connecting AI to Google Drive meant writing one integration; connecting to Notion meant writing another. Now with MCP, as long as everyone follows this protocol, AI can easily connect to anything.

This article skips complex theory and cuts straight to the point: understanding how MCP works and building one yourself!

Core Architecture: Host vs. Client vs. Server

To understand MCP, first distinguish its three core roles: Host, Client, and Server.

1. Host (Main Application)

Who is the Host?

Simply put, the Host is the application you directly interact with. It's the AI's "interface."

What does it do?

The Host displays AI responses and receives your input. Crucially, it decides when to call external tools and passes that instruction to the internal Client.

Examples:
* Claude Desktop
* Cursor (the AI IDE)
* VS Code (with Copilot)
* Your own Python script (if it runs an LLM and calls tools)

2. Client (Client Instance)

Who is the Client?

The Client is a module embedded inside the Host—think of it as the Host's "communications officer."

What does it do?

The Client handles "handshakes" and "message passing." When the Host needs a tool (like reading Google Drive files), the Client connects to the corresponding MCP Server, sends instructions, and passes Server responses back. A Host can open multiple Clients connecting to different Servers.

3. Server (Server)

Who is the Server?

The Server actually provides tools or data. It's like the AI's "toolbox" or "library."

What does it do?

The Server defines several capabilities (in MCP terminology: Resources, Prompts, and Tools). When receiving Client instructions, it executes corresponding actions (fetching Google Drive files, running Python code, searching the web) and returns results.

Examples:
* Hugging Face MCP Server (search models, papers)
* Google Drive MCP Server (access files)
* Jupyter MCP Server (let AI code in your Jupyter environment)
* Custom Servers built with FastMCP

Transport Channels: STDIO vs. SSE

How does the Host's Client communicate with the Server? Via Transport channels. The two most common are STDIO and SSE—completely different use cases.

1. STDIO (Standard Input/Output)

The most intuitive, standard connection method—typically for Host and Server running on the same machine.

  • How it works:

The Host (like Claude Desktop) launches the Server executable (or Docker container) as a subprocess. It sends JSON instructions via stdin and reads responses from Server's stdout.

  • Advantages:

  • No network setup: No IP, no port—connection is ultra-simple.

  • Excellent performance: Local process communication; negligible latency.
  • Synchronized lifecycle: When Host closes, Server process auto-closes; no lingering processes.

  • Disadvantages:

  • Can only connect to Servers on your own machine.

2. SSE (Server-Sent Events)

For connecting to remote Servers (in cloud or on NAS), use SSE.

  • How it works:

Based on standard HTTP web technology. The Client first handshakes with Server, then Server opens a persistent HTTP stream. Server can proactively push updated data through the stream.

  • Advantages:

  • Remote connection support: Server can be anywhere networked.

  • Multi-client: One Server serves many Clients simultaneously.

  • Disadvantages:

  • Complex setup: handling networks, firewalls, port forwarding, authentication.

Hands-On Practice

Theory's one thing; building's another. Here are two simple implementation examples.

1. FastMCP: Build and Dockerize an MCP Server

Example using Python's FastMCP library, packaged as Docker. We use Docker's -i (interactive) flag so the container's Server communicates with the Host via STDIO.

Step A: Write a simple my_server.py

from fastmcp import FastMCP

# Create a FastMCP instance
mcp = FastMCP("My Cool Server")

# Define a simple tool: addition
@mcp.tool()
async def add_numbers(a: int, b: int) -> int:
    """Add two numbers together."""
    return a + b

if __name__ == "__main__":
    # Start Server in stdio mode
    mcp.run(transport="stdio")

Step B: Write a Dockerfile

FROM python:3.11-slim

# Set working directory
WORKDIR /app

# Install FastMCP library
RUN pip install --no-cache-dir fastmcp

# Copy code into container
COPY my_server.py .

# Default startup command
ENTRYPOINT ["python", "my_server.py"]

Step C: Build and launch container (Host side)

In your terminal, build the Docker image:

docker build -t my-mcp-server .

Then configure in your MCP config file (e.g., claude_desktop_config.json):

"mcpServers": {
  "my-docker-server": {
    "command": "docker",
    "args": ["run", "-i", "--rm", "my-mcp-server:latest"]
  }
}

Now Claude launches the container and connects via stdio.

2. Jupyter STDIO: Let AI Control Your Local Jupyter

If you want Claude Desktop controlling your computer's Jupyter for data analysis, use jupyter-mcp-server.

Step A: Install package

In terminal:

# If installing in Python environment
pip install jupyter-mcp-server

# Or with uv, directly run
uvx --install jupyter-mcp-server

Step B: Configure in Host config (using STDIO)

In your MCP config file (e.g., claude_desktop_config.json):

"mcpServers": {
  "my-jupyter": {
    "command": "jupyter-mcp-server",
    "args": []
  }
}

Now you understand Host, Client, Server, and transport channels. Whether using existing Servers or building custom ones, MCP opens infinite possibilities for AI agents. Go try it!

Comments

Loading comments…

Leave a Comment