Skip to main content

MCP Key Rotator

CI License: MIT Python 3.11+

Provider-agnostic API-key rotation and quota management for stdio, Streamable HTTP, and legacy HTTP+SSE MCP servers. One local session receives one credential and keeps it for that session's lifetime—no mid-session account changes and no automatic replay of tool calls.

v0.2.0 adds guided setup, AI-agent automation, an interactive dashboard, OS credential vault support, native HTTP transports, six client integrations, optional process-tree cleanup, and local structured telemetry.

Install in one prompt

Give an AI coding agent the prompt in docs/AI_AGENT_INSTALL.md. It installs the released package, detects supported clients and credential variable names, reuses existing upstream MCP servers, applies safe changes with backups, and runs offline diagnostics. It never needs credential values in chat.

Install manually

# Install uv first if needed: https://docs.astral.sh/uv/getting-started/installation/
uv tool install mcp-key-rotator
mkr setup

uv manages Python automatically. pipx install mcp-key-rotator and python -m pip install mcp-key-rotator are supported fallbacks. The guided wizard works on Windows, macOS, and Linux and does not require YAML editing.

See the illustrated installation guide for platform commands, credential vault setup, upgrades, and uninstall.

Everyday commands

Command Purpose
mkr Open the keyboard-accessible key-health dashboard.
mkr setup Guided setup with preview, backups, validation, and rollback.
mkr setup --agent --apply --json Noninteractive AI-agent setup; no secret prompts.
mkr doctor [--json] Offline diagnostics and plain-language repair guidance.
mkr status [--json] Redacted key health, eligibility, counters, cooldowns, and resets.
mkr keys ... List, add, reset, disable, enable, or reclassify keys.
mkr clients ... Detect, add, remove, or generate generic client configuration.
mkr config ... Locate, validate, or display redacted configuration.
mkr check PROVIDER Explicit read-only quota probe where supported; never automatic.
mkr run PROVIDER Session-pinned stdio connector used by client registrations.
mkr serve PROVIDER Advanced authenticated loopback Streamable HTTP endpoint.
mkr uninstall --yes Remove managed client entries; data removal is separately explicit.

Architecture

Stdio upstream

MCP client ── newline-delimited JSON-RPC ──► mkr run PROVIDER
                                                │ select once per client session
                                                │ inject only that key into a minimal environment
                                                ▼
                                      existing MCP server subprocess

Traffic is forwarded unchanged. Only JSON-RPC errors, failed MCP tool results, and optionally stderr are inspected for health. Successful tool content is not scanned.

HTTP upstream

mkr run connects stdio clients to Streamable HTTP or legacy HTTP+SSE upstreams. mkr serve exposes a Streamable HTTP upstream through an authenticated loopback Streamable HTTP listener. Concurrent local sessions have independent upstream sessions, pinned keys, and translated MCP-Session-Id values. Protocol versions and Last-Event-ID are forwarded.

The listener requires MKR_HTTP_TOKEN (or --auth-env NAME), rejects non-loopback clients, and validates Host and Origin headers. Prefer stdio when a client cannot securely configure HTTP authorization. See TRANSPORTS.md.

Safe defaults

  • Environment auto-detection or optional OS credential-vault storage; no secrets in generated YAML, client JSON, logs, backups, telemetry, or AI chats.
  • Persistent round-robin selection; random selection remains an advanced option.
  • SQLite WAL, short BEGIN IMMEDIATE transactions, migrations, lock timeouts, and crash-safe state transitions in the platform application-data directory.
  • Conservative distinction between resettable quota exhaustion, temporary rate limits, invalid authentication, billing/credit failures, transient failures, and unknown tool errors.
  • Provider reset timestamps, lazy derived resets, manual recovery, custom regex patterns, and optional read-only provider quota probes.
  • Built-in GitHub, OpenRouter, Tavily, Brave Search, and Exa adapters plus a versioned plugin SDK and offline contract-test kit.
  • Timestamped backups, atomic client/YAML writes, concurrent-edit refusal, idempotent setup, and complete per-invocation rollback.

Keys need independent quota pools for rotation to increase capacity. Multiple keys on one account may share credits or rate limits.

Configuration v2

A generated configuration can be as small as:

version: 2
providers:
  github:
    keys:
      - env: GITHUB_TOKEN_1
      - keyring: github/secondary
    server:
      command: github-mcp-server
      args: [stdio]

