aem_clear_cache
Clear AEM caches including dispatcher, clientlibs, or all cached data. Specify host, port, and credentials to manage cache directly from the AEM MCP Server.
Instructions
Clear various AEM caches
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cacheType | No | Type of cache to clear | all |
| host | No | AEM host (default: localhost) | localhost |
| password | No | AEM password (default: admin) | admin |
| port | No | AEM port (default: 4502) | |
| username | No | AEM username (default: admin) | admin |
Implementation Reference
- src/aem-tools.ts:222-250 (handler)The main tool handler function in AEMTools class that extracts config and cacheType from args, calls the AEMClient.clearCache method, formats the results into a text response, and returns it in MCP format.async clearCache(args: any) { const config = this.getConfig(args); const { cacheType = 'all' } = args; const result = await this.aemClient.clearCache(config, cacheType); let cacheText = `Cache Clear Result: Cache Type: ${cacheType} Success: ${result.success} `; if (result.success && result.results) { cacheText += `\nResults:\n`; result.results.forEach((res: any) => { cacheText += `- ${res.type}: ${res.success ? 'Success' : 'Failed'} - ${res.message}\n`; }); } else { cacheText += `Message: Failed to clear cache`; } return { content: [ { type: 'text', text: cacheText, }, ], }; }
- src/aem-client.ts:330-390 (helper)Core implementation in AEMClient that performs the actual HTTP requests to clear clientlibs and/or dispatcher caches based on the cacheType, collecting results from each operation.async clearCache(config: AEMConfig, cacheType: string = 'all'): Promise<any> { const baseUrl = this.getBaseUrl(config); const authHeader = this.getAuthHeader(config); const results: any[] = []; try { if (cacheType === 'clientlibs' || cacheType === 'all') { // Clear client libraries cache const clientlibsResponse = await this.axiosInstance.post( `${baseUrl}/libs/granite/ui/content/dumplibs.rebuild.html`, {}, { headers: { 'Authorization': authHeader, }, } ); results.push({ type: 'clientlibs', success: clientlibsResponse.status === 200, message: clientlibsResponse.status === 200 ? 'Client libraries cache cleared' : 'Failed to clear client libraries cache', }); } if (cacheType === 'dispatcher' || cacheType === 'all') { // Invalidate dispatcher cache (if available) try { const dispatcherResponse = await this.axiosInstance.post( `${baseUrl}/dispatcher/invalidate.cache`, {}, { headers: { 'Authorization': authHeader, }, } ); results.push({ type: 'dispatcher', success: dispatcherResponse.status === 200, message: dispatcherResponse.status === 200 ? 'Dispatcher cache invalidated' : 'Failed to invalidate dispatcher cache', }); } catch (error) { results.push({ type: 'dispatcher', success: false, message: 'Dispatcher cache invalidation not available or failed', }); } } return { success: true, results: results, }; } catch (error) { throw new Error(`Cache clearing failed: ${error instanceof Error ? error.message : 'Unknown error'}`); } }
- src/index.ts:310-343 (schema)Input schema definition for the aem_clear_cache tool, including properties for cacheType, host, port, username, and password with defaults.name: 'aem_clear_cache', description: 'Clear various AEM caches', inputSchema: { type: 'object', properties: { cacheType: { type: 'string', description: 'Type of cache to clear', enum: ['dispatcher', 'clientlibs', 'all'], default: 'all' }, host: { type: 'string', description: 'AEM host (default: localhost)', default: 'localhost' }, port: { type: 'number', description: 'AEM port (default: 4502)', default: 4502 }, username: { type: 'string', description: 'AEM username (default: admin)', default: 'admin' }, password: { type: 'string', description: 'AEM password (default: admin)', default: 'admin' } } } }
- src/index.ts:367-368 (registration)Registration of the tool handler in the MCP CallToolRequest switch statement, delegating execution to AEMTools.clearCache method.case 'aem_clear_cache': return await this.aemTools.clearCache(args);