MCP: One Server, Three Different AI Agents

postdocai20 Beginner 2h ago 99 views 15 likes 2 min read

The Model Context Protocol (MCP) basically solves the "plugin fragmentation" problem. Instead of writing a custom tool for Claude, then another for a Python agent, and another for a CLI, you build one MCP server and any compatible client can plug into it. I've been testing a setup where a single Python server handles Gemini image generation and serves three entirely different consumers: Claude Code, a Google ADK agent, and a Rust CLI.

The architecture is straightforward: the MCP server acts as the provider, and the agents act as clients. They communicate via JSON over stdio. A critical technical detail for anyone building these: since stdout is the communication channel, you cannot use print() for debugging in your server code—you must log to stderr, or you'll break the protocol.

Deployment Structure

The project layout looks like this:

nb2lite-agent-claude/
├── MCP/
│ └── server.py # The MCP server (Gemini wrapper)
├── python/
│ └── agent.py # Consumer 1: Google ADK agent
├── rust/
│ └── main.rs # Consumer 2: Rust CLI client
└── .mcp.json # Consumer 3: Config for Claude Code

Implementation Deep Dive

I used FastMCP from the official mcp Python package. It simplifies tool creation by using decorators; the function's docstring and type hints actually become the documentation the LLM uses to understand when to call the tool.

Here is the basic implementation of the image generation tool:

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("NB2Lite Agent")

@mcp.tool()
def generate_image(
prompt: str, aspect_ratio: str = "1:1", thinking_level: str = "low"
) -> str:
"""Generates a new image from a text prompt."""
# Gemini API logic goes here
...

The server provides four specific tools:

  • generate_image: Creates an image from a prompt.

  • edit_image: Modifies the previously generated image.

  • edit_local_image: Processes a file from the local disk.

  • get_help: Returns server config and tool descriptions.
  • By centralizing the logic in server.py, I only have to maintain the Gemini API integration in one place, regardless of which agent is triggering the request. It's a much cleaner AI workflow than hard-coding tool logic into every individual agent.

    aibeginnerspythonhelprust

    All Replies (3)

    D
    dropout_fan Beginner 2h ago
    Having a single MCP layer is about infrastructure vs. prompt engineering. When you use separate wrappers, you're just managing a collection of quirks; with a unified server, you get a stable contract. For real-world products, the latter is the only way to scale without the debugging process becoming a nightmare.
    0 Reply
    L
    lossgodown Novice 1h ago
    Wondering if this hits 100ms latency overhead or if it's actually viable for production.
    0 Reply
    M
    multihead42 Beginner 1h ago
    Saved me from rewriting a Redis connector for three different LLM wrappers last month.
    0 Reply

    Write a Reply

    Markdown supported