Skip to main content
Glama

aem_query_content

Query Adobe Experience Manager content using JCR-SQL2 or XPath to search and retrieve specific content items from AEM instances.

Instructions

Query content using JCR-SQL2 or XPath

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesQuery string (JCR-SQL2 or XPath)
typeNoQuery typeJCR-SQL2
limitNoMaximum number of results (default: 20)
hostNoAEM host (default: localhost)localhost
portNoAEM port (default: 4502)
usernameNoAEM username (default: admin)admin
passwordNoAEM password (default: admin)admin

Implementation Reference

  • MCP tool handler that processes arguments, calls the AEM client to execute the query, and formats the response as MCP content.
      async queryContent(args: any) {
        const config = this.getConfig(args);
        const { query, type = 'JCR-SQL2', limit = 20 } = args;
    
        if (!query) {
          throw new Error('Query is required');
        }
    
        const result = await this.aemClient.queryContent(config, query, type, limit);
        
        let queryText = `Content Query Result:
    Query: ${query}
    Type: ${type}
    Limit: ${limit}
    Success: ${result.success}
    `;
    
        if (result.success && result.results) {
          queryText += `Results:\n${JSON.stringify(result.results, null, 2)}`;
        } else {
          queryText += `Message: ${result.message || 'Query failed'}`;
        }
        
        return {
          content: [
            {
              type: 'text',
              text: queryText,
            },
          ],
        };
      }
  • Low-level implementation that sends HTTP request to AEM's querybuilder.json endpoint to execute the content query.
    async queryContent(config: AEMConfig, query: string, type: string = 'JCR-SQL2', limit: number = 20): Promise<any> {
      const baseUrl = this.getBaseUrl(config);
      const authHeader = this.getAuthHeader(config);
    
      const params = new URLSearchParams();
      params.append('query', query);
      params.append('type', type);
      params.append('p.limit', limit.toString());
    
      try {
        const response = await this.axiosInstance.get(
          `${baseUrl}/bin/querybuilder.json?${params.toString()}`,
          {
            headers: {
              'Authorization': authHeader,
            },
          }
        );
    
        if (response.status === 200) {
          return {
            success: true,
            results: response.data,
          };
        } else {
          return {
            success: false,
            message: `Query failed: HTTP ${response.status}`,
          };
        }
      } catch (error) {
        throw new Error(`Query failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
      }
    }
  • Input schema and metadata for the aem_query_content tool, registered in ListToolsRequestHandler.
    {
      name: 'aem_query_content',
      description: 'Query content using JCR-SQL2 or XPath',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: 'Query string (JCR-SQL2 or XPath)'
          },
          type: {
            type: 'string',
            description: 'Query type',
            enum: ['JCR-SQL2', 'xpath'],
            default: 'JCR-SQL2'
          },
          limit: {
            type: 'number',
            description: 'Maximum number of results (default: 20)',
            default: 20
          },
          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'
          }
        },
        required: ['query']
      }
    },
  • src/index.ts:363-364 (registration)
    Switch case in CallToolRequestHandler that routes calls to the aem_query_content handler.
    case 'aem_query_content':
      return await this.aemTools.queryContent(args);

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/pradeep-moolemane/aem-mcp'

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