Skip to main content
Glama

insert_block

Insert a new block as a child under a specified parent block in Logseq to organize hierarchical content. Set properties, control placement (beginning or end), and inherit journal attributes when applicable.

Instructions

Inserts a new block as a child of the specified parent block. This allows for creating hierarchical content by adding children to existing blocks. IMPORTANT NOTES: 1. All blocks are automatically formatted as bullet points in Logseq UI 2. To create links to other pages, use double brackets: [[Page Name]] 3. The new block will be inserted at the beginning or end of the parent's children depending on the 'before' parameter When inserting blocks into journal pages: - The block will inherit the "journal?" and "journalDay" attributes - "journalDay" will be in YYYYMMDD format (e.g., 20250404 for April 4, 2025) Args: parent_block_id (str): The ID of the parent block to insert under. content (str): The content of the new block. properties (dict, optional): Properties to set on the new block. before (bool, optional): Whether to insert at the beginning of children. Default is False (append at the end). Returns: dict: Information about the created block.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
beforeNo
contentYes
parent_block_idYes
propertiesNo

Implementation Reference

  • MCP tool handler for 'insert_block': inserts a new block as a child of a parent block by calling the Logseq client. Includes type hints and docstring for schema.
    @mcp.tool() def insert_block(parent_block_id: str, content: str, properties: Optional[Dict] = None, before: bool = False) -> Dict: """ Inserts a new block as a child of the specified parent block. This allows for creating hierarchical content by adding children to existing blocks. IMPORTANT NOTES: 1. All blocks are automatically formatted as bullet points in Logseq UI 2. To create links to other pages, use double brackets: [[Page Name]] 3. The new block will be inserted at the beginning or end of the parent's children depending on the 'before' parameter When inserting blocks into journal pages: - The block will inherit the "journal?" and "journalDay" attributes - "journalDay" will be in YYYYMMDD format (e.g., 20250404 for April 4, 2025) Args: parent_block_id (str): The ID of the parent block to insert under. content (str): The content of the new block. properties (dict, optional): Properties to set on the new block. before (bool, optional): Whether to insert at the beginning of children. Default is False (append at the end). Returns: dict: Information about the created block. """ """Insert a new block under the specified parent block.""" return logseq_client.insert_block(parent_block_id, content, properties, before)
  • Low-level LogseqAPIClient method that calls the Logseq API (insertBlock or prependBlock) to insert the block.
    def insert_block(self, parent_block_id: str, content: str, properties: Dict = None, before: bool = False) -> Dict: """Insert a new block as a child of the specified parent block""" params = [parent_block_id, content] if properties: params.append(properties) # Choose the appropriate API method based on the 'before' parameter method = "logseq.Editor.insertBlock" if before: method = "logseq.Editor.prependBlock" response = self.call_api(method, params) if isinstance(response, dict) and "result" in response: return response.get("result") return response
  • Re-exports the insert_block tool function along with others, likely for module-level registration in MCP.
    from .pages import get_all_pages, get_page, create_page, delete_page, get_page_linked_references from .blocks import get_page_blocks, get_block, create_block, update_block, remove_block, insert_block, move_block, search_blocks __all__ = [ "get_all_pages", "get_page", "create_page", "delete_page", "get_page_blocks", "get_block", "create_block", "update_block", "remove_block", "insert_block", "move_block", "search_blocks", "get_page_linked_references", ]

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

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