5 Best Practices for Building, Testing, and Packaging MCP Servers
MCP servers work best when designed around the agent as the real caller: keep a small "tool budget" by grouping endpoints into use-case tools and prompts instead of one tool per API endpoint, and return error messages that tell the agent what to fix (e.g., an invalid API_TOKEN configuration) rather than human-facing denials. Tool names and descriptions double as documentation for agents, while user docs explain the value. Test the connect, list-tools and tool-call lifecycle with the MCP Inspector or `docker mcp` commands, and open connections per tool call rather than at startup so tools can be listed even when the server is misconfigured. Package servers as Docker images using stdio transport for submission to the Docker MCP Catalog.
Related posts
- Dynamic MCPs with Docker: Stop Hardcoding Your Agents’ World
Docker mediumAdeptDocker MCP Gateway now exposes primordial tools (mcp-find, mcp-add) that let agents search a curated catalog of 270+ MCP servers, add them to the live session, and trigger OAuth or elicitation flows, instead of hand-editing JSON config and restarting. The gateway can also hide added servers' tool definitions from tools/list so they stay discoverable without bloating the context window. A code-mode tool lets agents write JavaScript that composes tools from several MCP servers inside a Docker sandbox, keeping intermediate results out of the model and cutting per-turn token usage. The features ship in Docker Desktop 4.50 and are on by default, and cagent can expose such agents to ACP-enabled editors like Zed and Neovim.
- MCP Security: A Developer’s Guide
Docker easyNoviceMCP servers expand what AI agents can do but introduce risks across four categories: misconfigurations and weak defaults, malicious or compromised servers, secret leakage, and prompt injection or tool poisoning. One cited analysis found command injection flaws in 43% of MCP servers examined. Static AppSec tools miss these risks because agent behavior is non-deterministic and models can treat tool descriptions as instructions. The recommended guardrails are to containerize each server with resource and egress limits, route calls through a policy gateway that verifies signatures, enforces allowlists, redacts secrets, runs pre- and post-call interceptors and logs every call, and pin vetted servers by digest. Docker positions its MCP Gateway and MCP Catalog & Toolkit as the implementation.
- Designing MCP tools for agents: Lessons from building Datadog’s MCP server
Datadog Engineering mediumAdeptThin API wrappers make poor MCP tools: agents flood their context windows, blow token budgets on oversized records, and infer trends from raw samples. Datadog's MCP server fixes this with token-efficient formats (CSV/TSV for flat data, YAML for nested), trimmed default fields, and pagination by token budget instead of record count, fitting about 5x more records per token. It also exposes a SQL query interface over logs, which made eval runs about 40% cheaper. Other lessons: keep tool count low with flexible tools, opt-in toolsets or layering; return specific, actionable error messages; offer a RAG docs-search tool; and include guidance hints in tool results.
- Using MCP Servers: From Quick Tools to Multi-Agent Systems
Docker easyNoviceContainerizing MCP servers addresses three practical problems: language runtime sprawl, secret injection, and N×N client-to-server wiring. Three integration paths are laid out in order of complexity: Docker's MCP Toolkit and Catalog for one-click containerized servers wired to clients like Claude Desktop or VS Code, cagent for declarative YAML-defined multi-agent systems with per-agent tool scoping, and code-first frameworks like LangGraph, CrewAI or ADK for full orchestration control. All three route through the open-source MCP Gateway, which centralizes routing, authentication and a single endpoint, and a comparison table maps each option to who it suits and what you manage.
- Securing Model Context Protocol: Safer Agentic AI with Containers
Docker easyNoviceRunning MCP servers via npx on the host with plaintext environment-variable secrets leaves agentic tooling exposed to supply-chain tampering, credential leakage, and attacks such as rug pulls, tool shadowing, and tool poisoning. Containers address part of this through isolation, reproducibility, and verifiable provenance. They should be paired with scoped secret injection, a single MCP Gateway that screens all server-to-client traffic, and separate policies for which servers are trusted versus which a given agent needs. Tool annotations like readOnlyHint and destructiveHint can be enforced at container runtime, and Docker's MCP Catalog and Toolkit package these ideas behind one socat-over-STDIO connection.