MCP Server Security Best Practices: What We Learned Building One (Checklist)

A practical MCP server security checklist for local servers: least privilege, read-only mode, untrusted tool output, secrets and honest limits, from building one.

Kumar NihalNovember 24, 20268 min read
On this page

MCP Server Security Best Practices: What We Learned Building One (Checklist)

By Kumar, founder of Causly and creator of PCSKit. Last updated: November 24, 2026.

Quick answer: The core MCP server security best practices for a local server are: give every tool the least privilege it needs, keep state-changing and command-running tools off by default, treat tool descriptions and output as untrusted data, keep secrets out of what the server stores and returns, and state plainly what your controls cannot prove.

Disclosure: I build PCSKit, an open-source MCP server, and describe it in one section near the end. The rest of this post draws on the official MCP specification and OWASP guidance, linked in Sources.

MCP server security checklist (at a glance)#

  1. Give each tool the minimum permissions it needs.
  2. Separate read tools from write tools, and offer a read-only mode.
  3. Keep command-running tools off by default and behind human approval.
  4. Never build shell strings from model-supplied input. Validate every argument.
  5. Treat tool descriptions, schemas and return values as untrusted data.
  6. Set tool annotations accurately, but never rely on them as enforcement.
  7. Keep secrets out of config files, logs and tool output.
  8. Log every tool call, with secrets redacted.
  9. Pin and review third-party servers and their dependencies.
  10. Document what your controls do not protect against.

Why is MCP server security different from regular API security?#

In a normal API, the developer decides every call. In MCP, the model decides which tool to call and with which arguments, based on context an attacker may have influenced. OWASP describes the result as a mix of prompt injection, supply chain attacks and confused-deputy problems.

The practical consequence: every argument that reaches your server is untrusted input, even though it arrives from your own client.

Do local (stdio) MCP servers need security?#

Yes. The MCP specification warns that local servers run on the user's machine with direct system access. It lists three attack paths: malicious startup commands in a client configuration, malicious payloads inside a server, and insecure servers left running on localhost and reached through DNS rebinding.

For developers of local servers, the specification recommends using the stdio transport to limit access to the MCP client, or, with HTTP, requiring an authorization token or restricted inter-process communication.

One caveat from OWASP: stdio avoids a listening endpoint, but it does not restrict what the server process itself can reach. Files, network and credentials are still yours to limit.

If you do run a local HTTP server, the transport specification requires validating the Origin header on every connection (rejecting an invalid one with HTTP 403) and recommends binding to 127.0.0.1 instead of all interfaces, plus authentication.

What about OAuth, token passthrough and confused deputy?#

These mostly matter for remote servers and proxies. If your server fronts a third-party API with a shared client ID, the specification requires per-client consent before forwarding the user upstream, with exact redirect URI matching and __Host- cookies if you track consent in cookies.

It also forbids token passthrough: a server must not accept tokens that were not issued for that server. Accepting them lets clients bypass your controls and wrecks your audit trail.

How do you apply least privilege to MCP tools?#

  • One tool per action, so read and write are separate decisions.
  • A read-only mode where write tools are not registered at all. A model cannot call a tool it cannot see.
  • Narrow scopes if you use OAuth. The specification recommends starting with minimal scopes and escalating through targeted challenges, and warns against wildcard scopes and publishing every scope you have.
  • Per-server credentials. OWASP says never to share tokens across servers.

How do you stop a tool from running dangerous commands?#

  • Make it opt-in by the operator, not something the agent can switch on.
  • Run commands as argument arrays, not shell strings. OWASP's guidance is to never pass raw shell commands or unsanitized file paths.
  • Add an allowlist, a timeout and an output cap.
  • Keep a human in the loop. OWASP notes that the specification expects hosts to get explicit user consent before invoking tools. Show full parameters and never auto-approve.
  • Enforce rules in code at execution time, not in a prompt.

How should an MCP server treat tool descriptions and output?#

As untrusted. Tool poisoning hides instructions in descriptions, parameter schemas or return values. OWASP says to treat the entire tool schema as an injection surface, not only the description field.

For output, label it as data, tell the model not to follow instructions inside it, and strip control characters. Pattern filters are a useful extra, but OWASP is clear they cannot prove the remaining text is safe. Authorization must be enforced in trusted code, independent of how the model reads the text.

Use strict JSON Schema: set additionalProperties: false and add patterns on string fields so only declared, well-formed parameters pass.

Watch for rug pulls too, where a server changes its tool definitions after you approved them. OWASP recommends pinning a hash of the complete definition, including inputSchema, outputSchema and annotations.

Are MCP tool annotations a security control?#

No. Annotations are hints: readOnlyHint, destructiveHint, idempotentHint and openWorldHint. By default a tool is assumed not read-only and potentially destructive.

