Skip to main content
Glama
conorluddy

XC-MCP: XCode CLI wrapper

by conorluddy

cache-clear

Clear specified cached data (simulator, project, response, or all) to ensure fresh data retrieval in XC-MCP server operations, resolving issues with excessive token limits in Xcode CLI tool output.

Instructions

Clear cached data to force fresh data retrieval

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cacheTypeYesWhich cache to clear

Implementation Reference

  • The core handler function `clearCacheTool` that executes the cache clearing logic for simulator, project, response caches or all. Validates input and returns JSON confirmation with results.
    export async function clearCacheTool(args: any): Promise<ToolResult> { try { const { cacheType } = args as ClearCacheArgs; if (!['simulator', 'project', 'response', 'all'].includes(cacheType)) { throw new McpError( ErrorCode.InvalidParams, 'cacheType must be one of: simulator, project, response, all' ); } const results: Record<string, string> = {}; if (cacheType === 'simulator' || cacheType === 'all') { simulatorCache.clearCache(); results.simulator = 'Cleared successfully'; } if (cacheType === 'project' || cacheType === 'all') { projectCache.clearCache(); results.project = 'Cleared successfully'; } if (cacheType === 'response' || cacheType === 'all') { responseCache.clear(); results.response = 'Cleared successfully'; } return { content: [ { type: 'text' as const, text: JSON.stringify( { message: 'Cache cleared successfully', results, timestamp: new Date().toISOString(), }, null, 2 ), }, ], }; } catch (error) { if (error instanceof McpError) { throw error; } throw new McpError( ErrorCode.InternalError, `Failed to clear cache: ${error instanceof Error ? error.message : String(error)}` ); } }
  • TypeScript interface defining the input parameters for the cache-clear tool.
    interface ClearCacheArgs { cacheType: 'simulator' | 'project' | 'response' | 'all'; }
  • Registration of the consolidated `cache` tool with MCP server, which routes `operation: 'clear'` to the clearCacheTool handler. 'cache-clear' is a legacy alias documented but not separately registered.
    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)}` ); } } );
  • Routing helper in `cacheTool` that dispatches `operation: 'clear'` to `clearCacheTool`, providing backwards compatibility for legacy `cache-clear` tool.
    async function routeOperation(args: CacheToolArgs) { const { operation } = args; switch (operation) { case 'get-stats': return getCacheStatsTool({}); case 'get-config': if (!args.cacheType) { throw new McpError( ErrorCode.InvalidRequest, 'cacheType is required for get-config operation' ); } return getCacheConfigTool({ cacheType: args.cacheType }); 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, }); case 'clear': if (!args.cacheType) { throw new McpError(ErrorCode.InvalidRequest, 'cacheType is required for clear operation'); } return clearCacheTool({ cacheType: args.cacheType }); default: throw new McpError( ErrorCode.InvalidRequest, `Unknown operation: ${operation}. Valid operations: get-stats, get-config, set-config, clear` ); }
  • Zod input schema validation for the `cache` tool, including validation for `clear` operation.
    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,

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