cwiki_get_page
Fetch a wiki page by title or page ID. Choose between plain, view, or storage format and optionally force a refresh of cached content.
Instructions
Fetch a wiki page by page title or page id.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | No | ||
| page_id | No | ||
| format | No | plain | |
| force_refresh | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/incubator_cwiki_mcp/tools.py:87-112 (handler)The main handler for the cwiki_get_page tool. It fetches a Confluence wiki page by title or page_id, retrieves its content in the requested format (plain, view, or storage), and returns a dict with page summary, ancestors, and content.
@mcp.tool() def cwiki_get_page( title: str | None = None, page_id: str | None = None, format: Literal["plain", "view", "storage"] = "plain", force_refresh: bool = False, ) -> dict[str, Any]: """Fetch a wiki page by page title or page id.""" if not title and not page_id: raise ValueError("Provide either title or page_id.") page = ( client.get_page_by_id(page_id, force_refresh=force_refresh) if page_id else client.get_page_by_title(title or "", force_refresh=force_refresh) ) return { **client.page_summary(page), "ancestors": [ {"id": ancestor.get("id"), "title": ancestor.get("title")} for ancestor in page.get("ancestors", []) ], "contentFormat": format, "content": page_content(page, format), } - Helper function page_content() called by cwiki_get_page to extract body content in storage, view, or plain (HTML-to-text) format.
def page_content(page: dict[str, Any], format: Literal["plain", "view", "storage"]) -> str: body = page.get("body", {}) if format == "storage": return body.get("storage", {}).get("value", "") view = body.get("view", {}).get("value") or body.get("storage", {}).get("value", "") return html_to_text(view) if format == "plain" else view - src/incubator_cwiki_mcp/tools.py:87-88 (registration)The @mcp.tool() decorator on line 87 registers cwiki_get_page as an MCP tool with the FastMCP server.
@mcp.tool() def cwiki_get_page( - Helper client.get_page_by_id() called by the handler when page_id is provided.
def get_page_by_id(page_id: str | None, *, force_refresh: bool = False) -> dict[str, Any]: if not page_id: raise ValueError("page_id must not be empty") return confluence_get( f"/rest/api/content/{urllib.parse.quote(page_id)}", {"expand": "body.storage,body.view,version,history,ancestors,space"}, force_refresh=force_refresh, ) - Helper client.get_page_by_title() called by the handler when title is provided.
def get_page_by_title(title: str, *, force_refresh: bool = False) -> dict[str, Any]: if not title.strip(): raise ValueError("title must not be empty") pages = confluence_get( "/rest/api/content", { "spaceKey": SPACE_KEY, "title": title, "type": "page", "status": "current", "limit": "2", "expand": "body.storage,body.view,version,history,ancestors,space", }, force_refresh=force_refresh, ) results = pages.get("results", []) if not results: raise ValueError(f'No page found with title "{title}" in space {SPACE_KEY}.') if len(results) > 1: raise ValueError(f'More than one page matched title "{title}". Use page_id instead.') return results[0]