Area 06 · AI Security · Concept 18 of 20

MCP Server Trust

Connect only MCP servers you trust. A bad one can inject instructions or steal data.

11–20 · Production levelPhase 7 · Weeks 24–26≈ 45 min

The idea

An MCP server’s tool names and descriptions are text the model reads, so a malicious or compromised server can carry prompt injection ("tool poisoning"), shadow trusted tools with look-alike names, or change its behaviour after you approved it. Local servers run code on your machine with your permissions.

Treat MCP servers like any dependency: install from trusted publishers, pin versions, review what tools they expose, run local servers with minimal permissions, and prefer remote servers with proper OAuth over pasting long-lived tokens.

In your own clients, show users which server a tool comes from, require approval for sensitive tools, and alert on tool definition changes.

Why it matters

MCP makes connecting tools easy, which also makes connecting a malicious one easy.

Words to know

  • Tool poisoningMalicious instructions hidden in tool descriptions.
  • Rug pullA server changing its tools after it was approved.

Try it without code

Review a server

  1. Pick an MCP server you use.
  2. Read its tool descriptions in full.
  3. Check its publisher, version pinning and the permissions it runs with.

Use it in code

Pin and diff tool definitions so changes require re-approval.

python
import hashlib, json, pathlib

PINS = pathlib.Path("mcp_pins.json")

def fingerprint(tools):
    canon = json.dumps([{"name": t.name, "description": t.description, "schema": t.inputSchema}
                        for t in sorted(tools, key=lambda t: t.name)], sort_keys=True)
    return hashlib.sha256(canon.encode()).hexdigest()

def verify(server_name, tools):
    pins = json.loads(PINS.read_text()) if PINS.exists() else {}
    fp = fingerprint(tools)
    if server_name in pins and pins[server_name] != fp:
        raise RuntimeError(f"{server_name} tool definitions changed - review before use")
    pins.setdefault(server_name, fp)
    PINS.write_text(json.dumps(pins, indent=2))
PRACTICE · TICK IT AFTER THIS

Add tool fingerprint pinning to your MCP client and show the server name next to every tool call in your logs.

Common mistakes

  • Installing servers from random repos with npx and full permissions.
  • Auto-approving all tools from a server.

Go deeper