logseq_get_current_page_content
Retrieve the hierarchical block structure of the current page in Logseq, enabling LLMs to programmatically access and manage content within your knowledge graph.
Instructions
Get hierarchical block structure of current page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp_server_logseq/server.py:561-566 (handler)Main tool handler: calls Logseq API 'logseq.Editor.getCurrentPageBlocksTree' with no arguments and formats the hierarchical blocks tree result for output.elif name == "logseq_get_current_page_content": result = make_request("logseq.Editor.getCurrentPageBlocksTree", []) return [TextContent( type="text", text=format_blocks_tree(result) )]
- src/mcp_server_logseq/server.py:263-267 (registration)Tool registration in MCP server.list_tools(), defining name, description, and input schema (empty).Tool( name="logseq_get_current_page_content", description="Get hierarchical block structure of current page", inputSchema=GetCurrentBlocksTreeParams.model_json_schema() # No parameters ),
- Pydantic model defining the input schema for the tool (no parameters required).class GetCurrentBlocksTreeParams(LogseqBaseModel): pass
- Supporting function that recursively formats the Logseq blocks into a readable tree structure with indentation.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) )
- src/mcp_server_logseq/server.py:749-762 (handler)Prompt handler variant: similar logic for get_prompt() when used as a prompt.elif name == "logseq_get_current_page_content": result = make_request("logseq.Editor.getCurrentPageBlocksTree", []) return GetPromptResult( description="Current page content", messages=[ PromptMessage( role="user", content=TextContent( type="text", text=format_blocks_tree(result) ) ) ] )