Mesrai
Back to blog
// essaySecurity

MCP Security: A Practical MCP Server Security Audit for Developers

Half of developer environments now run MCP servers. A practical audit: inventory, tokens, tool poisoning, supply chain and an MCP security best practices checklist.

Surya Pratap SinghNovember 17, 20269 min read

MCP servers give AI coding assistants hands. Through the Model Context Protocol, an assistant can read your files, query your database, open GitHub issues and call internal APIs. That is what makes MCP useful, and it is exactly why MCP security matters: every MCP server you install runs with your permissions, holds your tokens, and feeds text straight into a model that cannot reliably tell instructions from data.

This guide is a practical MCP server security audit you can run in an afternoon. It covers how to inventory what is installed, the five risk areas to check, a hardened example configuration, an MCP security best practices checklist, and where code review fits.

Statistics from Snyk's scan of nearly 10,000 developer environments: 50.8% had at least one MCP server, 4,524 unique server configurations, and 1 in 12 developers had a High or Critical finding in their setup
MCP is already everywhere in developer environments. Source: Snyk.

Why MCP security matters now

Adoption has moved faster than review. Snyk's analysis of nearly 10,000 developer environments found that 50.8% of developers already had at least one MCP server installed, across 4,524 unique server configurations, and that 1 in 12 had a High or Critical finding in their setup. Most of those servers were installed with one command and never looked at again.

An MCP server is three things at once, and each brings its own risk:

  • Code you run. Local MCP servers are programs that execute on your machine with your user's privileges.
  • A holder of credentials. Most servers need a token for GitHub, a database, a cloud account or a SaaS tool.
  • A source of model input. Tool names, descriptions and results are all read by the model, so they can carry instructions.
Diagram of an MCP setup: the AI assistant connects to MCP servers, each with tools, credentials and outbound network access, with five risk areas marked: inventory, credentials, tool poisoning, supply chain and server-side risks
Five places an MCP setup can go wrong.

Step 1: Inventory every MCP server

You cannot secure what you have not listed. MCP servers are configured per tool, so check every AI client your team uses. Common locations include:

  • Claude Desktop: ~/Library/Application Support/Claude/claude_desktop_config.json on macOS.
  • Claude Code: a project-level .mcp.json, plus user-level settings.
  • Cursor: ~/.cursor/mcp.json and a project-level .cursor/mcp.json.
  • VS Code: .vscode/mcp.json in the workspace and user settings.

For each server, record:

  1. Origin: who publishes it, and is it the official package or a fork?
  2. Version: the exact version or image digest, not "latest".
  3. How it runs: a local process, a container, or a remote URL.
  4. Tools: which tools it exposes, and which of them can write, delete or send.
  5. Credentials: which tokens it receives and what those tokens can do.
  6. Data access: which files, databases or APIs it can reach.

Step 2: Check credential and token exposure

Credentials are the most common High finding in an MCP audit.

  • Secrets in config files. Tokens pasted directly into mcp.json end up in backups, screenshots and, for project configs, git history. Reference environment variables or a secret manager instead.
  • Over-privileged tokens. A GitHub token with full repo and admin scopes for a server that only reads issues is a gift to anyone who compromises it. Create a dedicated, fine-grained token per server with the minimum scopes.
  • Inherited environments. Local servers often inherit your whole shell environment, including cloud keys you forgot were there. Pass only the variables a server needs.
  • Token passthrough. If you build an MCP server, never forward a client's token to a downstream API. The MCP specification's security best practices state that servers "MUST NOT accept any tokens that were not explicitly issued for the MCP server."

Step 3: Watch for tool poisoning and prompt injection

Everything an MCP server returns to the model is model input: tool names, descriptions, parameter schemas and results. In April 2025, Invariant Labs named this tool poisoning: hidden instructions in a tool's description that the user never sees but the model reads and follows. Their demonstration used an innocent-looking tool to get an assistant to read and leak a user's SSH keys. Later research showed that any field in a tool's schema can carry instructions, not only the description.

Side by side: what the user sees, a calculator tool named add with a short description, and what the model reads, the same tool with hidden instructions to read a private key file and pass it as a parameter
Tool poisoning: the model reads more than the user sees.

Defences:

  • Read the full tool definitions of every server you install, not just the README. Look for instructions aimed at "the assistant" or "the AI".
  • Pin versions so a tool description cannot change silently after you reviewed it. A server that changes its tools after approval is sometimes called a rug pull.
  • Require confirmation for sensitive tools. Anything that writes files, sends messages or runs commands should ask before it acts.
  • Treat tool results as untrusted data, the same way you treat text from the internet. Our guide to prompt injection in GitHub covers the same principle for pull requests.

Step 4: Check the supply chain

Most MCP servers are installed from public package registries, often with a command such as npx -y some-server, which downloads and runs the latest version every time.

The risk is real. In 2025, CVE-2025-6514 was disclosed in mcp-remote, a widely used proxy that connects local AI clients to remote MCP servers. Connecting to a malicious server could lead to OS command injection through the OAuth flow. It was fixed in version 0.1.16, but only teams that knew they were running it, and updated, were protected.

  • Pin exact versions or image digests instead of latest or unpinned npx.
  • Prefer official servers from the vendor whose API they wrap.
  • Run servers in containers where you can, so a compromised server cannot read your home directory.
  • Track MCP packages like any other dependency, with update alerts and a quick review before upgrading.

