MCP Servers with Meshagent
Purpose: This guide shows you how to take any Model‑Context Protocol (MCP) server image and “wrap” it with Meshagent so the server can be launched as a service inside a Meshagent Room and then accessed by agents, chatbots, or external callers.
1. Why Wrap an MCP Image?
Meshagent Rooms are collaborative sandboxes where multiple AI agents (and humans) share toolkits—self‑contained HTTP services that expose standardized JSON tools. An MCP server already implements the toolkit spec, but it lacks the Room‑level plumbing:
Layer | What It Adds |
---|---|
MCP Base Image | Implements your domain logic and OpenAPI spec |
Meshagent Wrapper | • Starts Meshagent’s mcp stdio-service |
• Proxies HTTP ↔ stdin/stdout | |
• Handles Room auth, health, logging |
Wrapping therefore lets any MCP server be hot‑plugged into a Room with zero application changes.
2. High‑Level Workflow
- Pick a base: e.g.
mcp/3d-printer
from Docker Hub. - Write a one‑page Dockerfile (see §3).
- Build & tag:
docker build -t meshagent/mcp-3d-printer:latest .
. - Push to a registry Meshagent can pull from.
- Launch with
meshagent service
. - Interact via chatbot or API.
3. Reference Dockerfile
Key points
meshagent mcp stdio-service
converts stdin/stdout ↔ HTTP.--path=/webhook
is Meshagent’s default webhook path for MCP traffic.- The wrapper stays thin—no changes to the underlying server code.
4. Build & Push
:::tip Private registries If you use a private registry, configure a Meshagent Pull Secret so the Room can fetch the image. :::
5. Launching in a Room
--room
creates (or re‑uses) a named Room.--port
maps container port 8000 to a callable toolkit endpoint within the Room.- After a few seconds the toolkit appears in the Room UI and via API.
6. Interacting from an Agent
The chatbot (or any agent SDK) can now call the MCP tools—e.g. print_3d_model
, list_printers
, etc.—through standard Meshagent JSON‑RPC messages.
7. Debugging & Logs
Symptom | Fix |
---|---|
Toolkit never appears | • Check meshagent service ... logs for image‑pull errors |
• Verify --port path matches --path in Dockerfile | |
HTTP 404 on /webhook | Confirm --path flag in ENTRYPOINT and --port ... path= agree |
Permission errors | Make sure you switched back to USER user after root installs |
Broken pip | Add RUN apk add gcc musl-dev if native wheels need compiling |
8. Best Practices
- Pin Meshagent version (
ARG MESHAGENT_VERSION
) to avoid surprises. - Keep wrapper lean—no extra packages beyond Python & Meshagent.
- Use non‑root user for runtime security.
- Expose health endpoints (
liveness=/
) for production Rooms. - Document env vars (
README.md
, labels) so users know what to set. - Automate builds with CI to push
:latest
and semver tags.
9. Further Reading
- Meshagent CLI Getting Started: https://docs.meshagent.com/cli/getting_started
- Meshagent StdIO Service spec: https://docs.meshagent.com/agents/standard/intro
- Meshagent Room API: https://docs.meshagent.com/room_api/overview
- Example Brave Search Toolkit: https://hub.docker.com/r/meshagent/mcp-brave-search
- MCP Server Template repo: https://github.com/modelcontextprotocol/servers
Quick‑Reference Checklist
- MCP base image chosen
-
PARENT_ENTRYPOINT
set -
MESHAGENT_PORT
exposed - Meshagent installed in venv
- ENTRYPOINT execs
meshagent mcp stdio-service
- Image built & pushed to registry
- Service launched with
meshagent service ...
- Toolkit visible in Room
Happy wrapping!