Security7 min read

Rotating MCP Credentials: A Practical Guide for Leaks, Expiry, and Routine Hygiene

Every MCP that talks to an upstream service holds a credential. Eventually you need to rotate it — because it leaked, because the person who owned it left, or because 90 days have passed. This guide is the step-by-step playbook for both kinds of MCP credential: API keys (in client config) and OAuth tokens (in the OS credential store).

Two credential models, two playbooks

MCP credentials live in one of two places. API keys for local stdio MCPs sit in the client\'s config file as environment variables — `GITHUB_TOKEN`, `STRIPE_KEY`, `POSTGRES_URL`. OAuth access and refresh tokens for remote MCPs sit in the OS credential store, managed by the client. The rotation steps differ by storage location, but the underlying principle is the same: revoke first, re-issue second, update third.

Playbook A — Rotating an API-key MCP

  1. 1

    Issue a new key in the upstream service

    Most services let you have two keys active at once. Create the new one with the same (or tighter) scope.

  2. 2

    Update the MCP client config

    Replace the env-var value in claude_desktop_config.json / mcp_config.json / .vscode/mcp.json. Save.

  3. 3

    Restart the MCP client

    stdio MCPs only re-read env on start. Cmd+Q + relaunch is the surest path.

  4. 4

    Verify the new key works

    Run a no-op tool call in a fresh conversation. Confirm a successful response.

  5. 5

    Revoke the old key

    Only after the new key is confirmed working. This is the irreversible step — wait until you have proof of life.

  6. 6

    Audit recent activity

    If this rotation was triggered by a suspected leak, scan the upstream service's activity log for the past 24 hours for actions you did not initiate.

Playbook B — Rotating an OAuth MCP

  1. 1

    Revoke the token at the OAuth authorization server

    For most services this is in the user's "connected apps" or "authorized clients" UI. Revoking here invalidates both the access token and any associated refresh token.

  2. 2

    Clear the token from the OS credential store

    Most MCP clients ship a "log out" or "disconnect" command per MCP. If yours does not, manually delete the entry from Keychain / DPAPI / libsecret using the client's service name.

  3. 3

    Re-trigger the OAuth flow

    Open the MCP in your client. The client detects the missing token, opens the system browser, and walks you through OAuth 2.1 with PKCE. Approve the scopes.

  4. 4

    Confirm the new tokens land in the credential store

    A new access + refresh pair should appear. Refresh-token rotation will handle subsequent renewals automatically.

  5. 5

    Audit recent activity if the rotation was triggered by suspected compromise

    OAuth services typically expose an activity log keyed by the access token's session ID. Look for actions in the window between issue and revocation.

If the credential leaked into git

  1. Revoke immediately — do not stop to remove the commit. Assume the key has already been scraped.
  2. If the repo is public, GitHub\'s secret-scanning likely already pinged the upstream provider. Many providers (Stripe, GitHub itself, AWS) auto-revoke leaked tokens within minutes.
  3. Issue a new credential with the same (or tighter) scope.
  4. Update the MCP client config and restart.
  5. Decide whether to rewrite git history. Public repo with a sensitive token: probably yes, but accept that any clone before the rewrite still has the secret. Private repo: usually not worth the disruption.
  6. Audit upstream activity for the window between push and revocation.
  7. Add a pre-commit hook (gitleaks, talisman, or similar) so this does not happen again.

Routine rotation cadence

A reasonable default is 90 days for any MCP credential that can move money, send messages, or write to production data, and 180 days for everything else. The cost of routine rotation is small; the cost of an undetected leak compounding for 18 months is significant.

Calendar reminders are sufficient for individuals. Teams should put the cadence in a runbook and rotate together — staggered per-person rotation creates windows where credentials with mixed scopes are valid simultaneously, which makes incident response harder.

Frequently asked questions

When should I rotate MCP credentials?

Three triggers: (1) confirmed or suspected leak — committed to git, pasted in a shared doc, on a stolen laptop; (2) personnel change — someone with access leaves the team; (3) routine — every 90 days for high-value tokens, every 180 for everything else. Routine rotation is the cheapest insurance against quiet, undetected leaks.

