get-confluence-page
Retrieve a Confluence page's content by page ID or title and space key. Optionally include comments and version history.
Instructions
Get a Confluence page by ID or title. Use this tool to retrieve a specific page's content, optionally including comments and version history.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page_id | No | The ID of the Confluence page | |
| title | No | The title of the Confluence page | |
| space_key | No | The key of the Confluence space | |
| include_comments | No | ||
| include_history | No |
Implementation Reference
- src/mcp_jira_confluence/server.py:744-761 (registration)Tool registration for 'get-confluence-page' in handle_list_tools(). Defines the tool name, description, and input schema (JSON Schema) with parameters: page_id, title, space_key, include_comments, include_history. Uses anyOf to require either page_id or (title + space_key).
types.Tool( name="get-confluence-page", description="Get a Confluence page by ID or title. Use this tool to retrieve a specific page's content, optionally including comments and version history.", inputSchema={ "type": "object", "properties": { "page_id": {"type": "string", "description": "The ID of the Confluence page"}, "title": {"type": "string", "description": "The title of the Confluence page"}, "space_key": {"type": "string", "description": "The key of the Confluence space"}, "include_comments": {"type": "boolean", "default": False}, "include_history": {"type": "boolean", "default": False} }, "anyOf": [ {"required": ["page_id"]}, {"required": ["title", "space_key"]} ] } ), - Handler implementation for 'get-confluence-page' in handle_call_tool(). Fetches a Confluence page by ID or title+space_key, retrieves body.storage content, version, and space info. Optionally includes comments (via confluence_client.get_page_comments) and version history (via confluence_client.get_page_history). Returns formatted markdown content.
elif name == "get-confluence-page": page_id = arguments.get("page_id") title = arguments.get("title") space_key = arguments.get("space_key") include_comments = arguments.get("include_comments", False) include_history = arguments.get("include_history", False) if not page_id and (not title or not space_key): raise ValueError("Missing required arguments: either page_id or both title and space_key") # Fetch the page data page_data = None if page_id: page_data = await confluence_client.get_page(page_id, expand="body.storage,version,space") else: # Search by title and space key cql = f'title = "{title}" AND space.key = "{space_key}"' search_result = await confluence_client.search(cql, limit=1) if search_result.get("results"): page_id = search_result["results"][0]["id"] page_data = await confluence_client.get_page(page_id, expand="body.storage,version,space") else: raise ValueError("Page not found") # Format the response title = page_data["title"] content = page_data["body"]["storage"]["value"] space_name = page_data.get("space", {}).get("name", "Unknown Space") version = page_data["version"]["number"] if "version" in page_data else "Unknown" response = f"**Title:** {title}\n" response += f"**Space:** {space_name}\n" response += f"**Version:** {version}\n\n" response += f"{ConfluenceFormatter.confluence_to_markdown(content)}" if include_comments: # Add comments section try: comments_data = await confluence_client.get_page_comments(page_id) if comments_data.get("results"): response += "\n\n**Comments:**\n" for comment in comments_data["results"]: author = comment.get("by", {}).get("displayName", "Unknown") body = comment.get("body", {}).get("storage", {}).get("value", "") created = comment.get("when", "") response += f"- **{author}** on {created}: {ConfluenceFormatter.confluence_to_markdown(body)}\n" except Exception as e: logger.warning(f"Could not fetch comments: {e}") if include_history: # Add history section try: history_data = await confluence_client.get_page_history(page_id) if history_data.get("results"): response += "\n\n**History:**\n" for version_info in history_data["results"]: version_number = version_info.get("number", "Unknown") author = version_info.get("by", {}).get("displayName", "Unknown") date = version_info.get("when", "Unknown") response += f"- Version {version_number} by {author} on {date}\n" except Exception as e: logger.warning(f"Could not fetch history: {e}") return [ types.TextContent( type="text", text=response, ) ] - ConfluenceClient.get_page() - the low-level API call that retrieves a Confluence page by ID with optional expand parameters. Used by the handler to fetch page content.
async def get_page(self, page_id: str, expand: Optional[str] = None) -> Dict[str, Any]: """Get a Confluence page by its ID.""" params = {} if expand: params["expand"] = expand return await self.get(f"content/{page_id}", params=params) async def get_page_by_title(self, space_key: str, title: str) -> Optional[Dict[str, Any]]: """Get a page by its title in a specific space.""" params = { "title": title, "spaceKey": space_key, "expand": "body.storage", "limit": 1 } result = await self.get("content", params=params) if result.get("results") and len(result["results"]) > 0: return result["results"][0] return None async def create_page(self, space_key: str, title: str, content: str, parent_id: Optional[str] = None) -> Dict[str, Any]: """Create a new Confluence page.""" data = { "type": "page", "title": title, "space": {"key": space_key}, "body": { "storage": { "value": content, "representation": "storage" } } } if parent_id: data["ancestors"] = [{"id": parent_id}] return await self.post("content", data) async def update_page(self, page_id: str, title: str, content: str, version: int) -> Dict[str, Any]: """Update an existing Confluence page.""" data = { "type": "page", "title": title, "body": { "storage": { "value": content, "representation": "storage" } }, "version": { "number": version + 1 } } return await self.put(f"content/{page_id}", data) async def add_comment(self, page_id: str, comment: str) -> Dict[str, Any]: """Add a comment to a Confluence page.""" data = { "type": "comment", "container": {"id": page_id, "type": "page"}, "body": { "storage": { "value": comment, "representation": "storage" } } } return await self.post("content", data) async def get_comments(self, page_id: str, start: int = 0, limit: int = 25) -> Dict[str, Any]: """Get comments for a Confluence page.""" params = { "start": start, "limit": limit, "expand": "body.storage" } return await self.get(f"content/{page_id}/child/comment", params=params) async def get_page_comments(self, page_id: str) -> Dict[str, Any]: """Get comments for a Confluence page (alias for get_comments).""" return await self.get_comments(page_id) async def get_page_history(self, page_id: str) -> Dict[str, Any]: """Get version history for a Confluence page.""" return await self.get(f"content/{page_id}/version", params={"expand": "by"}) - ConfluenceClient.get_page_comments() - retrieves comments for a Confluence page, used when include_comments=True.
async def get_comments(self, page_id: str, start: int = 0, limit: int = 25) -> Dict[str, Any]: """Get comments for a Confluence page.""" params = { "start": start, "limit": limit, "expand": "body.storage" } return await self.get(f"content/{page_id}/child/comment", params=params) async def get_page_comments(self, page_id: str) -> Dict[str, Any]: """Get comments for a Confluence page (alias for get_comments).""" return await self.get_comments(page_id) - ConfluenceClient.get_page_history() - retrieves version history for a Confluence page, used when include_history=True.
async def get_page_history(self, page_id: str) -> Dict[str, Any]: """Get version history for a Confluence page.""" return await self.get(f"content/{page_id}/version", params={"expand": "by"})