Skip to main content
Glama

getTemplates

Retrieve available page templates for a specific site in Adobe Experience Manager to streamline content creation and ensure consistent design implementation.

Instructions

Get available page templates

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sitePathNo

Implementation Reference

  • Core handler function that implements the getTemplates tool logic by querying AEM instance for site-specific and global page templates via HTTP GET requests to template paths, 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');
    }
  • MCP tool registration entry in the list of available methods, defining name, description, and parameters.
    { name: 'getTemplates', description: 'Get available page templates', parameters: ['sitePath'] },
  • MCP request handler dispatch for 'getTemplates' tool, delegating to AEM connector.
    case 'getTemplates':
        return await this.aemConnector.getTemplates(params.sitePath);
  • TypeScript type definition/signature for getTemplates method, specifying input (optional sitePath) and output (TemplatesResponse).
    getTemplates(sitePath?: string): Promise<import("./interfaces/index.js").TemplatesResponse>;
  • Delegation method in AEMConnector that forwards getTemplates call to the TemplateOperations module.
    async getTemplates(sitePath) {
        return this.templateOps.getTemplates(sitePath);

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/indrasishbanerjee/aem-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server