/** * Idempotency Cache for MCP Mutation Tools * * Prevents duplicate frames from being created when AI agents retry tool calls * due to network flakiness or tooling issues. Based on request_id. * * Design: * - In-memory cache with configurable TTL (default: 24 hours) * - Stores complete MCPResponse for each request_id * - Automatic cleanup of expired entries on get/set operations * - Thread-safe for single-process MCP servers * * Inspired by LexSona's MCP idempotency pattern. */ import type { MCPResponse } from "./server.js"; /** * Idempotency cache for MCP mutation tools */ export declare class IdempotencyCache { private cache; private readonly ttlMs; /** * Create a new idempotency cache * @param ttlMs Time-to-live in milliseconds (default: 24 hours) */ constructor(ttlMs?: number); /** * Get cached response for a request_id * @param requestId The request ID to look up * @returns Cached response if found and not expired, undefined otherwise */ getCached(requestId: string): MCPResponse | undefined; /** * Store a response in the cache * @param requestId The request ID to cache * @param response The MCP response to cache */ setCached(requestId: string, response: MCPResponse): void; /** * Remove all expired entries from the cache * Called automatically on get/set operations */ private clearExpired; /** * Get current cache size (for debugging/testing) */ size(): number; /** * Clear all cached entries (for testing) */ clear(): void; }