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-usage-control

v1.3.0

Published

Concurrency-safe usage enforcement primitives for MCP tool execution.

Readme

mcp-usage-control

Core package for concurrency-safe MCP usage enforcement. MCP and storage vendor independent.

Distribution: Check the current published version on npm and find verified source artifacts on GitHub Releases. For an unreleased source candidate or local tarballs, follow Use from source.

English

The current core provides policy quoting, atomic multi-budget admission, pending -> cost-liable transitions, renewable leases, explicit settlement, scoped idempotency, provider-neutral observability hooks, reusable Store conformance support, and MemoryUsageStore as the process-local reference implementation.

reserve -> markLiable -> execute -> settle
             ^             |
             |--- renew ---|

A quote can apply several budgets to one invocation. Every budget reserves atomically or none does. Replay protection is scoped by (tenantId, principal.id, tool, operationId) and settled tombstones default to 24 hours in the reference store.

On successful UsageControl.reserve(), the admission result includes both the lease and authoritative remainingByBudget. Consumers should not recompute remaining capacity from configured limits. Budget keys can be application-sensitive/high-cardinality, so expose or label them only under an explicit application policy.

const admission = await control.reserve(request);
if (admission.allowed) {
  console.log(admission.remainingByBudget);
  await admission.lease.markLiable();
}

Pending expiry releases every participating budget. Cost-liable expiry conservatively keeps the full charge so a crash after execution starts cannot become a refund.

Long-running MemoryUsageStore

MemoryUsageStore remains process-local, but controlled long-running single-process deployments can bound retained state:

const store = new MemoryUsageStore({
  maxRetainedOperations: 100_000,
  maxRetainedBudgetKeys: 100_000,
});

Capacity exhaustion raises MemoryUsageStoreCapacityError and fails closed instead of silently evicting accounting/replay state. store.stats() exposes retained-state counts. store.retireBudgetKey(key) explicitly retires a completed accounting-window key and rejects keys still referenced by active reservations; the application owns the decision that the window is permanently over and the key will not be reused.

See Memory store operations. For horizontal scale or restart durability, use a provider-backed shared Store.

UsageControl can receive an optional UsageObserver and explicit metadata. Observer delivery is best-effort, returned promises are not awaited, and observer failures can never change enforcement state. onEvent() itself is invoked inline, so keep synchronous work lightweight. Tool arguments and raw exception messages are not captured automatically.

For low-cardinality operational logs, projectUsageEvent() converts raw lifecycle events into a bounded shape that excludes identity IDs, reservation IDs, tool/budget identifiers, arbitrary outcomes, and application-defined denial text by default.

Operational helper subpaths (v0.10)

The v0.10 operational surface is exposed through explicit subpaths so it remains separate from the authoritative Store contract:

  • mcp-usage-control/operational — bounded process-local lifecycle snapshots, static runtime identity, and explicit scoped quota projection.
  • mcp-usage-control/settlement-outcomes — canonical settlement vocabulary, finite alias normalization, and bounded invalid_settlement_outcome diagnostics.
  • mcp-usage-control/thresholds — pure absolute/percentage remaining-threshold evaluation and above -> reached crossing detection.

These helpers never infer accounting windows, entitlement, pricing, refund eligibility, or provider health policy. See Operational usability.

Authentication, payments/billing, MCP SDK integration, and provider-backed production storage belong outside this package.

日本語

current coreはpolicy quote、atomic multi-budget admission、pending -> cost-liable transition、renewable lease、explicit settlement、scoped idempotency、provider-neutral observability hook、再利用可能なStore conformance support、process-local reference implementationの MemoryUsageStore を提供します。

reserve -> markLiable -> execute -> settle
             ^             |
             |--- renew ---|

1 invocationへ複数budgetを適用でき、全budgetをatomicにreserveするか、どれもreserveしません。replay protectionは (tenantId, principal.id, tool, operationId) 単位で、reference storeのsettled tombstone defaultは24時間です。

UsageControl.reserve() 成功時のadmission resultには lease とauthoritativeな remainingByBudget の両方が含まれます。consumer側でconfigured limitからremainingを再計算しないでください。budget keyにはapplication-sensitive / high-cardinalityな値が含まれ得るため、公開やmetric label化は明示的なapplication policyの下でだけ行います。

const admission = await control.reserve(request);
if (admission.allowed) {
  console.log(admission.remainingByBudget);
  await admission.lease.markLiable();
}

pending expiryは全budgetを解放し、cost-liable expiryはexecution開始後crashがrefundにならないようfull chargeを保守的に維持します。

MemoryUsageStore の長期運用

MemoryUsageStore はprocess-localのままですが、管理されたlong-running single-process deploymentではretained stateをbounded化できます。

const store = new MemoryUsageStore({
  maxRetainedOperations: 100_000,
  maxRetainedBudgetKeys: 100_000,
});

capacity exhaustion時はaccounting / replay stateをsilent evictionせず MemoryUsageStoreCapacityError でfail closedします。store.stats() でretained-state数を確認できます。store.retireBudgetKey(key) は終了済みaccounting-window keyを明示退役し、active reservation参照中のkeyはrejectします。windowが永久に終了し、そのkeyを同じwindowとして再利用しないという判断はapplication側が所有します。

詳しくは Memory Storeの長期運用。horizontal scaleやrestart durabilityが必要ならprovider-backed shared Storeを使います。

UsageControl へoptionalな UsageObserver と明示metadataを渡せます。observer deliveryはbest-effortで、返されたPromiseをawaitせず、observer failureがenforcement stateを変更することはありません。onEvent() 自体はinlineで呼ばれるため同期処理は軽量にしてください。tool argumentsやraw exception messageは自動収集しません。

low-cardinalityな運用logには projectUsageEvent() を使えます。raw lifecycle eventからidentity ID、reservation ID、tool / budget identifier、任意outcome、application定義denial textをdefaultで除外したbounded shapeへ変換します。

Operational helper subpath (v0.10)

v0.10のoperational surfaceはauthoritative Store contractと分離した明示subpathとして公開します。

  • mcp-usage-control/operational — bounded process-local lifecycle snapshot、static runtime identity、明示scopeしたquota projection。
  • mcp-usage-control/settlement-outcomes — canonical settlement vocabulary、finite alias normalization、boundedな invalid_settlement_outcome diagnostic。
  • mcp-usage-control/thresholds — absolute / percentage remaining threshold評価と above -> reached crossing detectionのpure helper。

これらはaccounting window、entitlement、pricing、refund可否、provider health policyを推測しません。詳しくは Operational usability。

authentication、payment / billing、MCP SDK integration、provider-backed production storageはこのpackageの責務外です。

Atomic vector usage (v0.7)

For one logical operation that consumes unlike units, use VectorUsagePolicy + VectorUsageControl with a Store that implements optional VectorUsageStore. Each dimension keeps its own units and hierarchical budgets; unlike units are never summed. Vector admission, progressive growth, expiry/recovery, and settlement are atomic across the complete dimension set.

Store authors can validate the optional capability with runVectorUsageStoreConformance() from mcp-usage-control/conformance.

Operation reconciliation (v0.8)

OperationReconciliationStore is the optional scalar read capability, and v0.13 adds the parallel VectorOperationReconciliationStore capability for initial vector-reserve acknowledgement ambiguity. MemoryUsageStore implements both. The conformance subpath exports scalar and vector reconciliation conformance helpers for third-party Stores. Unknown or unprovable state rejects and remains fail closed; reconciliation never authorizes business replay. Cloudflare remains an explicit scalar-only remote reconciliation exception. See Operation reconciliation/status.