Unified retry/backoff decorators for MCP servers - tenacity presets for httpx/requests API calls
Project description
mcp-retry
Tiny, opinionated retry/backoff decorators for MCP servers and other API clients. A thin preset layer over tenacity: exponential backoff + jitter, retry on 429/5xx/network errors, log before each retry, re-raise on exhaustion.
Extracted from a fleet of production MCP servers (TikTok Shop, TikTok Ads, and others) so every server retries the same way instead of re-implementing tenacity incantations.
Install
pip install mcp-retry # core (tenacity only)
pip install "mcp-retry[httpx]" # + httpx preset
Usage
httpx-based MCP servers (async)
from mcp_retry import httpx_retry
@httpx_retry()
async def _do_request(self, url):
response = await client.get(url)
if response.status_code == 429 or response.status_code >= 500:
response.raise_for_status() # triggers retry
return response
Retries on httpx.RequestError (connection errors, timeouts, DNS failures) and httpx.HTTPStatusError. Only call raise_for_status() for status codes you want retried (429/5xx) — 4xx client errors should surface immediately.
requests-based projects (sync)
from mcp_retry import requests_retry
@requests_retry()
def fetch(url):
r = requests.get(url)
if r.status_code == 429 or r.status_code >= 500:
r.raise_for_status()
return r
Custom exceptions / tuning
from mcp_retry import api_retry
@api_retry(max_attempts=5, min_wait=2, retryable_exceptions=(MyTransientError,))
def fragile_call():
...
Defaults: 3 attempts, exponential wait 1–30 s plus 0–2 s random jitter, warning-level log before each sleep, reraise=True.
Why not just tenacity?
You should use tenacity — this is tenacity. mcp-retry just freezes one sane configuration (and the httpx/requests exception sets) behind a one-line decorator, so a dozen MCP servers stay consistent and a retry-policy change is a single-package bump instead of a dozen edits.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_retry-0.1.0.tar.gz.
File metadata
- Download URL: mcp_retry-0.1.0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dc30ba25b5fa55b8484361dd40cb5d5c09fb5414aa36223441e2e7f333753ea
|
|
| MD5 |
6120f2fac51051aa5d00dea6a8ecb26e
|
|
| BLAKE2b-256 |
0279dc71319b8c8bb3fd49c8ef25774d25cd59b14134b45d317c0fcfa6ec4406
|
File details
Details for the file mcp_retry-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mcp_retry-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e9f1ee83775c4a1d975ca945e4445b93509d8f9240280e1f079f1187dde56fc
|
|
| MD5 |
0817f5739fcd0e0c88bceb65bca9b0f5
|
|
| BLAKE2b-256 |
26ccf4a1b987b68e0a8b1800477c8f934bdcbd4602d32614b35e42bcebe6c0be
|