---
title: "5 Best Practices for Building, Testing, and Packaging MCP Servers"
description: "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."
url: "https://swe.quest/articles/5-best-practices-for-building-testing-and-packaging-mcp-servers-156585fac07369be"
canonical: "https://www.docker.com/blog/mcp-server-best-practices/"
source: "Docker"
published: "2025-07-03"
difficulty: "medium"
kind: "How-to"
reading_minutes: 7
tags: ["ai-agents","containers","api-design","testing"]
---

# 5 Best Practices for Building, Testing, and Packaging MCP Servers

A post on [Docker](https://swe.quest/sources/docker.md), published 2025-07-03, 7 min read, How-to. Original: [https://www.docker.com/blog/mcp-server-best-practices/](https://www.docker.com/blog/mcp-server-best-practices/)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [AI agents](https://swe.quest/tags/ai-agents.md) (AI & ML)
- [Containers](https://swe.quest/tags/containers.md) (Infrastructure)
- [API design](https://swe.quest/tags/api-design.md) (Backend & APIs)
- [Testing](https://swe.quest/tags/testing.md) (Engineering practices)

## Prerequisites

- Model Context Protocol basics
- Docker images ([easy posts on Containers](https://swe.quest/tags/containers.md?difficulty=easy))

## Keywords

Model Context Protocol, Docker MCP Catalog, MCP Inspector, Docker MCP Toolkit, Gordon

## Related posts

- [Dynamic MCPs with Docker: Stop Hardcoding Your Agents’ World](https://swe.quest/articles/dynamic-mcps-with-docker-stop-hardcoding-your-agents-world-a530a7120388ea63.md): Docker · 2025-11-06 · Medium · 11 min read · AI agents, LLMs, Sandboxing & isolation, Containers, Developer tools
  Docker 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.
- [MCP Security: A Developer’s Guide](https://swe.quest/articles/mcp-security-a-developer-s-guide-ee8f7d25fd64b2f2.md): Docker · 2025-09-16 · Easy · 8 min read · AI agents, Security, Supply chain security, Containers
  MCP 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.
- [Designing MCP tools for agents: Lessons from building Datadog’s MCP server](https://swe.quest/articles/designing-mcp-tools-for-agents-lessons-from-building-datadog-s-mcp-server-d09621598f568627.md): Datadog Engineering · 2026-03-04 · Medium · 8 min read · AI agents, API design, LLMs, Observability
  Thin API wrappers make poor MCP tools: agents flood their context windows, blow token budgets on oversized records, and infer trends from raw samples.
- [Using MCP Servers: From Quick Tools to Multi-Agent Systems](https://swe.quest/articles/using-mcp-servers-from-quick-tools-to-multi-agent-systems-25a421c78bb6b492.md): Docker · 2026-01-22 · Easy · 6 min read · AI agents, Containers, LLMs
  Containerizing MCP servers addresses three practical problems: language runtime sprawl, secret injection, and N×N client-to-server wiring.
- [Securing Model Context Protocol: Safer Agentic AI with Containers](https://swe.quest/articles/securing-model-context-protocol-safer-agentic-ai-with-containers-f3a8a077a2aa77b5.md): Docker · 2025-05-06 · Easy · 9 min read · AI agents, Sandboxing & isolation, Supply chain security, Containers
  Running 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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
