npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mcp-utils/retry

v1.0.0

Published

Retry with exponential backoff for MCP tool handlers — powered by vurb.

Readme

@mcp-utils/retry

npm License


External APIs fail. Networks are unreliable. A single transient error — a 503 from your payment gateway, a database connection blip — is enough to break the entire agent interaction.

LLM agents don't retry automatically. When your tool throws, the AI gives up.

Here's how to make your tools resilient in one line:

import { withRetry } from '@mcp-utils/retry';

// Before: one transient error = broken tool call = broken agent
handler: async (ctx, args) => success(await paymentApi.charge(args))

// After: survives failures, recovers automatically
handler: withRetry(
    async (ctx, args) => success(await paymentApi.charge(args)),
    { attempts: 3, backoff: 'exponential' }
)

Install

npm install @mcp-utils/retry

Usage

Exponential backoff (recommended for APIs)

import { withRetry } from '@mcp-utils/retry';

const chargePayment = withRetry(
    async (ctx, args) => success(await paymentApi.charge(args)),
    {
        attempts: 3,
        backoff: 'exponential', // 300ms → 600ms → 1200ms
        baseDelayMs: 300,
    },
);

Retry only when it makes sense

Don't retry auth failures or business logic errors — only transient failures:

const fetchData = withRetry(handler, {
    attempts: 5,
    retryOn: (err) => {
        if (err instanceof AuthError) return false;      // don't retry — permanent
        if (err instanceof RateLimitError) return true;  // retry — transient
        return isNetworkError(err);
    },
});

Shared policy across handlers

import { createRetry } from '@mcp-utils/retry';

const resilient = createRetry({ attempts: 3, backoff: 'exponential' });

const getUser = resilient(async (ctx, args) => success(await api.users.get(args['id'])));
const getOrg  = resilient(async (ctx, args) => success(await api.orgs.get(args['id'])));

Combine with timeout

import { withTimeout } from '@mcp-utils/timeout';

// Each attempt gets 5 seconds, up to 3 attempts
const handler = withRetry(
    withTimeout(
        async (ctx, args, _p, signal) => success(await api.call(args, signal)),
        5_000,
    ),
    { attempts: 3 },
);

API

withRetry(handler, options)

| Option | Type | Default | Description | |---|---|---|---| | attempts | number | 3 | Total attempts including the first | | backoff | 'exponential' \| 'linear' \| 'none' | 'exponential' | Delay strategy between attempts | | baseDelayMs | number | 300 | Base delay in milliseconds | | maxDelayMs | number | 10_000 | Maximum delay cap | | retryOn | (err, attempt) => boolean | always retry | Predicate controlling whether to retry |

  • Only thrown exceptions trigger a retry — isError: true domain errors are returned as-is
  • Stops between attempts if the request has been cancelled via AbortSignal
  • Returns a structured toolError with full diagnostic context after all attempts fail

createRetry(options)

Returns a decorator: (handler) => wrappedHandler. Same options as withRetry.


Part of @mcp-utils — production-grade utilities for MCP server development.

License

Apache-2.0