Step 5: If you build MCP servers, check the server-side risks

The MCP specification's security best practices list several risks that matter if your team builds or hosts MCP servers:

  • Confused deputy: proxy servers that use a static OAuth client ID must get per-client user consent before forwarding to a third-party authorization server.
  • Server-side request forgery (SSRF): clients and servers that fetch URLs supplied by another party should require HTTPS, block private and link-local addresses, including the 169.254.169.254 cloud metadata endpoint, and validate every redirect.
  • State handle hijacking: never treat possession of a session or state ID as authentication; bind state to the authenticated user.
  • Scope minimisation: start with minimal scopes and request more only when a privileged operation is first attempted. Avoid wildcard scopes such as * or full-access.
  • Local server exposure: local servers should prefer the stdio transport, or require an authorization token if they listen on HTTP.

A hardened MCP configuration example

Here is an illustrative configuration that applies the audit. The exact syntax for referencing environment variables differs between clients, so check your client's documentation.

jsonmcp.json
{
  "mcpServers": {
    "github": {
      "command": "docker",
      "args": [
        "run", "-i", "--rm",
        "-e", "GITHUB_PERSONAL_ACCESS_TOKEN",
        "ghcr.io/github/github-mcp-server@sha256:<pinned-digest>"
      ],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "<read-only fine-grained token from your secret manager>"
      }
    },
    "project-files": {
      "command": "npx",
      "args": [
        "@modelcontextprotocol/server-filesystem@<exact-version>",
        "/Users/you/projects/app"
      ]
    }
  }
}

What makes it safer:

  • The GitHub server runs in a container pinned to an image digest, with a dedicated read-only token.
  • The filesystem server is pinned to an exact version and limited to one project directory, not your home folder.
  • No token is written into the file itself.
  • Nothing runs from an unpinned latest.
MCP security audit worksheet with columns for check, risk level and fix, covering origin, pinned version, token scope, secrets in config, inherited environment, write tools, tool descriptions, network access and update tracking
Use this worksheet for every MCP server in your environment.

MCP security best practices checklist

  • Every MCP server across every AI client is listed with its origin and exact version.
  • Servers come from official or trusted publishers, pinned to a version or digest.
  • Each server has its own minimum-scope token, never your personal admin token.
  • No secrets are written directly into MCP config files.
  • Local servers receive only the environment variables they need.
  • Tools that write, delete, send or execute require confirmation.
  • Tool definitions were read in full before approval and are re-checked after updates.
  • Servers run in containers or sandboxes where possible, limited to the directories they need.
  • If you build servers: no token passthrough, SSRF protections, minimal scopes and per-client consent.
  • MCP config changes in repositories go through code review.

Where repository review helps

Runtime controls protect a running MCP setup. Code review protects the changes that create or alter it, and much of MCP now lives in your repositories as project config files and as the source code of servers you build.

  • Config changes get reviewed. Mesrai reviews every pull request, including changes to .mcp.json and similar files, and can flag new servers, unpinned versions or tokens written into config.
  • Your MCP policy as rules. With Mesrai Rules you can write policies in plain English, such as "flag MCP servers that are not pinned to an exact version" or "flag secrets in mcp.json files", and every pull request is checked against them.
  • Server code gets a security review. If your team builds MCP servers, Mesrai reviews that code like any other service, looking for missing authorization, SSRF-prone URL fetching and leaked credentials. See SSRF in webhook handlers for the kind of issue it catches.

Mesrai does not replace runtime MCP security controls. It makes sure the changes that grant MCP access are seen by someone before they ship.

Frequently asked questions

What is MCP security?

MCP security is the practice of controlling what Model Context Protocol servers can do on behalf of an AI assistant: which code runs, which credentials it holds, which data it can reach, and how much the model should trust what those servers return.

Are MCP servers safe to use?

They can be, if you treat them like any other software with access to your systems: install from trusted sources, pin versions, give each server minimal permissions, and review tool definitions. The risk comes from installing servers casually and giving them broad tokens.

What is MCP tool poisoning?

An attack where instructions are hidden in a tool's description or schema. The user sees a harmless tool, but the model reads the hidden text and may follow it, for example by reading a sensitive file and passing it to the tool.

How do I find which MCP servers are installed?

Check the MCP configuration file for each AI client you use, such as Claude Desktop, Claude Code, Cursor and VS Code, at both user and project level. Record each server's origin, version, tools and credentials.

What are the most important MCP security best practices?

Pin versions, use a dedicated minimum-scope token per server, keep secrets out of config files, require confirmation for tools that write or execute, run servers in sandboxes where possible, and review MCP configuration changes like code.

Sources

Want MCP configuration changes reviewed before they reach your team's machines? Try Mesrai on your repositories.

// try

See it on your next PR.

Free for individual developers as a launch offer. Set up in about 2 minutes. Mesrai reviews every commit.