dome-throttle
Token-bucket rate limiting and budget tracking for MCPDome.
What it does
- Provides
RateLimiterwith global, per-identity, and per-tool token-bucket rate limiting, using DashMap for lock-free concurrent access. - TOCTOU-safe bucket access — uses DashMap's
entry()API for atomic get-or-insert, eliminating race conditions in concurrent bucket creation. - LRU eviction with TTL — DashMap entries are automatically cleaned up when the map exceeds
max_entries, preventing unbounded memory growth from unique identity/tool combinations. - Provides
BudgetTrackerfor cumulative spend tracking per identity with configurable rolling time windows, caps, and TTL-based eviction. - Returns
DomeError::RateLimitedorDomeError::BudgetExhaustedon violation, allowing the interceptor chain to block and audit the request. - Supports configurable bucket sizes, refill rates, global limits, and budget limits via
RateLimiterConfigandBudgetTrackerConfig.
Usage
[]
= "0.4"
use ;
let limiter = new;
limiter.check_rate_limit?;
Part of MCPDome
This crate is part of MCPDome, a security gateway for the Model Context Protocol. See the main repository for full documentation.
License
Apache-2.0