---
title: "Best practices for MCP secrets management"
description: "Every outbound call from your MCP server carries credentials—API keys, database passwords, OAuth tokens, you name it. If those secrets leak, the blast radius extends far beyond your LLM demo. Learn to secure your MCP secrets."
url: https://workos.com/guide/best-practices-for-mcp-secrets-management
published: "Jul 10, 2025"
---

# Best practices for MCP secrets management

## **The new blast radius**

Large-language models (LLMs) used to be fairly self-contained—feed in a prompt, get back a completion, call it a day. The [Model Context Protocol (MCP)](https://workos.com/blog/model-context-protocol) changes the game by letting models hit live APIs, query fresh data, and even trigger CI/CD pipelines.

Cool? Absolutely. Risky? Also absolutely.

Every outbound call from your MCP server carries credentials—API keys, database passwords, OAuth tokens...and more.

If those secrets leak, the blast radius extends far beyond your LLM demo.

This guide reviews the challenges of MCP server security and lays out concrete, engineer-friendly tactics for keeping sensitive data under wraps.

## **What an MCP server actually does**

Think of [an MCP server](https://workos.com/blog/model-context-protocol) as a multilingual router:

1. It takes a natural-language request from the model—“Give me the last 50 GitHub issues”—and maps it to a structured tool invocation.
2. It executes that call against an external service, authenticating with some secret.
3. It packages the response back into something the LLM understands.

Because the server sits in the middle, it often needs privileged access to production systems. That makes it a prime target.

## **Why secrets go missing — common anti-patterns**

As we wrote about in Best practices for secrets management, there are a number of common anti-patterns to avoid:

| Anti-pattern | Why it bites |
| --- | --- |
| Hard-coded secrets | An API key buried in config.ts ends up in Git history, code-review diffs, or (worse) Stack Overflow snippets. |
| Long-lived credentials | Static, year-long tokens mean an attacker only has to get lucky once. |
| Over-broad access | A single root token that can read and write everything is convenient—until someone runs DROP DATABASE. |
| Filesystem over-exposure | MCP SDKs let you mount entire directories as tool-visible paths. A bad glob (**/*) or mis-scoped volume can hand the LLM your /home folder, leaking PII or source code in a single response. |
| No audit trail | If you can't answer "who accessed this secret and when," you're flying blind. |
| In-flight leakage | Plain-text HTTP, verbose logs, and misconfigured proxies can all surface secrets you thought were hidden. |

## **Six best practices for MCP secrets management**

Treat every secret like a live grenade—handle it sparingly, store it safely, and rotate it often.

### **1  Eliminate hard-coding**

Pull secrets from environment variables *or* a dedicated secrets manager—never from source control.

`# .env (never committed to version control and added to .gitignore) GITHUB_TOKEN=ghp_************************`

Reference them via environment variables in your implementation:

`// mcp-server/src/clients/github.ts const token = process.env.GITHUB_TOKEN;`

**Heads-up:** env vars are fine for 12-factor apps, but on Kubernetes or Nomad anyone with exec access can run env to read them. For high-sensitivity creds consider tmpfs mounts, sealed-secrets, or an injector sidecar that feeds secrets over a UNIX socket.

### **2  Prefer dynamic, short-lived credentials**

Tools such as HashiCorp Vault or the [open source AWS vault command line tool](https://github.com/99designs/aws-vault) (dynamic secrets) or AWS STS can mint time-boxed creds on demand. If compromised, they self-destruct quickly.

### **3  Apply least privilege with RBAC**

Each tool integration should have its own role with the minimum scope required. Products [like **WorkOS AuthKit** provide fine-grained authorization overlays that plug directly into MCP servers and Cloudflare Workers.](https://workos.com/blog/workos-cloudflare-mcp-auth-for-agentic-ai)

`# Vault policy example path "kv/data/github" {   capabilities = ["read"] }`

### **4  Enforce end-to-end encryption**

TLS is table stakes. You can go further, and enable mutual TLS between the MCP server and your secrets backend to block man-in-the-middle attacks.

### **5  Rotate and revoke automatically**

Schedule rotation jobs or use vendor-supplied auto-rotation. AWS Secrets Manager, for instance, can rotate an RDS password via Lambda on a cron schedule.

### **6  Log, alert, repeat**

Pipe audit logs to a SIEM so that *“unauthorized read at 02:13 UTC”* triggers a page—not a post-mortem.

## **Choosing the right tool for the job**

| Tool | Sweet spot | Notable features |
| --- | --- | --- |
| Vault by HashiCorp | Self-hosted, on-prem or multi-cloud | Dynamic secrets, fine-grained ACLs, pluggable auth back-ends |
| AWS Secrets Manager | AWS-centric workloads | Native rotation for RDS/Redshift, CloudWatch auditing |
| Infisical | Developer-first SaaS | GitHub sync, per-environment scopes, CLI that feels like dotenv on steroids |
| WorkOS AuthKit | Identity & RBAC overlay for MCP + Cloudflare | Enterprise SSO, fine-grained roles/permissions, audit-ready consent flows; pairs with secrets stores to gate agent actions [WorkOS + Cloudflare MCP](https://workos.com/blog/workos-cloudflare-mcp-auth-for-agentic-ai) |

All four integrate cleanly with MCP servers via REST, gRPC, or language SDKs—and WorkOS layers identity controls on top of whatever secrets backend you choose.

## **Implementing secrets management in an MCP workflow**

![](https://cdn.prod.website-files.com/621f84dc15b5ed16dc85a18a/680fd97d55eb62a67e7c458a_mcp-secrets-mgmt.webp)

**Why this matters**

- Tokens never persist to disk (and logs/core dumps are scrubbed).
- The LLM never sees the raw credential.
- Vault issues the token and records an audit entry.
- WorkOS can gate which *tools* an agent may invoke based on the user’s role, adding a second line of defence.

## **Security principles baked into the MCP spec**

- **Explicit user consent** — every tool invocation must be approved by the end user.
- **Minimum necessary data** — hosts should shield user data unless explicitly permitted.
- **Tool safety** — each tool is treated as arbitrary code; the spec mandates human approval before execution.
- **Sampling transparency** — users decide which parts of the prompt/response the server can inspect.

Your secrets strategy should dovetail with these principles: grant only the scope required, log every access, and surface any deviation for human review.

## **Beyond the happy path — threat-model like an attacker**

- **Assume breach** — design as if an attacker already has network access. Can they walk from the MCP host to your secrets store?
- **Beware prompt injection** — a malicious prompt could trick the server into calling dangerous tools. Validate *operations*, not just credentials.
- **Lock down filesystem mounts** — scope directory paths explicitly (/data/reports/*.csv > /data/* > /) and run integration tests that attempt to exfiltrate /etc/passwd; fail the build if they succeed.
- **Plan incident response** — know how to revoke all active secrets in minutes, not hours.

## **Final thoughts: small habits, huge payoffs**

Securing an MCP server isn’t dark magic.

It’s engineering hygiene: no hard-coding, least privilege, dynamic creds, aggressive rotation, airtight filesystem scopes, and ruthless logging—bolstered by identity layers like WorkOS AuthKit that enforce consent and RBAC.

The payoff is massive: you preserve user trust, keep auditors happy, and sleep better knowing your LLM won’t accidentally DROP your production database—or leak /var/log/auth.log—on livestream.

Lock down your secrets today, and your future self (and your security team) will thank you tomorrow.
