Building & Deploying MCP Best Practices
Ten practices for building, securing, and versioning production MCP servers.
Search across all documentation pages
Ten practices for building, securing, and versioning production MCP servers.
Use this list when you scaffold a new server, promote stdio to HTTP, or review an MCP change before merge.
call_tool, plus invalid args. Manual host checks alone are not enough.version on breaking tool renames; snapshot tool names/required fields so agents do not silently break.Origin; forward session and protocol version headers correctly./healthz, timeouts on outbound calls, retention for spills, one-command rollback image, and dual-mode (stdio + HTTP) only when both are tested.| Stage | Habits | Exit criterion |
|---|---|---|
| Design | 1-3 | Tool map + primitive roles + stdio logging rules written |
| Build | 4-6 | CI smoke green; schema freeze; spill path documented |
| Expose | 7-9 | HTTPS + auth + scopes reviewed |
| Run | 10 | Health, timeouts, rollback rehearsed |
console.log / print on stdio "just for debug" left enabled./mcp without bearer validation.Authorization headers.# Patterns: stderr logs, small tool, spill hook, transport switch
import logging, os, sys
from mcp.server.fastmcp import FastMCP
logging.basicConfig(stream=sys.stderr, level=logging.INFO)
mcp = FastMCP("prod-server")
@mcp.tool()
def ping() -> str:
"""Liveness check; no side effects."""
return "pong"
if __name__ == "__main__":
transport = os.environ.get("MCP_TRANSPORT", "stdio")
mcp.run(transport=transport) # verify allowed values at buildSafe stdio logging (3), automated MCP smoke tests (4), and auth for remote HTTP (8). Without those, the rest is decoration.
Usually no. Use env-injected secrets and OS user isolation. Add OAuth when the server is remote HTTP.
On every intentional tool rename or required-field change. Unexpected freezes failures should block merge.
For new remote deploys it is the current standard. Support legacy HTTP+SSE only with a documented compatibility path (verify at build).
Add resources when agents repeatedly need the same large read-only context. Until then, habits 1 and 6 keep tools usable.
Check tool descriptions, schemas, tests, auth impact, and whether outputs can grow without bound.
Only when hosts will surface them. Empty prompt support is optional noise.
Tool success rate, latency p95, auth failure rate, spill rate, and session error rate (bad session / version mismatch).
Related: Building & Deploying MCP Basics
Related: Anatomy of an MCP Server: Handlers, Schemas, and Transport
Related: Auth and Access Control for Remote MCP Servers
Related: Handling Large Tool Outputs: Auto-Spill to Sandbox Files
Stack versions: Pins from the category manifest (verify at build): OpenRouter (~315+ models, July 2026 pricing/fees); LangGraph 1.0+; CrewAI 1.14+; Microsoft Agent Framework 1.0; Vercel AI SDK 6; Pydantic AI (latest); LlamaIndex (latest); OpenAI Agents SDK (latest + MCP); MCP (Linux Foundation governance); A2A (HTTP+SSE+JSON-RPC 2.0); Solana
@solana/web3.js+@solana/spl-token.
Reviewed by Chris St. John·Last updated Jul 16, 2026