execute_cql_search
Run CQL queries on Confluence to search and retrieve pages, specifying the query string and results limit for targeted content discovery.
Instructions
Execute a CQL query on Confluence to search pages
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cql | Yes | CQL query string | |
| limit | No | Number of results to return |
Implementation Reference
- src/index.ts:105-127 (handler)Core handler function that executes the CQL query against Confluence API using axios.get, handles errors, and returns results.async function executeCQL(cql: string, limit: number): Promise<any> { try { const params = { cql, limit, }; const response = await axios.get( `${CONFLUENCE_URL}/wiki/rest/api/content/search`, { // Updated URL headers: getAuthHeaders().headers, params, }, ); return response.data; } catch (error: any) { return { error: error.response ? error.response.data : error.message, }; } }
- src/index.ts:231-249 (handler)MCP CallToolRequestSchema handler case that validates input, calls executeCQL, and formats response as MCP content.case 'execute_cql_search': { const cql = String(request.params.arguments?.cql); const limit = Number(request.params.arguments?.limit ?? 10); if (!cql) { throw new Error('CQL query is required'); } const response = await executeCQL(cql, limit); return { content: [ { type: 'text', text: JSON.stringify(response, null, 2), }, ], }; }
- src/index.ts:40-58 (registration)Registers the execute_cql_search tool in the ListTools response, including name, description, and input schema.{ name: 'execute_cql_search', description: 'Execute a CQL query on Confluence to search pages', inputSchema: { type: 'object', properties: { cql: { type: 'string', description: 'CQL query string', }, limit: { type: 'integer', description: 'Number of results to return', default: 10, }, }, required: ['cql'], }, },
- src/index.ts:43-57 (schema)Defines the input schema for the execute_cql_search tool, specifying cql as required string and optional limit integer.inputSchema: { type: 'object', properties: { cql: { type: 'string', description: 'CQL query string', }, limit: { type: 'integer', description: 'Number of results to return', default: 10, }, }, required: ['cql'], },
- src/index.ts:214-223 (helper)Helper function to generate authentication headers using Basic Auth from environment variables, used in executeCQL.function getAuthHeaders(): AxiosRequestConfig<any> { const authHeader = `Basic ${Buffer.from( `${CONFLUENCE_API_MAIL}:${CONFLUENCE_API_KEY}`, ).toString('base64')}`; return { headers: { Authorization: authHeader, 'Content-Type': 'application/json', }, };