Skip to main content
Glama

ClaudeMCPGuard

Resilience middleware for FastMCP.

ClaudeMCPGuard improves MCP tool reliability with bounded retries, exponential backoff, per-tool timeouts, structured JSON logs, and an optional circuit breaker.

Python FastMCP License

Installation · Usage · Configuration · Development

Overview

Capability

Description

Bounded retries

Retry failed calls with configurable exponential backoff and a maximum attempt count.

Per-tool timeouts

Set a default timeout and override it for individual tools.

Structured logging

Emit one JSON record per completed tool call, including duration and attempt count.

Circuit breaker

Temporarily block calls after repeated failures and allow a recovery probe.

Typed package

Ship typing information and support Python 3.10 and newer.

Privacy-conscious logs

Exclude tool arguments and result payloads from log records.

Related MCP server: FastMCP Python Boilerplate

Installation

Install the published distribution from PyPI:

python -m pip install ClaudeMCPGuard

The distribution is named ClaudeMCPGuard. The Python import package remains mcp_guard.

For development:

git clone https://github.com/Nawfel1235/ClaudeMCPGuard.git
cd ClaudeMCPGuard
python -m pip install -e ".[dev]"

Quick start

from fastmcp import FastMCP
from mcp_guard import MCPGuard

mcp = FastMCP("example")
mcp.add_middleware(MCPGuard())

@mcp.tool
async def lookup_user(user_id: str) -> dict[str, str]:
    return {"user_id": user_id, "status": "active"}

if __name__ == "__main__":
    mcp.run()

Configuration

from fastmcp import FastMCP
from mcp_guard import MCPGuard, MCPGuardConfig

mcp = FastMCP("production-tools")
mcp.add_middleware(
    MCPGuard(
        MCPGuardConfig(
            max_attempts=4,
            initial_delay=0.2,
            backoff_multiplier=2.0,
            timeout_seconds=20.0,
            tool_timeouts={"slow_report": 60.0, "no_timeout": None},
            breaker_failure_threshold=5,
            breaker_recovery_timeout=30.0,
        )
    )
)

Options

Option

Default

Description

max_attempts

3

Total attempts, including the first call.

initial_delay

0.25

Initial retry delay, in seconds.

backoff_multiplier

2.0

Multiplier applied after each failed attempt.

timeout_seconds

30.0

Default timeout. Set to None to disable it.

tool_timeouts

{}

Per-tool timeout overrides. A value of None disables the timeout for that tool.

breaker_failure_threshold

None

Consecutive failed calls required to open the circuit. Disabled when None.

breaker_recovery_timeout

30.0

Seconds before the circuit allows a recovery probe.

Retries apply to exceptions raised by the downstream FastMCP pipeline. A timeout counts as a failed attempt. The circuit breaker counts one failed tool call after retries are exhausted. Cancellation is propagated and is never retried.

Important: Retries can repeat side effects. Enable them only for idempotent operations or tools protected by idempotency keys.

Structured logging

ClaudeMCPGuard uses Python's standard logging package and the logger named mcp_guard.

Example record:

{
  "tool_name": "lookup_user",
  "timestamp": "2026-11-29T20:00:00+00:00",
  "duration_seconds": 0.0142,
  "success": true,
  "attempts": 2
}

Failure records include an error field. Tool arguments and result payloads are intentionally excluded.

Claude Code skill

A ready-to-use skill is included at skills/SKILL.md. Copy it into your project at .claude/skills/mcp-guard/SKILL.md.

Compatibility

ClaudeMCPGuard targets FastMCP's public Middleware and MiddlewareContext APIs. The dependency range is fastmcp>=2.14,<4. Review FastMCP's middleware documentation when upgrading across major versions.

Development

python -m pip install -e ".[dev]"
pytest
ruff check .
mypy

License

Released under the MIT License. See LICENSE.

Maintained by Nawfel.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      An MCP server that enables Claude to manage infrastructure across Kubernetes, Docker, Prometheus, and Terraform through natural language. It provides over 42 specialized tools with a safety-first design, including risk-based command classification and audit logging.
      43
      MIT
    • A
      license
      A
      quality
      F
      maintenance
      Provides a production-ready FastMCP Python server boilerplate with structured logging, rate limiting, and config validation for building MCP servers compatible with Claude and other agents.
      2
      1
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      A FastMCP server that enables AI engineers to run a production-ready MCP endpoint with in-memory token-bucket rate limiting and strict Pydantic v2 input validation. It connects to Claude Desktop, Cursor, and custom agent runners over stdio for safe tool execution.
      1
      MIT
    • F
      license
      Not graded
      quality
      B
      maintenance
      This MCP server wraps agent tool calls with fault-tolerant retry logic, including adaptive exponential backoff, full jitter, 429 rate-limit backpressure handling, and circuit breaker patterns. It enables autonomous agents to execute tools reliably without frontier LLM round-trips, using a zero-dependency Python stdio JSON-RPC interface.
      7
      -