#!/usr/bin/env tsx /** * MCP Adapter - Generic Model Context Protocol Integration * * Provides a unified interface for all MCP server integrations, * eliminating code duplication across different service adapters. * * Usage: * const adapter = new MCPAdapter('vercel', config) * await adapter.execute(request) */ export declare enum McpErrorCode { VALIDATION_ERROR = "VALIDATION_ERROR", NETWORK_ERROR = "NETWORK_ERROR", TIMEOUT_ERROR = "TIMEOUT_ERROR", CONFIG_ERROR = "CONFIG_ERROR" } export declare class McpError extends Error { code: McpErrorCode; constructor(message: string, code: McpErrorCode); } /** * Dispose all active MCP adapters (cleanup on shutdown) */ export declare function disposeAllAdapters(): void; export interface MCPRequest { action: string; parameters?: Record; options?: { timeout?: number; retries?: number; dryRun?: boolean; /** Idempotency key to prevent duplicate operations */ idempotencyKey?: string; /** TTL for idempotency cache in milliseconds (default: 5 minutes) */ idempotencyTTL?: number; }; } export interface MCPResponse { success: boolean; data?: unknown; error?: string; metadata?: { duration: number; retries: number; service: string; /** Indicates this response was served from idempotency cache */ cached?: boolean; /** The idempotency key that was used */ idempotencyKey?: string; }; } /** * Persistent backend for idempotency cache. * Implementations handle their own TTL expiration for stored entries. */ export interface IdempotencyStore { get(key: string): Promise<{ response: MCPResponse; expiresAt: number; } | null>; set(key: string, response: MCPResponse, ttlMs: number): Promise; delete(key: string): Promise; } /** * In-memory idempotency cache for preventing duplicate operations. * Each adapter instance has its own cache. Optionally backed by a * persistent {@link IdempotencyStore} for cross-process durability. */ declare class IdempotencyCache { private cache; private store; private cleanupInterval; private readonly DEFAULT_TTL; constructor(store?: IdempotencyStore); /** * Get a cached response by idempotency key. * Checks memory first, then falls through to the persistent store. */ get(key: string): Promise; /** * Store a response with idempotency key. * Writes to both memory and the persistent store (if configured). */ set(key: string, response: MCPResponse, ttl?: number): void; /** * Check if a key exists in the cache */ has(key: string): boolean; /** * Remove expired entries (memory only - store manages its own TTL) */ private cleanup; /** * Clear all cached entries */ clear(): void; /** * Stop the cleanup interval */ dispose(): void; /** * Get cache statistics */ stats(): { size: number; keys: string[]; }; } export interface MCPConfig { apiKey?: string; baseUrl?: string; timeout?: number; retries?: number; environment?: 'development' | 'production'; } export declare abstract class MCPAdapter { protected serviceName: string; protected config: MCPConfig; protected logger: import("@revealui/utils/logger").Logger; protected idempotencyCache: IdempotencyCache; constructor(serviceName: string, config: MCPConfig); /** * Dispose of adapter resources (cleanup idempotency cache) */ dispose(): void; /** * Get idempotency cache statistics */ getCacheStats(): { size: number; keys: string[]; }; /** * Clear the idempotency cache */ clearCache(): void; /** * Execute an MCP request * * If an idempotencyKey is provided in options, the request will be checked * against the cache. If a cached response exists, it will be returned * immediately. Otherwise, the request will be executed and the response * will be cached for future duplicate requests. */ execute(request: MCPRequest): Promise; /** * Validate the incoming request */ protected validateRequest(request: MCPRequest): void; /** * Check if an action is supported by this adapter */ protected abstract isValidAction(action: string): boolean; /** * Execute the actual request (implemented by subclasses) */ protected abstract executeRequest(request: MCPRequest): Promise; /** * Create a dry-run response */ protected createDryRunResponse(request: MCPRequest): MCPResponse; /** * Get authentication headers for API calls */ protected getAuthHeaders(): Record; /** * Get the authentication header name for this service */ protected abstract getAuthHeaderName(): string; /** * Make an HTTP request with proper error handling */ protected makeRequest(method: 'GET' | 'POST' | 'PUT' | 'DELETE', url: string, data?: unknown): Promise; } /** * Generate an idempotency key based on the request content. * * This creates a deterministic key from the action and parameters, * so identical requests will get the same key. * * @example * ```typescript * const key = generateIdempotencyKey({ * action: 'deploy', * parameters: { projectId: '123' } * }) * // Returns: "deploy:a1b2c3d4e5f6..." * ``` */ export declare function generateIdempotencyKey(request: MCPRequest): string; /** * Generate a unique idempotency key with timestamp. * * Use this when you want each request to be unique but still * want idempotency protection against rapid duplicate submissions. * * @example * ```typescript * const key = generateUniqueIdempotencyKey('deploy') * // Returns: "deploy:1706536800000:a1b2c3d4" * ``` */ export declare function generateUniqueIdempotencyKey(action: string): string; export {}; //# sourceMappingURL=adapter.d.ts.map