cache-set-config
Adjust cache timeout settings in XC-MCP to optimize performance, control data freshness, and manage memory usage. Tailor cache duration for simulators, projects, or all caches to suit development or CI workflows.
Instructions
🎛️ Cache Optimization - Fine-tune XC-MCP's intelligent caching for your workflow.
Why manage caching:
• ⚡ Performance tuning - Longer caches = faster repeated operations
• 🔄 Fresh data control - Shorter caches = more up-to-date information
• 💾 Memory management - Balance speed vs memory usage
• 🎯 Workflow optimization - Different cache settings for development vs CI
Configure cache maximum age settings. Default is 1 hour for simulator and project caches.
Examples:
Set 30 minutes: {"cacheType": "all", "maxAgeMinutes": 30}
Set 2 hours for simulators: {"cacheType": "simulator", "maxAgeHours": 2}
Set 5 minutes: {"cacheType": "project", "maxAgeMinutes": 5}
Common Workflow:
cache-get-stats → check current cache status
cache-set-config → adjust cache timeouts
cache-clear → force refresh when needed
Your normal xcodebuild/simctl operations (now faster!)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cacheType | Yes | Which cache to configure | |
| maxAgeHours | No | Maximum cache age in hours (alternative to maxAgeMs) | |
| maxAgeMinutes | No | Maximum cache age in minutes (alternative to maxAgeMs) | |
| maxAgeMs | No | Maximum cache age in milliseconds |
Implementation Reference
- src/tools/cache/set-config.ts:62-137 (handler)The core handler function that implements the logic for the 'cache-set-config' tool. It validates input parameters, calculates max age in milliseconds from various units, updates cache max ages for specified cache types, and returns a formatted JSON response with results.export async function setCacheConfigTool(args: any): Promise<ToolResult> { try { const { cacheType, maxAgeMs, maxAgeMinutes, maxAgeHours } = args as SetCacheConfigArgs; if (!['simulator', 'project', 'response', 'all'].includes(cacheType)) { throw new McpError( ErrorCode.InvalidParams, 'cacheType must be one of: simulator, project, response, all' ); } // Calculate max age in milliseconds let maxAge: number; if (maxAgeMs !== undefined) { maxAge = maxAgeMs; } else if (maxAgeMinutes !== undefined) { maxAge = maxAgeMinutes * 60 * 1000; } else if (maxAgeHours !== undefined) { maxAge = maxAgeHours * 60 * 60 * 1000; } else { throw new McpError( ErrorCode.InvalidParams, 'Must specify one of: maxAgeMs, maxAgeMinutes, or maxAgeHours' ); } if (maxAge < 1000) { throw new McpError( ErrorCode.InvalidParams, 'Cache max age must be at least 1000ms (1 second)' ); } const results: Record<string, string> = {}; if (cacheType === 'simulator' || cacheType === 'all') { simulatorCache.setCacheMaxAge(maxAge); results.simulator = `Set to ${formatDuration(maxAge)}`; } if (cacheType === 'project' || cacheType === 'all') { projectCache.setCacheMaxAge(maxAge); results.project = `Set to ${formatDuration(maxAge)}`; } if (cacheType === 'response' || cacheType === 'all') { // Note: responseCache doesn't have setCacheMaxAge yet, we'd need to implement it results.response = 'Response cache config is fixed at 30 minutes'; } return { content: [ { type: 'text' as const, text: JSON.stringify( { message: 'Cache configuration updated', results, timestamp: new Date().toISOString(), }, null, 2 ), }, ], }; } catch (error) { if (error instanceof McpError) { throw error; } throw new McpError( ErrorCode.InternalError, `Failed to set cache config: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/tools/cache/set-config.ts:6-11 (schema)TypeScript interface defining the expected input arguments for the cache-set-config tool handler.interface SetCacheConfigArgs { cacheType: 'simulator' | 'project' | 'response' | 'all'; maxAgeMs?: number; maxAgeMinutes?: number; maxAgeHours?: number; }
- Utility function used by the handler to convert milliseconds to a human-readable duration string.function formatDuration(ms: number): string { const seconds = Math.floor(ms / 1000); const minutes = Math.floor(seconds / 60); const hours = Math.floor(minutes / 60); const days = Math.floor(hours / 24); if (days > 0) return `${days}d ${hours % 24}h`; if (hours > 0) return `${hours}h ${minutes % 60}m`; if (minutes > 0) return `${minutes}m ${seconds % 60}s`; return `${seconds}s`; }
- src/tools/cache/index.ts:74-86 (helper)Dispatcher logic in the consolidated 'cache' tool that routes 'set-config' operation to the setCacheConfigTool handler.case 'set-config': if (!args.cacheType) { throw new McpError( ErrorCode.InvalidRequest, 'cacheType is required for set-config operation' ); } return setCacheConfigTool({ cacheType: args.cacheType, maxAgeMs: args.maxAgeMs, maxAgeMinutes: args.maxAgeMinutes, maxAgeHours: args.maxAgeHours, });
- src/registry/cache.ts:20-46 (registration)Registration of the consolidated 'cache' tool, which includes the 'set-config' operation (backwards compatible with 'cache-set-config'). Includes Zod input schema validation for all cache operations.server.registerTool( 'cache', { description: getDescription(CACHE_DOCS, CACHE_DOCS_MINI), inputSchema: { operation: z.enum(['get-stats', 'get-config', 'set-config', 'clear']), cacheType: z.enum(['simulator', 'project', 'response', 'all']).optional(), maxAgeMs: z.number().optional(), maxAgeMinutes: z.number().optional(), maxAgeHours: z.number().optional(), }, ...DEFER_LOADING_CONFIG, }, async args => { try { await validateXcodeInstallation(); // eslint-disable-next-line @typescript-eslint/no-explicit-any return (await cacheTool(args)) as any; } catch (error) { if (error instanceof McpError) throw error; throw new McpError( ErrorCode.InternalError, `Tool execution failed: ${error instanceof Error ? error.message : String(error)}` ); } } );