---
title: "How to Actually Secure MCP (Model Context Protocol)"
description: "Learn how to secure MCP (Model Context Protocol) implementations before connecting LLMs to production systems. Covers threat models including prompt injection, credential scoping, TLS requirements, JSON Schema validation, and logging best practices for safely deploying AI tool integrations."
image: "https://cdn.sethserver.com/blog-images/how-to-actually-secure-mcp-model-context-protocol-social-1794887091.jpg"
---

# How to Actually Secure MCP (Model Context Protocol)

MCP is fun until it’s root on your infra.

MCP is the new hotness, and I get it. It’s a clean way to let an LLM app call tools without inventing - or having to freaking LEARN - a new plugin format every 10 minutes. [modelcontextprotocol](https://modelcontextprotocol.io/docs/tutorials/security/security_best_practices)

It’s also the moment a lot of teams accidentally wire a language model into production systems and call it “automation.” [socprime](https://socprime.com/blog/mcp-security-risks-and-mitigations/)

If you let MCP touch prod, you didn’t “add AI.” You built a new attack surface. MCP is just another protocol sitting on top of your existing mess. And all of that gets used in ways you didn’t plan. [protectai](https://protectai.com/blog/mcp-security-101)

## MCP in 5 minutes (for infra people)

MCP usually looks like this. [modelcontextprotocol](https://modelcontextprotocol.io/docs/tutorials/security/security_best_practices)

- **MCP host**: your LLM app (chat UI, agent, IDE assistant, whatever).
- **MCP client**: the bit inside the host that speaks MCP.
- **MCP servers**: processes that expose tools and resources (GitHub, Slack, database queries, kubectl wrappers, internal APIs).

The flow is basically: [protectai](https://protectai.com/blog/mcp-security-101)

1. **Discovery**: the host asks “what tools exist?”
2. **Selection**: the model picks a tool based on the prompt and tool descriptions.
3. **Invocation**: the host sends tool name + arguments to the MCP server.
4. **Execution**: the server does the real work against downstream systems.

The interesting part is selection. A model is making a choice based on text. That choice can be steered by any text you stuff into context: user input, logs, HTML, ticket descriptions, “helpful” tool instructions, you name it. [prompt](https://www.prompt.security/blog/top-10-mcp-security-risks)

## Threat model in builder language

Here’s what breaks first.

### 1) Prompt/tool injection: wrong tool, wrong args

Say your tool list includes:

- `deploy_service`
- `delete_namespace`
- `rotate_secrets`

If the model gets nudged into calling one of those with bad arguments, that’s not a hallucination. That’s an RPC your own system happily executed. [prompt](https://www.prompt.security/blog/top-10-mcp-security-risks)

Injection doesn’t have to come from the user prompt. It can come from: [invariantlabs](https://invariantlabs.ai/blog/mcp-security-notification-tool-poisoning-attacks)

- Pasted logs that contain “helpful” instructions
- A ticket title or description from Jira
- Tool output you feed back into the model
- Malicious or sloppy tool metadata

The model doesn’t treat these as “trusted” or “untrusted.” It just sees tokens.

### 2) MCP servers with god-mode tokens

This is the classic “server acts like root” problem, just with more marketing.

If your MCP server holds a single global API key for prod, every tool call is “admin,” even if the actual human is an intern poking at a staging incident. [socprime](https://socprime.com/blog/mcp-security-risks-and-mitigations/)

Early in my career I wrote custom BI software in C++ for a Fortune 500 company. I even rolled my own encryption scheme so database creds could hop between machines without relying on external tools. It worked. It also meant I was the only person who could explain it without a whiteboard and a headache. Off‑the‑shelf would’ve been safer and faster.

Same energy here: if you build one magical credential blob that makes everything “just work,” that blob turns into your breach report later. [varonis](https://www.varonis.com/blog/why-polp-is-critical-for-ai-security)

### 3) Long-lived sessions with no rotation or audit

If MCP sessions live forever and you don’t log who called what, you’re basically leaving a quiet remote control lying around. [modelcontextprotocol](https://modelcontextprotocol.io/docs/tutorials/security/security_best_practices)

An attacker that lands inside your network now gets:

- A long-lived channel to sensitive tools
- No rotation on tokens or session IDs
- No clean way for you to answer “who ran this action and why?”

Even without an attacker, you’ll get paged for “why did this tool run?” and your answer will be “some context somewhere told the model it was a good idea.” [socprime](https://socprime.com/blog/mcp-security-risks-and-mitigations/)

## Opinionated best practices (with concrete examples)

### TLS everywhere (even “localhost”)

People love saying “it’s just localhost, bro.” Then they add:

- A tunnel for remote teammates
- A dev container or VM
- A port‑forward from k8s

At that point “localhost” means “a path attackers can hit if they find the right hop.” [modelcontextprotocol](https://modelcontextprotocol.io/docs/tutorials/security/security_best_practices)

Use TLS between host and MCP servers, and use mTLS if you can. Treat MCP servers like any other internal service, not special snowflakes. [socprime](https://socprime.com/blog/mcp-security-risks-and-mitigations/)

For local dev, generate a local CA and issue short‑lived certs. Boring security is usually the kind that works. [modelcontextprotocol](https://modelcontextprotocol.io/docs/tutorials/security/security_best_practices)

### Per-server credentials with least privilege

Don’t hand MCP servers a single god-token. Give each server its own identity and let that identity do as little as possible. [socprime](https://socprime.com/blog/mcp-security-risks-and-mitigations/)

Patterns that age well:

- Each MCP server gets its own credential.
- That credential is scoped to the smallest set of actions.
- If a server needs both read and write, consider splitting it into two servers.

Example:

- `mcp-github-readonly` can list PRs and read files.
- `mcp-github-write` can comment and merge, but only for a specific repo or org.
- Your host only connects to the write server in workspaces that actually need it. [knostic](https://www.knostic.ai/blog/mcp-security)

That’s the Principle of Least Privilege for AI agents: scope credentials to the exact actions each agent or tool needs, nothing more. [doc-e](https://www.doc-e.ai/post/managing-excessive-agency-the-principle-of-least-privilege-for-ai-agents)

### Tool allowlists on the host

The host should decide which tools the model even knows about. [socprime](https://socprime.com/blog/mcp-security-risks-and-mitigations/)

Don’t drop every tool into a single shared registry and hope the model “learns” not to call dangerous ones.

Instead, make it contextual:

- In a “support chat” workspace, allow: `search_docs`, `create_ticket`, `read_customer_profile`.
- In a “prod ops” workspace, allow: `get_deploy_status`, `tail_logs`.
- Keep `delete_*` and other destructive tools out of the model’s reach, or wire them behind explicit human-confirm flows. [hatchworks](https://hatchworks.com/blog/ai-agents/ai-agent-security/)

If the model can’t see a tool, it can’t call it. That’s the cheapest guardrail you’ll ever ship.

### JSON Schema enforcement on inputs and outputs

If your tool accepts a free‑form string like `command`, you’re asking for surprises. [genai.owasp](https://genai.owasp.org/resource/a-practical-guide-for-secure-mcp-server-development/)

Use JSON Schema for tool inputs. Validate every call. If it doesn’t match, hard fail and log it.

Example schema for a deploy tool:

```json
{
  "type": "object",
  "properties": {
    "service": { "type": "string", "pattern": "^[a-z0-9-]{3,40}$" },
    "env": { "type": "string", "enum": ["staging", "prod"] },
    "version": { "type": "string", "pattern": "^v?[0-9]+\\.[0-9]+\\.[0-9]+$" }
  },
  "required": ["service", "env", "version"],
  "additionalProperties": false
}
```

That `additionalProperties: false` is doing real work. It blocks the “oh and also run this extra command” nonsense hiding in extra fields. [knostic](https://www.knostic.ai/blog/mcp-security)

Validate outputs too. If a tool returns a big text blob, the model will happily read it as instructions unless you fence it off or sanitize it. [prompt](https://www.prompt.security/blog/top-10-mcp-security-risks)

### Centralized logging that ties everything together

You want one clear chain every time a tool runs: [genai.owasp](https://genai.owasp.org/resource/a-practical-guide-for-secure-mcp-server-development/)

**user → prompt → chosen tool → args → downstream result**

If you can’t answer “who triggered this?” and “what did the model see?” you can’t debug incidents, detect abuse, or improve the system. [socprime](https://socprime.com/blog/mcp-security-risks-and-mitigations/)

Log at least:

- User ID / workspace
- Model request ID
- Tool name + validated args
- Downstream request ID (GitHub request ID, DB query ID, etc.)
- Result status + errors

Hook this into whatever you already use for audit trails. Treat MCP calls like privileged API calls, because they are. [hatchworks](https://hatchworks.com/blog/ai-agents/ai-agent-security/)

## MVP but not reckless

Ship fast is fine. Shipping a self‑aimed foot-gun is not.

A sane day‑one rollout looks like: [genai.owasp](https://genai.owasp.org/resource/a-practical-guide-for-secure-mcp-server-development/)

- **Local-only MCP servers** to start. No exposed network ports, no random public tunnels.
- **Read-only tools** first: search, list, fetch. No write paths until you’ve watched logs in anger.
- **Short-lived sessions**: rotate credentials, expire tokens.
- **No prod access** until you have logging, allowlists, and some confidence from staging.
- **Explicit “human confirm” gates** for anything changing state, especially deletes, merges, or credential changes.

A model making suggestions or drafting commands is fine. A model executing irreversible actions needs guardrails that live in code, not in a Notion doc about “how we use AI responsibly.” [socprime](https://socprime.com/blog/mcp-security-risks-and-mitigations/)

If you’re starting to build your first MCP server, spend your early energy on policy enforcement, bounded outputs, and boring error handling. Those are the pieces that keep a handy utility from turning into your next security incident. [modelcontextprotocol](https://modelcontextprotocol.io/docs/tutorials/security/security_best_practices)

MCP isn’t just “a nicer plugin system.” It’s a remote control for your systems. Treat it like one, secure it like one, and you’ll sleep a lot better. [checkpoint](https://www.checkpoint.com/cyber-hub/cyber-security/what-is-ai-security/mcp-security/)

-Sethers


```json
{"@context": "https://schema.org", "@type": "BlogPosting", "headline": "How to Actually Secure MCP (Model Context Protocol)", "datePublished": "2026-04-14T20:15:34", "dateModified": "2026-04-14T20:15:34", "image": {"@type": "ImageObject", "url": "https://cdn.sethserver.com/blog-images/how-to-actually-secure-mcp-model-context-protocol-social-1794887091.jpg", "width": 400, "height": 400}, "url": "https://www.sethserver.com/ai/how-to-actually-secure-mcp-model-context-protocol.html", "author": {"@type": "Person", "name": "Seth Black", "url": "https://www.linkedin.com/in/seth-black-tx"}, "publisher": {"@type": "Organization", "name": "Sethserver", "logo": {"@type": "ImageObject", "url": "https://www.sethserver.com/static/images/PaperAirplane512.png"}}, "description": "Learn how to secure MCP (Model Context Protocol) implementations before connecting LLMs to production systems. Covers threat models including prompt injection, credential scoping, TLS requirements, JSON Schema validation, and logging best practices for safely deploying AI tool integrations.", "articleSection": "Technology"}
{"@context": "https://schema.org", "@type": "BreadcrumbList", "itemListElement": [{"@type": "ListItem", "position": 1, "name": "sethserver", "item": "https://www.sethserver.com/"}, {"@type": "ListItem", "position": 2, "name": "AI", "item": "https://www.sethserver.com/ai/"}, {"@type": "ListItem", "position": 3, "name": "How to Actually Secure MCP (Model Context Protocol)", "item": "https://www.sethserver.com/ai/how-to-actually-secure-mcp-model-context-protocol.html"}]}
```
