Skip to main content
Glama

fetch_page_markdown

Fetch a Confluence page and convert its HTML to Markdown, reducing token usage by 60-80% while preserving formatting, links, and structure.

Instructions

Fetch a Confluence page and convert it to Markdown format.

This tool retrieves page content and converts it from HTML to Markdown, reducing token usage by 60-80% compared to raw HTML while preserving formatting, links, and structure.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
page_idYesThe Confluence page ID to fetch

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the fetch_page_markdown tool. Decorated with @mcp.tool() to register as an MCP tool. Takes a Confluence page ID, fetches the page content via the ConfluenceClient, extracts metadata (title, space, version, URL, labels), converts the HTML body to Markdown using markdownify, and returns a formatted Markdown string with a metadata header.
    @mcp.tool()
    def fetch_page_markdown(page_id: str) -> str:
        """
        Fetch a Confluence page and convert it to Markdown format.
        
        This tool retrieves page content and converts it from HTML to Markdown,
        reducing token usage by 60-80% compared to raw HTML while preserving
        formatting, links, and structure.
        
        Args:
            page_id: The Confluence page ID to fetch
        
        Returns:
            Markdown-formatted page content with metadata header
        """
        try:
            if not page_id or not page_id.strip():
                return "Error: page_id parameter is required and cannot be empty"
            
            # Fetch page content
            page = confluence.get_page_content(page_id)
            
            # Extract metadata
            title = page.get("title", "Untitled")
            space_key = page.get("space", {}).get("key", "")
            space_name = page.get("space", {}).get("name", "")
            version = page.get("version", {}).get("number", 1)
            page_url = f"{CONFLUENCE_URL}/wiki{page.get('_links', {}).get('webui', '')}"
            
            # Extract HTML content
            html_content = page.get("body", {}).get("storage", {}).get("value", "")
            
            if not html_content:
                return f"Error: No content found for page ID {page_id}"
            
            # Convert HTML to Markdown
            markdown_content = md(
                html_content,
                heading_style="ATX",
                bullets="-",
                strip=['script', 'style']
            )
            
            # Extract labels if available
            labels = page.get("metadata", {}).get("labels", {}).get("results", [])
            label_names = [label.get("name") for label in labels if label.get("name")]
            
            # Format final output with metadata
            output = f"""# {title}
    
    **Space:** {space_name} ({space_key})  
    **Version:** {version}  
    **URL:** {page_url}
    """
            
            if label_names:
                output += f"**Labels:** {', '.join(label_names)}\n"
            
            output += f"\n---\n\n{markdown_content}"
            
            return output
        
        except Exception as e:
            logger.error(f"Error fetching page {page_id}: {e}")
            return f"Error: {str(e)}"
  • server.py:205-205 (registration)
    Registration of fetch_page_markdown as an MCP tool via the @mcp.tool() decorator from the FastMCP framework.
    @mcp.tool()
  • Helper method on ConfluenceClient that fetches page content from the Confluence API, expanding body.storage, space, version, and metadata.labels - used by fetch_page_markdown to retrieve page data.
    def get_page_content(self, page_id: str) -> dict:
        """Fetch a specific page with its content."""
        params = {
            "expand": "body.storage,space,version,metadata.labels"
        }
        return self._make_request("GET", f"/content/{page_id}", params=params)
  • Schema/docstring defining the input parameter (page_id: str) and the return type (str) for the fetch_page_markdown tool.
    Args:
        page_id: The Confluence page ID to fetch
    
    Returns:
        Markdown-formatted page content with metadata header
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must disclose behavioral traits. It mentions token reduction but omits critical details: it does not state whether the operation is read-only (only fetch), whether authentication is required, rate limits, or what happens if the page does not exist.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description consists of two short sentences, front-loaded with the primary action. Every sentence provides meaningful context without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

An output schema exists but is not shown, so return values are expected to be documented there. The description does not mention error handling, prerequisites (e.g., page must exist), or limitations (e.g., only works on Confluence pages). Lacks completeness for a minimal tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage for the single parameter page_id. The description adds no additional semantic information beyond what the schema already states ('The Confluence page ID to fetch'). Baseline of 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'Fetch a Confluence page and convert it to Markdown format', specifying the verb and resource. It distinguishes from siblings by implying that list_spaces and search_pages serve different purposes (listing spaces, searching pages).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for fetching page content but provides no explicit guidance on when to use this tool versus alternatives like list_spaces or search_pages. No exclusions or context for when not to use.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mazhar480/awesome-confluence-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server