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.
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. |
Installation
Install from PyPI after the first release:
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.
Metadata
Release files for ClaudeMCPGuard 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| claudemcpguard-0.1.0.tar.gz | 8.5 kB | Without provenance | Details for claudemcpguard-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| claudemcpguard-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for claudemcpguard-0.1.0-py3-none-any.whl |
Total release size: 16.4 kB
Release files / claudemcpguard-0.1.0.tar.gz
| Download URL | claudemcpguard-0.1.0.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
577fe3e16a9f8d1a52c8338bd625656ca6ec8d765c4442c25c50818b2cb8295b
|
|
BLAKE2b-256 checksum How to use checksums |
650d109bdb2c496f44f0281ab38ca326973e561a845b42acfb8afd02be55bc95
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.12
|
Release files / claudemcpguard-0.1.0-py3-none-any.whl
| Download URL | claudemcpguard-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
623a0067300ab2a90434abb2711f9eb88f265c68617029eaec3abc8e89721f18
|
|
BLAKE2b-256 checksum How to use checksums |
8860b4da91c3594087c475af377c9b9dfdd337148b811c54eff6e9032d806cfb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.12
|
Security for ClaudeMCPGuard 0.1.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.