/** * Execute Tool With Cache Abstraction * * Generic caching wrapper for tools that follow the pattern: * 1. Check cache * 2. Execute GraphQL query on cache miss * 3. Validate result (optional) * 4. Transform result (optional) * 5. Cache and return * * Eliminates code duplication across 10+ tools with caching logic. */ import { CallToolResult } from '@modelcontextprotocol/sdk/types.js'; import { ServiceContainer } from '../core/container.js'; /** * Cache key generator function */ export type CacheKeyGenerator = (input: TInput) => string; /** * GraphQL variables mapper function */ export type VariablesMapper = (input: TInput) => TVariables; /** * Result validator function */ export interface ValidationResult { valid: boolean; message?: string; isError?: boolean; } export type ResultValidator = (data: TOutput) => ValidationResult; /** * Result transformer function */ export type ResultTransformer = (data: TOutput) => TTransformed; /** * Configuration for cached tool execution */ export interface CachedToolOptions { /** Service container with dependencies */ container: ServiceContainer; /** Cache key generator from input */ cacheKey: CacheKeyGenerator; /** Cache TTL in seconds */ cacheTTL: number; /** GraphQL query string */ query: string; /** Map input to GraphQL variables */ variables: VariablesMapper; /** Validate query result (optional) */ validateResult?: ResultValidator; /** Transform result before caching/returning (optional) */ transformResult?: ResultTransformer; /** Tool name for error reporting */ toolName: string; } /** * Create a cached tool executor * * Returns an async function that executes the tool with caching logic. * * @example * ```typescript * const executeGetVaultData = executeToolWithCache({ * container, * cacheKey: (input) => cacheKeys.vaultData(input.vaultAddress, input.chainId), * cacheTTL: cacheTTL.vaultData, * query: GET_VAULT_DATA_QUERY, * variables: (input) => ({ address: input.vaultAddress, chainId: input.chainId }), * validateResult: (data) => ({ * valid: !!data.vaultByAddress, * message: data.vaultByAddress ? undefined : 'Vault not found', * }), * toolName: 'get_vault_data', * }); * ``` */ export declare function executeToolWithCache(options: CachedToolOptions): (input: TInput) => Promise; /** * Create a simple cached tool executor without validation or transformation * * Simplified version for tools that don't need validation or transformation. * * @example * ```typescript * const executeSimpleTool = createSimpleCachedTool({ * container, * cacheKey: (input) => `tool:${input.id}`, * cacheTTL: 300, * query: SIMPLE_QUERY, * variables: (input) => ({ id: input.id }), * toolName: 'simple_tool', * }); * ``` */ export declare function createSimpleCachedTool(options: Omit, 'validateResult' | 'transformResult'>): (input: TInput) => Promise; //# sourceMappingURL=execute-tool-with-cache.d.ts.map