aem_clear_cache
Clear Adobe Experience Manager caches to resolve content display issues and ensure updated content appears correctly by removing cached dispatcher, clientlibs, or all cache types.
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 |
| port | No | AEM port (default: 4502) | |
| username | No | AEM username (default: admin) | admin |
| password | No | AEM password (default: admin) | admin |
Implementation Reference
- src/aem-tools.ts:222-250 (handler)Handler function in AEMTools class that processes tool arguments, calls AEMClient.clearCache, formats the result into MCP content response.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 helper method in AEMClient that executes HTTP POST requests to clear clientlibs cache and/or invalidate dispatcher cache based on the specified cacheType.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:312-342 (schema)Input schema definition for the aem_clear_cache tool, specifying parameters like cacheType, host, port, credentials.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 CallToolRequest switch statement in index.ts.case 'aem_clear_cache': return await this.aemTools.clearCache(args);
- src/index.ts:309-343 (registration)Tool registration entry in the listTools response, including name, description, and schema.{ 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' } } } }