Skip to main content
Glama
conorluddy

XC-MCP: XCode CLI wrapper

by conorluddy

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:

  1. cache-get-stats → check current cache status

  2. cache-set-config → adjust cache timeouts

  3. cache-clear → force refresh when needed

  4. Your normal xcodebuild/simctl operations (now faster!)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cacheTypeYesWhich cache to configure
maxAgeHoursNoMaximum cache age in hours (alternative to maxAgeMs)
maxAgeMinutesNoMaximum cache age in minutes (alternative to maxAgeMs)
maxAgeMsNoMaximum cache age in milliseconds

Implementation Reference

  • 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)}` ); } }
  • 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`; }
  • 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, });
  • 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)}` ); } } );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/conorluddy/xc-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server