confluence_search
Search Confluence pages and content using CQL queries with optional filters by space and result limit.
Instructions
Search Confluence content using CQL (Confluence Query Language). Example queries: "type=page AND title~"API"", "type=page ORDER BY lastmodified DESC"
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | CQL search query (e.g., "type=page AND title~\"keyword\"") | |
| limit | No | Maximum number of results (default: 10) | |
| spaceKey | No | Optional space key to limit search to a specific space |
Implementation Reference
- index.js:48-62 (handler)The `searchContent` async function is the core handler for the confluence_search tool. It makes an HTTP GET request to the Confluence REST API `/content/search` endpoint with CQL query parameters, supports optional space key filtering, and returns the search results.
async function searchContent(query, limit = 10, spaceKey = null) { try { let cql = query; if (spaceKey) { cql = `${query} AND space=${spaceKey}`; } const response = await client.get(`${CONFLUENCE_API_BASE}/content/search`, { params: { cql, limit, expand: 'space,version' } }); return response.data; } catch (error) { throw new Error(`Failed to search content: ${error.message}`); } } - index.js:406-420 (handler)The `case 'confluence_search'` block in the CallToolRequestSchema handler dispatches the tool call, invokes `searchContent()` with the query, limit, and spaceKey arguments, and returns the JSON-stringified result.
case 'confluence_search': { const result = await searchContent( args.query, args.limit || 10, args.spaceKey ); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } - index.js:231-251 (registration)The tool `confluence_search` is registered in the ListToolsRequestSchema handler with its name, description, and JSON Schema input schema (query string required, optional limit number, optional spaceKey string).
name: 'confluence_search', description: 'Search Confluence content using CQL (Confluence Query Language). Example queries: "type=page AND title~\\"API\\"", "type=page ORDER BY lastmodified DESC"', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'CQL search query (e.g., "type=page AND title~\\"keyword\\"")', }, limit: { type: 'number', description: 'Maximum number of results (default: 10)', }, spaceKey: { type: 'string', description: 'Optional space key to limit search to a specific space', }, }, required: ['query'], }, }, - index.js:20-43 (helper)Supporting configuration and HTTP client setup: Confluence API base URL construction, authentication via email+API token, and axios client instance creation used by the searchContent handler.
const ATLASSIAN_SITE = process.env.ATLASSIAN_SITE; const ATLASSIAN_EMAIL = process.env.ATLASSIAN_EMAIL; const ATLASSIAN_API_TOKEN = process.env.ATLASSIAN_API_TOKEN; // Validate configuration if (!ATLASSIAN_SITE || !ATLASSIAN_EMAIL || !ATLASSIAN_API_TOKEN) { console.error('ERROR: ATLASSIAN_SITE, ATLASSIAN_EMAIL, and ATLASSIAN_API_TOKEN must be set'); process.exit(1); } // API Base URL const CONFLUENCE_API_BASE = `https://${ATLASSIAN_SITE}/wiki/rest/api`; // HTTP client with auth const client = axios.create({ auth: { username: ATLASSIAN_EMAIL, password: ATLASSIAN_API_TOKEN, }, headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, }); - test-mcp.js:67-79 (helper)Test script that exercises the confluence_search tool by calling it with a 'type=page' query and limit of 3, then validating the response.
// Test search console.log('\nš Testing confluence_search...'); const searchResult = await client.callTool({ name: 'confluence_search', arguments: { query: 'type=page', limit: 3 }, }); console.log('ā Success!'); const searchData = JSON.parse(searchResult.content[0].text); console.log(`Found ${searchData.results?.length || 0} pages`);