aem_query_content
Execute JCR-SQL2 or XPath queries on Adobe Experience Manager (AEM) content to retrieve specific nodes or data, with customizable limits and host configurations.
Instructions
Query content using JCR-SQL2 or XPath
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| host | No | AEM host (default: localhost) | localhost |
| limit | No | Maximum number of results (default: 20) | |
| password | No | AEM password (default: admin) | admin |
| port | No | AEM port (default: 4502) | |
| query | Yes | Query string (JCR-SQL2 or XPath) | |
| type | No | Query type | JCR-SQL2 |
| username | No | AEM username (default: admin) | admin |
Implementation Reference
- src/aem-tools.ts:137-168 (handler)The primary handler function for the 'aem_query_content' tool. It validates input, calls the AEMClient to perform 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, }, ], }; }
- src/index.ts:234-274 (schema)Input schema definition for the 'aem_query_content' tool, including parameters like query, type, limit, and AEM connection details.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)Registration of the tool handler in the CallToolRequest switch statement, dispatching to AEMTools.queryContent.case 'aem_query_content': return await this.aemTools.queryContent(args);
- src/index.ts:231-275 (registration)Tool registration in the ListTools response, including name, description, and schema reference.{ 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/aem-client.ts:264-297 (helper)Core helper function that executes the HTTP request to AEM's QueryBuilder endpoint (/bin/querybuilder.json) to perform the actual 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'}`); } }