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,
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool clears cached data but doesn't specify whether this is destructive (likely yes, but not confirmed), requires permissions, has side effects, or provides any output/confirmation. This leaves significant gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's front-loaded and wastes no space, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with no annotations and no output schema, the description is incomplete. It doesn't cover behavioral aspects like safety, permissions, or what happens after execution, nor does it explain the context of cache types or sibling tool relationships, leaving the agent with insufficient information for reliable use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, documenting the single parameter 'cacheType' with an enum. The description doesn't add any meaning beyond the schema, such as explaining what each cache type represents or the implications of clearing 'all'. Baseline 3 is appropriate as the schema handles parameter documentation adequately.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Clear cached data') and the outcome ('to force fresh data retrieval'), providing a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'cache-get-config' or 'cache-set-config', which handle configuration rather than clearing operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description offers no guidance on when to use this tool versus alternatives. It doesn't mention scenarios where clearing cache is necessary (e.g., after updates or to resolve stale data) or when other tools like 'cache-get-stats' might be preferred for monitoring instead of action.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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