What is the right order of operations for an emergency rotation?

Revoke first, then re-issue, then update the client. Revoking first kills any in-flight abuse. Re-issuing second gets you a working credential. Updating the client last avoids a window where your live MCP holds an invalid token and starts erroring loudly enough that you notice — that is good, but the kill-first ordering is even better.

Where is the MCP token stored on my machine?

For local stdio MCPs: in the client's config (env vars in claude_desktop_config.json, mcp_config.json, or .vscode/mcp.json). For OAuth-based remote MCPs: in the OS credential store — Keychain on macOS, DPAPI on Windows, libsecret on Linux. Knowing this matters for rotation — config-file tokens require a file edit; credential-store tokens require a client command to re-authorise.

How do I rotate an API-key MCP without downtime?

Most services support two active keys for exactly this case. Issue a new key alongside the old one. Update the MCP client config to the new key and restart. Confirm the new key works for a few minutes. Then revoke the old key. Zero-downtime, zero-risk window.

How do I rotate an OAuth-based MCP credential?

Refresh-token rotation is automatic if the server implements the 2025-06-18 spec correctly — each refresh issues a new refresh token and invalidates the old. For a forced rotation (revoke + re-auth), revoke at the upstream OAuth server, then re-trigger the OAuth flow in your client. Most clients have an explicit "re-authorise" command per MCP.

What if the token is already in a public git repo?

Revoke immediately — assume it has already been scraped. GitHub's secret-scanning notifies many providers automatically, and they will often revoke for you within minutes. After revoking, audit the upstream service for any actions taken in the window between push and revocation. Then rewrite history if the repo will stay public, or accept the leak and rely on the revocation.

Related: MCP Security overview · OAuth 2.1 for MCP

More guides

Fundamentals

What Is MCP? A Plain-English Guide to Model Context Protocol

6 min read

Setup Guide

Best MCPs for Cursor in 2026 (Ranked + Setup)

8 min read

Setup Guide

Best MCPs for Claude Desktop in 2026 (Ranked + Setup)

9 min read

Setup Guide

Best MCPs for Claude Code in 2026 (Ranked + Setup)

8 min read

Setup Guide

Best MCPs for Windsurf in 2026 (Cascade-Ready Setup)

8 min read

Setup Guide

Best MCPs for VS Code in 2026 (Agent Mode + .vscode/mcp.json)

8 min read

Strategy

MCP Registry vs Curated Directory: Which Should You Use?

5 min read

Setup Guide

Best MCPs for ChatGPT: The Apps and Connectors Worth Installing

9 min read

Tutorial

How to Add an MCP Server to ChatGPT (Developer Mode + Apps Directory)

7 min read

Security

MCP Security: What to Know Before You Install

9 min read

Role Guide

Best MCPs for Marketers in 2026 (SEO, Email, Analytics)

8 min read

Strategy

Remote vs Local MCP Servers: When to Use Each

7 min read

Fundamentals

MCP vs Function Calling: What’s the Difference?

6 min read

Comparison

MCP Directories Compared: Top MCPs vs mcp.so vs PulseMCP vs mcp.directory

8 min read

Security

MCP Prompt Injection: How Tool-Calling Agents Get Hijacked

8 min read

Security

OAuth 2.1 for MCP: What the Spec Standardised and What You Need to Know

8 min read

Security

Sandboxing MCP Servers: Containers, Least Privilege, and Process Isolation

9 min read

Security

Least-Privilege Scoping for MCPs: How to Grant the Smallest Useful Permission

7 min read

Setup Guide

Best MCP Servers for Databases in 2026 (Ranked + Setup)

10 min read

Setup Guide

Best MCP Servers for Research in 2026 (Search, Scrape, Synthesize)

9 min read

Setup Guide

Best MCP Servers for Design-to-Code in 2026 (Figma → React)

9 min read

Setup Guide

Best MCP Servers for Domains in 2026 (Registrars + DNS)

9 min read

Tutorial

How to Buy a Domain From Claude (Cloudflare MCP, Step by Step)

6 min read

Tutorial

How to Search for Domains With an AI Agent (Cross-Registrar Workflow)

7 min read