Skip to main content
Glama
conorluddy

XC-MCP: XCode CLI wrapper

by conorluddy

cache-get-config

Retrieve current cache configuration settings for Xcode CLI operations in XC-MCP, enabling efficient management of simulator, project, or response caches.

Instructions

Get current cache configuration settings

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cacheTypeNoWhich cache configuration to retrieveall

Implementation Reference

  • The core handler function `getCacheConfigTool` implementing the `cache-get-config` tool logic. Retrieves current cache retention configuration for specified cache types (simulator, project, response) and formats output with human-readable durations.
    export async function getCacheConfigTool(args: any): Promise<ToolResult> {
      try {
        const { cacheType = 'all' } = args as GetCacheConfigArgs;
    
        if (!['simulator', 'project', 'response', 'all'].includes(cacheType)) {
          throw new McpError(
            ErrorCode.InvalidParams,
            'cacheType must be one of: simulator, project, response, all'
          );
        }
    
        const config: Record<string, any> = {};
    
        if (cacheType === 'simulator' || cacheType === 'all') {
          const maxAge = simulatorCache.getCacheMaxAge();
          config.simulator = {
            maxAgeMs: maxAge,
            maxAgeHuman: formatDuration(maxAge),
          };
        }
    
        if (cacheType === 'project' || cacheType === 'all') {
          const maxAge = projectCache.getCacheMaxAge();
          config.project = {
            maxAgeMs: maxAge,
            maxAgeHuman: formatDuration(maxAge),
          };
        }
    
        if (cacheType === 'response' || cacheType === 'all') {
          config.response = {
            maxAgeMs: 30 * 60 * 1000, // Fixed 30 minutes
            maxAgeHuman: '30m',
            note: 'Response cache duration is currently fixed',
          };
        }
    
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify(
                {
                  cacheConfiguration: config,
                  timestamp: new Date().toISOString(),
                },
                null,
                2
              ),
            },
          ],
        };
      } catch (error) {
        if (error instanceof McpError) {
          throw error;
        }
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to get cache config: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • Helper function `formatDuration` converts milliseconds to human-readable time strings (e.g., '1h 30m') used in the cache configuration output.
    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`;
    }
  • Input schema validation for the consolidated `cache` tool, which includes `get-config` operation with `cacheType` parameter validation using Zod.
      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,
    },
  • MCP server registration of the `cache` tool, which dispatches `get-config` operations to the `cache-get-config` implementation via `cacheTool` router.
    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)}`
          );
        }
      }
    );
  • Router function `routeOperation` in consolidated `cacheTool` that dispatches 'get-config' operation to `getCacheConfigTool`.
    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`
          );
      }
    }

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