// {{ display_name }} MCP server — generated by mcpify. Do not hand-edit.

import { RateLimitExceededError } from './errors.js';

/** Sliding-window rate limiter: at most `limit` calls per `windowMs` — REQ-2.3.3. */
export class RateLimiter {
  private timestamps: number[] = [];

  constructor(
    private readonly limit: number,
    private readonly windowMs: number = 1000,
  ) {}

  acquire(): void {
    const now = Date.now();
    this.timestamps = this.timestamps.filter((timestamp) => now - timestamp < this.windowMs);
    if (this.timestamps.length >= this.limit) {
      throw new RateLimitExceededError();
    }
    this.timestamps.push(now);
  }
}