The specification says clients must treat annotations as untrusted unless they come from a trusted server. The MCP project's own blog puts it bluntly: a server can claim read-only and still delete your files. Annotations are not enforcement.

They still help. Trusted clients can use them to decide when to prompt, and a flipped hint changes approval behavior, which is why it belongs in your definition hash. So set them accurately, then enforce the real boundary elsewhere.

How do you keep secrets out of an MCP server?#

  • Store OAuth tokens in OS-native secure storage (Keychain, Credential Manager, Secret Service), not plaintext config files.
  • Redact secrets and personal data from logs.
  • Remember that redaction is usually pattern-based, so it can miss secrets with no telltale prefix or key name. Say so, and let operators add their own rules.

What should an MCP server log?#

OWASP recommends logging every tool invocation with full parameters, user context and timestamps, redacting secrets, and alerting on unusual patterns such as new tools being called or abnormal call frequency. Without this, incident investigation is guesswork.

How do you vet third-party MCP servers?#

Install only from sources you trust, read the code and tool definitions, check package names for typosquatting, scan dependencies, and watch for description changes after install. For one-click local setups, the specification says clients must show the exact command, untruncated, before running it. Its example of what to catch includes a chained command that sends an SSH key to a remote host.

What did building PCSKit teach us about MCP server security?#

PCSKit is a local-first CLI and MCP server (Apache-2.0) that records evidence of what happened in a repository so one AI coding agent can hand work to the next. Its README and docs/DECISIONS.md record these choices:

  • --read-only registers only read-only tools. Write tools simply do not exist for the agent.
  • pcs_test runs a command on your machine, so it is off unless the operator starts the server with --allow-test. Commands are argument arrays with no shell, a timeout and an optional allowlist.
  • Recorded text (commit subjects, notes, test output) is returned as data with control characters stripped, and the server instructions tell the model not to follow it. This reduces prompt-injection risk. It does not eliminate it.
  • The project is fixed with --project, because the client's working directory cannot be trusted.
  • Policy files can only tighten defaults. The global file is the trusted one, because an agent can edit a project file.
  • Two bugs taught us something. Applying Windows permissions recursively locked the owner out of their own folder, and in git worktrees .git is a file, so the data folder was not excluded. Both now have tests.
  • Limits are documented: redaction is pattern-based, and the tamper-evident log only proves changes if you keep a signed anchor somewhere else.

Source and docs: github.com/KNIHAL/pcskit and pcskit.causly.in/docs. None of this makes a server "secure". It narrows what can go wrong and says where it still can.

FAQ#

Is MCP secure?#

The protocol makes authorization optional, so security depends on how a server is built and deployed. The MCP specification and OWASP cheat sheet below list the main risks and mitigations.

Does using stdio make an MCP server secure?#

No. It limits who can talk to the server, not what the server process can access. You still need least privilege and sandboxing.

Do I need OAuth for a local MCP server?#

OWASP advises requiring authentication when remote endpoints expose non-public tools or data. For a local stdio server, the boundary is the user's own machine, so the focus shifts to least privilege, consent for risky tools and limiting what the process can reach.

What is tool poisoning?#

Malicious instructions hidden in a tool's description, parameter schema or return value that manipulate the model. Treat all of it as untrusted.

What is a confused deputy attack in MCP?#

A server acts with its own broad privileges instead of the requesting user's. In OAuth proxy setups, an attacker can exploit a saved consent cookie to skip consent. The fix is per-client consent.

Sources#

Share
Kumar Nihal

Written by

Kumar Nihal

AI-first software engineer and founder of Causly. I build software, SaaS and AI systems, and write about it here. More about me

Get new posts by email

High-signal notes on AI, automation and building systems. No spam.

Keep reading

Insight

Why I Built PCSKit: Solving Context Loss in AI Coding Sessions

AI coding agents are productive, but their work can lose continuity when a context window fills up, a session gets interrupted, or developers switch between tools. I built PCSKit to solve this problem with local-first project continuity, evidence-based handoffs, and verifiable development history—so the next AI agent can continue from the actual project state instead of relying on an unreliable summary.

Nov 24, 2026
Insight

AI Coding Agent Handoffs: Why HANDOFF.md Needs Verifiable Evidence

Learn how to preserve context across AI coding agent sessions with reliable handoffs. Explore the limitations of traditional HANDOFF.md files, why task summaries aren't enough, and how Git state, test results, file changes, and verifiable evidence help agents resume development work with greater confidence.

Nov 24, 2026
Insight

MCP Tool Annotations Explained: Practical Examples, Defaults, and Security Best Practices

Understand MCP Tool Annotations and how they influence AI agent interactions with tools. Learn the four core annotations — readOnlyHint, destructiveHint, idempotentHint, and openWorldHint — with practical JSON examples, default behaviors, security considerations, common mistakes, and testing strategies for building reliable Model Context Protocol servers.

Nov 24, 2026