The adapter, credential injection name, strategy, state path, and reset policy have safe provider defaults. Generic providers specify credential_env; advanced stdio environment, process cleanup, HTTP headers, and quota patterns remain available when genuinely needed. See CONFIGURATION.md and examples/.

Configuration v2 is an intentional clean break from v0.1. Setup backs up legacy files before replacing them and never deletes existing SQLite health history. The v0.1 MVP remains available at tag v0.1.0.

Client compatibility

Automatic configuration is provided for OpenCode, Claude Code, Claude Desktop, Codex CLI, Cursor, and Gemini CLI. A generic JSON generator supports other clients. See the compatibility matrix for native paths, formats, and desktop validation boundaries.

Health semantics

Observation Stored effect Future sessions
Resettable spending/monthly quota exhausted exhausted with reset timestamp Excluded until reset or manual recovery
HTTP 429 / documented temporary limit Active with cooldown Temporarily skipped, not monthly exhausted
Invalid authentication invalid Excluded until recovery/replacement
Credit, billing, or nonresetting budget failure billing Excluded pending billing action
Transient provider failure Active with short cooldown Temporarily skipped
Unknown protocol/tool error No provider-specific transition Forwarded unchanged

A failure never switches the current session's key. mkr check is on demand because provider read endpoints can themselves be rate limited. Usage counters count observed MCP tool outcomes, not provider tokens or credits.

Telemetry and process cleanup

Set MKR_TELEMETRY=true and MKR_LOG_PATH=/private/path/events.jsonl to opt into local JSON operational events. Only allowlisted session lifecycle, key name, classification, return code, duration, transport, and termination reason fields are accepted. There is no hosted metrics service or mandatory daemon.

Set server.cleanup_tree: true after compatibility testing to place stdio children in a POSIX process group or Windows job/tree. The default remains direct-child supervision.

Limitations

  • Stdio uses newline-delimited JSON-RPC, as required by the supported MCP stdio transport.
  • No automatic request replay, reconnect, or cross-key retry: a disconnected or failed tool call may already have executed or incurred cost.
  • HTTP resumption delegates event replay to the upstream server; the proxy does not maintain its own event cache.
  • mkr serve currently requires an HTTP upstream; use mkr run for stdio upstreams.
  • OAuth-only remote MCP authorization is not converted into static API-key rotation.
  • Error detection depends on upstream servers preserving useful error details.
  • Desktop clients require a restart and some cannot be launched automatically in CI.

Development and verification

python -m pip install -e ".[dev]"
ruff check .
python -m unittest discover -v
python -m build

Tests use local mocks and subprocesses only; normal CI makes no paid provider calls. The release pipeline covers Windows/macOS/Linux, Python 3.11–3.14, exact-wheel uv/pipx installs, secret and dependency scans, package/Docker execution, SBOMs, and provenance attestations.

See CONTRIBUTING.md, ARCHITECTURE.md, PROVIDERS.md, SECURITY.md, RELEASING.md, and CHANGELOG.md. An optional Docker image is included; host installation is generally simpler when wrapping other local runtimes.

License

MIT

Metadata

Release files for mcp-key-rotator 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-key-rotator 0.2.0
File Size Uploaded Provenance Actions
mcp_key_rotator-0.2.0.tar.gz 123.5 kB With provenance Details for mcp_key_rotator-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mcp-key-rotator 0.2.0
File Interpreter ABI Platform Actions
mcp_key_rotator-0.2.0-py3-none-any.whl Python 3 none any Details for mcp_key_rotator-0.2.0-py3-none-any.whl

Total release size: 202.8 kB

Release files / mcp_key_rotator-0.2.0.tar.gz

Download URL mcp_key_rotator-0.2.0.tar.gz
Size 123.5 kB
Tags Source
SHA-256 checksum
How to use checksums
58c02beb0b1ba68fcc90819b1b1b8dbcdc7b09c02244ae2ef4e259c751b4428b
BLAKE2b-256 checksum
How to use checksums
4ee6fcc2a866d3a981265ba08e90b9d369c3238886000fcfe7830b8ea1bf6423
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

Release files / mcp_key_rotator-0.2.0-py3-none-any.whl

Download URL mcp_key_rotator-0.2.0-py3-none-any.whl
Size 79.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1c606b989a1eb3341164a054a2487b6c30f8c5e3d3d41499cae1969de5f00c56
BLAKE2b-256 checksum
How to use checksums
99db650e791134e719daf9c8815f50910ebb75ceb70f8f843310c0a9d6a484ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

Security for mcp-key-rotator 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mcp_key_rotator-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page