Skip to main content
Glama
dailydaniel

Logseq MCP Server

logseq_get_page_content

Retrieve the hierarchical block content of a specific page from your Logseq knowledge graph, using the page name or UUID for targeted access.

Instructions

Get block hierarchy for specific page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
src_pageYesPage name or UUID

Implementation Reference

  • Main handler for logseq_get_page_content tool: parses arguments, calls Logseq API 'logseq.Editor.getPageBlocksTree', formats hierarchical block structure using format_blocks_tree, and returns as TextContent.
    elif name == "logseq_get_page_content":
        args = GetPageBlocksTreeParams(**arguments)
        result = make_request(
            "logseq.Editor.getPageBlocksTree",
            [args.src_page]
        )
        return [TextContent(
            type="text",
            text=format_blocks_tree(result)
        )]
  • Pydantic model defining input schema for the tool: requires 'src_page' parameter (page name or UUID). Used for validation in handler and tool registration.
    class GetPageBlocksTreeParams(LogseqBaseModel):
        src_page: Annotated[
            str,
            Field(description="Page name or UUID", examples=["[[Journal]]", "6485a-9de3..."])
        ]
  • Tool registration in @server.list_tools(): defines name, description, and input schema linking to GetPageBlocksTreeParams.
    Tool(
        name="logseq_get_page_content",
        description="Get block hierarchy for specific page",
        inputSchema=GetPageBlocksTreeParams.model_json_schema(),
    ),
  • Helper function to format the hierarchical block tree returned from Logseq API into a readable indented text representation, used in the tool handler.
    def format_blocks_tree(blocks: list) -> str:
        """Format hierarchical block structure"""
        def print_tree(block, level=0):
            output = []
            prefix = "  " * level + "- "
            output.append(f"{prefix}{block.get('content', '')}")
            for child in block.get('children', []):
                output.extend(print_tree(child, level + 1))
            return output
    
        return "\n".join(
            line for block in blocks
            for line in print_tree(block)
        )

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/dailydaniel/logseq-mcp'

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