getTemplates
Retrieve available page templates from the AEM MCP Server for efficient content management and streamlined site creation.
Instructions
Get available page templates
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sitePath | No |
Implementation Reference
- Core implementation of getTemplates tool. Fetches templates from site-specific (/conf) and global (/apps, /libs) paths using AEM JSON APIs, with fallback logic and structured response.async getTemplates(sitePath) { return safeExecute(async () => { // If sitePath is provided, look for templates specific to that site if (sitePath) { try { // Try to get site-specific templates from /conf const confPath = `/conf${sitePath.replace('/content', '')}/settings/wcm/templates`; const response = await this.httpClient.get(`${confPath}.json`, { params: { ':depth': '2' } }); const templates = []; if (response.data && typeof response.data === 'object') { Object.entries(response.data).forEach(([key, value]) => { if (key.startsWith('jcr:') || key.startsWith('sling:')) return; if (value && typeof value === 'object' && value['jcr:content']) { templates.push({ name: key, path: `${confPath}/${key}`, title: value['jcr:content']['jcr:title'] || key, description: value['jcr:content']['jcr:description'], thumbnail: value['jcr:content']['thumbnail'], allowedPaths: value['jcr:content']['allowedPaths'], status: value['jcr:content']['status'], ranking: value['jcr:content']['ranking'] || 0, templateType: value['jcr:content']['templateType'], lastModified: value['jcr:content']['cq:lastModified'], createdBy: value['jcr:content']['jcr:createdBy'] }); } }); } return createSuccessResponse({ sitePath, templates, totalCount: templates.length, source: 'site-specific' }, 'getTemplates'); } catch (error) { // Fallback to global templates if site-specific not found this.logger.warn('Site-specific templates not found, falling back to global templates', { sitePath, error: error.message }); } } // Get global templates from /apps or /libs try { const globalPaths = ['/apps/wcm/core/content/sites/templates', '/libs/wcm/core/content/sites/templates']; const allTemplates = []; for (const templatePath of globalPaths) { try { const response = await this.httpClient.get(`${templatePath}.json`, { params: { ':depth': '2' } }); if (response.data && typeof response.data === 'object') { Object.entries(response.data).forEach(([key, value]) => { if (key.startsWith('jcr:') || key.startsWith('sling:')) return; if (value && typeof value === 'object') { allTemplates.push({ name: key, path: `${templatePath}/${key}`, title: value['jcr:title'] || key, description: value['jcr:description'], thumbnail: value['thumbnail'], allowedPaths: value['allowedPaths'], status: value['status'] || 'enabled', ranking: value['ranking'] || 0, templateType: value['templateType'], lastModified: value['cq:lastModified'], createdBy: value['jcr:createdBy'], source: templatePath.includes('/apps/') ? 'apps' : 'libs' }); } }); } } catch (pathError) { // Continue to next path if this one fails this.logger.debug('Template path not accessible', { path: templatePath, error: pathError.message }); } } return createSuccessResponse({ sitePath: sitePath || 'global', templates: allTemplates, totalCount: allTemplates.length, source: 'global' }, 'getTemplates'); } catch (error) { throw handleAEMHttpError(error, 'getTemplates'); } }, 'getTemplates'); }
- dist/mcp-server.js:388-395 (registration)MCP tool registration including name, description, and input schema for getTemplates.{ name: 'getTemplates', description: 'Get available page templates', inputSchema: { type: 'object', properties: { sitePath: { type: 'string' } }, }, },
- dist/mcp-server.js:733-736 (handler)MCP server dispatch handler that calls the AEM connector's getTemplates method.case 'getTemplates': { const sitePath = args.sitePath; const result = await aemConnector.getTemplates(sitePath); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
- dist/aem-connector-new.js:146-147 (helper)Delegation method in AEMConnector that forwards to TemplateOperations instance.async getTemplates(sitePath) { return this.templateOps.getTemplates(sitePath);
- dist/aem-connector-new.d.ts:48-48 (schema)TypeScript definition for getTemplates method return type (TemplatesResponse). Note: File ID assumed from search; confirm if needed.getTemplates(sitePath?: string): Promise<import("./interfaces/index.js").TemplatesResponse>;