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§
- Aggregated
Usage - One pre-aggregated provider event ready for export.
- Billable
- A charge to record against a tenant.
- Billing
Pipeline - Coordinates a
UsageBufferwith an off-path exporter. - Call
- The call being priced, as known from its (trusted) headers.
- Classified
Call - Validated identity shared by pricing and metering.
- Composite
Exporter - Fan-out exporter for logs, billing, analytics, and audit sinks.
- Deferred
Completions - Queue of terminal accounting waiting for somewhere to await.
- Edge
Config - Runtime configuration shared by every cloned metering service.
- Edge
Metrics - Process-local edge counters.
- FnExporter
- Adapter for an application-owned async export function.
- InMemory
Task Store - Process-local task attribution for an embedded server.
- InMemory
Tenant Store - Mutable in-memory tenant table for development and embedded deployments.
- Limits
- Tenant limits.
Nonemeans unbounded. - LogExporter
- Stateless exporter that emits structured log events.
- Meter
Event Dead Letter - A meter event that needs application-owned reconciliation.
- Meter
Event Exporter - Exports pre-aggregated usage through an application-supplied provider.
- Meter
Event Provider Error - Sanitized batch-wide provider failure without per-event outcomes.
- Meter
Layer - Tower layer that installs
MeterService. - Meter
Service - Service produced by
MeterLayer. - Metrics
Snapshot - Point-in-time metric values.
- Noop
Recorder - Shared, no-op recorder for deployments that want attribution metrics only.
- Open
Telemetry Metrics - Registration guard for the OpenTelemetry observable instruments.
- Price
Book - Per-name unit pricing with a fallback.
- Task
Attribution - 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.
- Usage
Buffer - Thread-safe in-memory aggregator with bounded idempotency memory.
- Usage
Event - One delivered unit event emitted by the request path.
Enums§
- Charge
- The verdict.
- Classification
- The outcome of looking at the request headers alone.
- Credential
Error - Missing or ambiguous tenant credentials.
- Edge
Config Error - Invalid edge configuration.
- Export
Error - Provider export failure.
- Free
Reason - 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.
- Limit
Decision - Successful reservation or the reason admission was denied.
- Limit
Reason - Why a usage reservation was rejected.
- Meter
Event Dead Letter Reason - Why a meter event was quarantined for reconciliation.
- Meter
Event Outcome - The provider’s final or retryable disposition for one meter event.
- Method
- A method named in the
Mcp-Methodheader. - Record
Error - Recording failures are internal synchronization failures only.
- Record
Outcome - Result of attempting to record an event.
- Retry
Policy - Ordering required when retrying a failed export.
- Task
Origin Kind - Non-identifying method category retained for a durable task.
- Task
Store Error - A sanitized durable-task store failure.
- Weak
ApiKey - 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§
- Batch
Exporter - Exports a prepared batch away from the request path.
- Meter
Event Provider - Submits ordered batches of pre-aggregated usage to a billing provider.
- Task
Attribution Store - Persists pre-priced, non-identifying attribution under a durable task ID.
- Tenant
Store - Resolves a presented high-entropy API key without retaining its plaintext.
- Usage
Recorder - 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§
- Export
Future - Boxed future returned by object-safe billing exporters.
- Meter
Body - Response body returned by
MeterService. - Meter
Event Provider Future - Boxed future returned by a meter event provider.
- Shared
Exporter - Convenient trait-object alias for composing exporters at runtime.
- Shared
Recorder - Convenient trait-object alias used by the edge layer.
- Task
Store Future - Boxed future returned by object-safe task stores.