Skip to content

MCP: security & production

An MCP server runs with real credentials and takes actions on behalf of a model that can be manipulated. Design as if the model’s inputs are hostile.

Threat Example Mitigation
Prompt injection A web page or ticket the agent reads says “call delete_all_projects” Least-privilege tools; confirmations or elicitation for destructive actions; no destructive tools on servers that also read untrusted content
Over-privileged credentials A server uses an admin token for a read-only job Scoped tokens per server; read-only credentials where possible
Secret leakage A token in mcp.json committed to git; secrets echoed in tool output or error messages Variable references instead of literal values (Cursor: ${env:NAME} or envFile; Claude Code .mcp.json: ${NAME} or ${NAME:-default}) or a secret manager; redact secrets in outputs, errors, and logs
Path traversal read_file("../../.ssh/id_rsa") Resolve and check paths against allowed roots
Command injection A tool builds a shell string from input Never pass input to a shell; use argument arrays; allowlist commands
SSRF A fetch_url tool used to reach internal services Allowlist domains; block private IP ranges
Tool poisoning / rug pull A third-party server changes its tool descriptions to manipulate the model Only install trusted servers; pin versions; review changes
Token passthrough (remote) A server accepts any bearer token and forwards the client’s token to other APIs Accept only tokens issued for your server (validate the audience); never forward client tokens; get separate tokens for upstream APIs
Confused deputy (OAuth proxy servers) A server that proxies a third-party OAuth provider with one static client ID skips consent for a returning user, so an attacker’s client, registered with its own redirect URI, receives that user’s authorisation code Ask for consent per client before forwarding to the third-party provider; match redirect URIs exactly; generate and check the state parameter
Denial of wallet / runaway A loop calls an expensive API thousands of times Rate limits, quotas, and result-size caps
  • Reads all credentials from environment variables; none in code or committed config
  • Validates every input (schemas, plus server-side checks for paths and IDs)
  • Restricts filesystem access to configured roots
  • No shell=True or exec(string); uses argument arrays
  • Destructive tools keep destructiveHint: true (the default), and ask for confirmation (elicitation) or need an explicit confirm: true argument
  • Caps output size and pagination
  • Logs to stderr without secrets
  • Pins its dependencies (lockfile committed)
  • TypeScript (v2): use createMcpHandler from @modelcontextprotocol/server (a web-standard request handler), NodeStreamableHTTPServerTransport or toNodeHandler from @modelcontextprotocol/node (Node’s http module), or a framework adapter: @modelcontextprotocol/express, @modelcontextprotocol/hono, or @modelcontextprotocol/fastify. Mount it on a route such as /mcp. (In v1 this was StreamableHTTPServerTransport, wired by hand.)
  • Python: mcp.run(transport="streamable-http"), or mount mcp.streamable_http_app() in your ASGI app. Both bind to 127.0.0.1 by default; in a container, pass host="0.0.0.0".
  • Sessions are legacy only. The 2026-07-28 protocol has no sessions: every request carries its own protocol version and is self-contained. Legacy (2025) clients can use sessions (Mcp-Session-Id). For them, stateless mode (for example stateless_http=True in Python) is simplest to scale horizontally. Keep legacy sessions only if you must send server-initiated messages to legacy clients.
  • HTTPS only
  • OAuth 2.1 following the MCP Authorization specification: the server acts as a resource server, publishes Protected Resource Metadata, and validates bearer tokens (issuer, audience, expiry, and scopes)
  • A request with a missing or invalid token gets 401 Unauthorized with a WWW-Authenticate header that points to the Protected Resource Metadata (resource_metadata="https://your-host/.well-known/oauth-protected-resource"), so the client can discover where to sign in
  • Client registration is supported on your authorisation server. Claude uses Client ID Metadata Documents (CIMD) only if the authorisation server advertises client_id_metadata_document_supported: true and supports the none token endpoint auth method. Otherwise it falls back to Dynamic Client Registration (DCR), which the spec now deprecates. Support CIMD, and keep DCR only for older clients
  • The callback (redirect) URLs of every client you support are registered on your authorisation server (the OAuth provider that issues the tokens, not the MCP server itself):
    • Claude (claude.ai, Claude Desktop, and Claude Code): https://claude.ai/api/mcp/auth_callback, plus the loopback URLs http://localhost/callback and http://127.0.0.1/callback, which must be matched on any port
    • Cursor: https://www.cursor.com/agents/mcp/oauth/callback and http://localhost:8787/callback
  • Or, for internal or simple cases, API keys in an Authorization header (clients: headers in Cursor’s mcp.json or Claude Code’s .mcp.json, or --header with claude mcp add)
  • Per-user authorisation inside every tool (whether this user may see or change this record)
  • Validate the Origin header and bind to localhost when running locally, to prevent DNS rebinding
  • Rate limiting per user or token
  • Timeouts on every upstream call
  • Structured logs: tool name, user, latency, and outcome (no secrets, and PII minimised)
  • Metrics and alerts on error rate and latency
  • Health endpoint for the load balancer
  • Horizontal scaling: 2026-07-28 requests need no affinity; for legacy clients, run stateless or use sticky sessions if you keep legacy sessions
  • Semantic versioning in the server version field and package.
  • Adding a tool or an optional parameter is a minor change. Renaming or removing a tool, or adding a required parameter, is a major change.
  • Deprecate a tool before removing it: keep it for one release and say “Deprecated: use X” in its description.
  • The SDKs handle both protocol eras: they negotiate the version with legacy clients and read it from each request from 2026-07-28 clients. Upgrade the SDK regularly and re-run your smoke tests and evals.
  • Keep a CHANGELOG.md.
Channel Audience How
Git repo + README Team Clone, build, and paste the config snippet
npm / PyPI package Anyone npx -y your-server / uvx your-server in the config
MCP Bundle (.mcpb) Claude Desktop users npx @anthropic-ai/mcpb init, then npx @anthropic-ai/mcpb pack; users open the file to install
Docker image Teams / isolation "command": "docker", "args": ["run", "-i", "--rm", "your/image"]
Remote URL Anyone, including claude.ai Deploy it; share the URL; users add it as a connector or url entry
MCP Registry / directories Public Publish metadata to the official MCP Registry (https://registry.modelcontextprotocol.io), Cursor’s directory, or Claude’s connectors directory
Plugin Team / org Bundle the MCP config with skills and agents in a Claude Code or Cursor plugin
  • Threat-model table reviewed for this server
  • Every tool classified as read-only, write, or destructive; the annotations match
  • Destructive actions need confirmation
  • Credentials are scoped to the minimum
  • Injection tests: tool inputs containing ../, ; rm -rf, $(…), and internal URLs
  • Output and error messages reviewed for secret or PII leakage
  • Dependencies scanned (npm audit / pip-audit)
  • For a remote server: auth tested with an expired, wrong-audience, or missing token (all must be rejected with 401)
  • For a remote server: sign-in tested from each target client (claude.ai, Claude Code, Cursor)