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

@meter-mcp/sdk

v0.2.0

Published

Server-side SDK for Meter prepaid credits and MCP usage billing

Readme

@meter-mcp/sdk

Server-side TypeScript SDK for Meter prepaid credits, usage billing, hosted buyer portals, service onboarding, and provider webhooks.

Requirements

  • Node.js 20 or newer
  • A Meter service ID and server-side service API key

Never expose a service API key in browser code.

Both ESM import and CommonJS require are supported.

Install

npm install @meter-mcp/sdk

Meter a unit of work

import { MeterPublicApiClient } from "@meter-mcp/sdk";

const meter = new MeterPublicApiClient({
  baseUrl: process.env.METER_API_URL!,
  serviceId: process.env.METER_SERVICE_ID!,
  serviceApiKey: process.env.METER_SERVICE_API_KEY!,
  timeoutMs: 10_000,
});

const result = await meter.withUsage(
  {
    customerLocalId: "customer_123",
    tool: "knowledge_search",
    credits: 8,
    providerId: "creator:alice",
    productId: "vault_1",
  },
  () => searchKnowledge()
);

withUsage creates one request ID, reserves credits, runs the protected work, commits usage on success, and releases the reservation when the work throws. Supply your own requestId when retrying work across process boundaries.

Track AI cost and gross margin

AI usage is attached only when protected work succeeds and Meter commits the billing transaction. Resolve it from the provider response:

import { aiUsageFromOpenAI } from "@meter-mcp/adapters";

await meter.withUsage(usage, callOpenAI, {
  aiUsage: (response) => aiUsageFromOpenAI(response, {
    pricing: {
      inputPerMillionUsd: 2,
      outputPerMillionUsd: 8,
      cachedInputPerMillionUsd: 0.5,
      version: "provider-price-sheet-2026-07-11",
    },
  }),
});

Use costUsd when the AI provider or gateway returns actual billed cost. Meter stores micro-USD integers and distinguishes reported, calculated, and unpriced usage. Prices are supplied explicitly instead of silently pinned in the SDK, so provider price changes remain auditable.

For integrations that cannot attach pricing on every request, configure a service-scoped fallback with upsertAiModelPrice. Meter versions and retains these prices and applies the latest effective version only to unpriced usage.

Handle billing errors

import {
  isMeterPaymentRequiredPayload,
  MeterPublicApiError,
  MeterTimeoutError,
} from "@meter-mcp/sdk";

try {
  await meter.authorize({
    customerLocalId: "customer_123",
    tool: "knowledge_search",
    credits: 8,
    requestId: crypto.randomUUID(),
  });
} catch (error) {
  if (error instanceof MeterPublicApiError && isMeterPaymentRequiredPayload(error.body)) {
    return Response.redirect(error.body.topUpUrl, 303);
  }
  if (error instanceof MeterTimeoutError) {
    // The request outcome is unknown. Retry with the same request ID.
  }
  throw error;
}

Hosted portal and operator console

const portal = await meter.createPortalSession("customer_123", {
  origin: "https://provider.example",
});

const consoleSession = await meter.createOperatorSession({
  externalSubject: "user_42",
  email: "[email protected]",
  role: "owner",
  origin: "https://provider.example",
});

Use @meter-mcp/adapters to expose these as authenticated Fetch, Next.js, Hono, or Express handlers.

Gateway integration

Register an existing MCP server without changing each tool implementation:

const integration = await meter.updateIntegration({
  gatewayEnabled: true,
  upstreamUrl: "https://mcp.provider.example/mcp",
  upstreamAuthMode: "oauth_client_credentials",
  oauthTokenUrl: "https://auth.provider.example/oauth/token",
  oauthClientId: process.env.UPSTREAM_CLIENT_ID!,
  oauthClientSecret: process.env.UPSTREAM_CLIENT_SECRET!,
  oauthScopes: ["mcp:invoke"],
  customerAuthMode: "jwt",
  jwtIssuer: "https://auth.provider.example/",
  jwksUrl: "https://auth.provider.example/.well-known/jwks.json",
  jwtAudience: "meter-mcp",
  autoProvisionCustomers: true,
  defaultCredits: 1,
  toolPrices: { knowledge_search: 8, read_document: 3 },
});

console.log(integration.gatewayUrl);

Verify provider webhooks

Read the raw request body before JSON parsing.

import { verifyMeterWebhookSignature } from "@meter-mcp/sdk";

const payload = await request.text();
await verifyMeterWebhookSignature({
  payload,
  signature: request.headers.get("x-meter-signature") ?? "",
  secret: process.env.METER_WEBHOOK_SECRET!,
});
const event = JSON.parse(payload);

The default timestamp tolerance is five minutes. Store the event ID and process events idempotently because deliveries are retried.

Error model

  • MeterPublicApiError: Meter returned a non-2xx HTTP response.
  • MeterTimeoutError: the configured timeout elapsed; the server outcome may be unknown.
  • MeterNetworkError: no HTTP response was received.
  • MeterWebhookSignatureError: webhook verification failed.

See the SDK API reference and examples for the complete integration surface.

License

MIT