Skip to main content

Crate mcp_usage_kit

Crate mcp_usage_kit 

Source
Expand description

Tower metering for rmcp Streamable HTTP servers.

This is the small public facade intended for application dependencies. It re-exports the protocol semantics, billing pipeline, and edge configuration so an application needs only one cargo add.

use std::sync::Arc;
use mcp_usage_kit::{EdgeConfig, InMemoryTenantStore, MeterLayer, Tenant};

let tenants = Arc::new(InMemoryTenantStore::new());
tenants.insert_unchecked("development-key", Tenant::new("acme", "cus_acme"));
let metered = MeterLayer::new(EdgeConfig::new(tenants)).layer(rmcp_service);

Re-exports§

pub use mcp_usage_core as core;
pub use mcp_usage_export as export;
pub use mcp_usage_tower as tower;
pub use mcp_usage_store as store;

Structs§

AggregatedUsage
One pre-aggregated provider event ready for export.
Billable
A charge to record against a tenant.
BillingPipeline
Coordinates a UsageBuffer with an off-path exporter.
Call
The call being priced, as known from its (trusted) headers.
ClassifiedCall
Validated identity shared by pricing and metering.
CompositeExporter
Fan-out exporter for logs, billing, analytics, and audit sinks.
DeferredCompletions
Queue of terminal accounting waiting for somewhere to await.
EdgeConfig
Runtime configuration shared by every cloned metering service.
EdgeMetrics
Process-local edge counters.
FnExporter
Adapter for an application-owned async export function.
InMemoryTaskStore
Process-local task attribution for an embedded server.
InMemoryTenantStore
Mutable in-memory tenant table for development and embedded deployments.
Limits
Tenant limits. None means unbounded.
LogExporter
Stateless exporter that emits structured log events.
MeterEventDeadLetter
A meter event that needs application-owned reconciliation.
MeterEventExporter
Exports pre-aggregated usage through an application-supplied provider.
MeterEventProviderError
Sanitized batch-wide provider failure without per-event outcomes.
MeterLayer
Tower layer that installs MeterService.
MeterService
Service produced by MeterLayer.
MetricsSnapshot
Point-in-time metric values.
NoopRecorder
Shared, no-op recorder for deployments that want attribution metrics only.
OpenTelemetryMetrics
Registration guard for the OpenTelemetry observable instruments.
PriceBook
Per-name unit pricing with a fallback.
TaskAttribution
Pre-priced durable-task attribution without the original name or URI.
Tenant
Authenticated tenant configuration used by the edge.
Usage
Usage already committed in the current window.
UsageBuffer
Thread-safe in-memory aggregator with bounded idempotency memory.
UsageEvent
One delivered unit event emitted by the request path.

Enums§

Charge
The verdict.
Classification
The outcome of looking at the request headers alone.
CredentialError
Missing or ambiguous tenant credentials.
EdgeConfigError
Invalid edge configuration.
ExportError
Provider export failure.
FreeReason
Why a call was not billed. Kept specific so an operator answering “why is my bill lower than my request count” gets a real answer from the metrics.
LimitDecision
Successful reservation or the reason admission was denied.
LimitReason
Why a usage reservation was rejected.
MeterEventDeadLetterReason
Why a meter event was quarantined for reconciliation.
MeterEventOutcome
The provider’s final or retryable disposition for one meter event.
Method
A method named in the Mcp-Method header.
RecordError
Recording failures are internal synchronization failures only.
RecordOutcome
Result of attempting to record an event.
RetryPolicy
Ordering required when retrying a failed export.
TaskOriginKind
Non-identifying method category retained for a durable task.
TaskStoreError
A sanitized durable-task store failure.
WeakApiKey
Why an API key was refused as too weak to be safe.

Constants§

API_KEY_HEADER
API-key header accepted in addition to Authorization: Bearer.
METHOD_HEADER
Mirrored JSON-RPC method request header.
MIN_API_KEY_BYTES
Shortest API key accepted by validate_api_key_strength.
NAME_HEADER
Mirrored tool, prompt, or resource name request header.
PROTOCOL_VERSION_HEADER
Standard protocol-version request header.

Traits§

BatchExporter
Exports a prepared batch away from the request path.
MeterEventProvider
Submits ordered batches of pre-aggregated usage to a billing provider.
TaskAttributionStore
Persists pre-priced, non-identifying attribution under a durable task ID.
TenantStore
Resolves a presented high-entropy API key without retaining its plaintext.
UsageRecorder
A synchronous usage sink suitable for the HTTP hot path.

Functions§

assess_limits
Atomically assess a proposed usage increment against quota and spend caps.
classify_request_headers
Validate unique protocol headers before authenticating or reading a body.
decide
Decide what a completed request/response exchange is worth.
decide_with_task_attribution
Decide an exchange using pre-priced, non-identifying task attribution.
decide_with_task_origin
Decide an exchange while supplying the call that created a polled task.
extract_api_key
Extract exactly one API key or Bearer credential.
hash_api_key
SHA-256 lookup hash for an API key.
install_opentelemetry
Register low-cardinality observable counters with an application-owned meter.
validate_api_key_strength
Reject API keys that are obviously too weak to be compared by digest.

Type Aliases§

ExportFuture
Boxed future returned by object-safe billing exporters.
MeterBody
Response body returned by MeterService.
MeterEventProviderFuture
Boxed future returned by a meter event provider.
SharedExporter
Convenient trait-object alias for composing exporters at runtime.
SharedRecorder
Convenient trait-object alias used by the edge layer.
TaskStoreFuture
Boxed future returned by object-safe task stores.