search_pages
Finds Confluence pages matching a query by title or content. Use space key to limit search to a specific space.
Instructions
Search for Confluence pages by title or content.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query string to match against page titles and content | |
| space_key | No | Optional space key to limit search to a specific space | |
| limit | No | Maximum number of results to return (default: 10, max: 50) |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- server.py:154-202 (handler)The @mcp.tool() decorated function 'search_pages' that implements the MCP tool handler for searching Confluence pages via CQL queries.
@mcp.tool() def search_pages(query: str, space_key: Optional[str] = None, limit: int = 10) -> str: """ Search for Confluence pages by title or content. Args: query: Search query string to match against page titles and content space_key: Optional space key to limit search to a specific space limit: Maximum number of results to return (default: 10, max: 50) Returns: JSON string containing matching pages with titles, IDs, spaces, and URLs """ try: if not query or not query.strip(): return "Error: query parameter is required and cannot be empty" if limit < 1 or limit > 50: return "Error: limit must be between 1 and 50" pages = confluence.search_pages(query=query, space_key=space_key, limit=limit) # Format response result = { "total": len(pages), "query": query, "space_key": space_key, "pages": [ { "id": page.get("id"), "title": page.get("title"), "type": page.get("type"), "space": { "key": page.get("space", {}).get("key"), "name": page.get("space", {}).get("name") }, "version": page.get("version", {}).get("number"), "url": f"{CONFLUENCE_URL}/wiki{page.get('_links', {}).get('webui', '')}" } for page in pages ] } import json return json.dumps(result, indent=2) except Exception as e: logger.error(f"Error searching pages: {e}") return f"Error: {str(e)}" - server.py:155-165 (schema)The function signature defines the input schema: query (str, required), space_key (Optional[str]), and limit (int, default=10). The return type is str (JSON).
def search_pages(query: str, space_key: Optional[str] = None, limit: int = 10) -> str: """ Search for Confluence pages by title or content. Args: query: Search query string to match against page titles and content space_key: Optional space key to limit search to a specific space limit: Maximum number of results to return (default: 10, max: 50) Returns: JSON string containing matching pages with titles, IDs, spaces, and URLs - server.py:176-198 (schema)The JSON output schema returned by the handler, containing total count, query, space_key, and pages array with id, title, type, space, version, and url.
# Format response result = { "total": len(pages), "query": query, "space_key": space_key, "pages": [ { "id": page.get("id"), "title": page.get("title"), "type": page.get("type"), "space": { "key": page.get("space", {}).get("key"), "name": page.get("space", {}).get("name") }, "version": page.get("version", {}).get("number"), "url": f"{CONFLUENCE_URL}/wiki{page.get('_links', {}).get('webui', '')}" } for page in pages ] } import json return json.dumps(result, indent=2) - server.py:154-154 (registration)The tool is registered as an MCP tool via the @mcp.tool() decorator on line 154.
@mcp.tool() - server.py:83-100 (helper)The ConfluenceClient.search_pages() helper method that constructs a CQL query and calls the Confluence REST API /content/search endpoint.
def search_pages( self, query: str, space_key: Optional[str] = None, limit: int = 10 ) -> list[dict]: """Search for Confluence pages by title or content.""" cql = f'type=page and (title~"{query}" or text~"{query}")' if space_key: cql += f' and space="{space_key}"' params = { "cql": cql, "limit": limit, "expand": "space,version" } response = self._make_request("GET", "/content/search", params=params) return response.get("results", [])