Skip to main content
Glama

insert_block

Adds a new bullet point as a child to an existing block in Logseq, enabling hierarchical content organization and structured note-taking.

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
parent_block_idYes
contentYes
propertiesNo
beforeNo

Implementation Reference

  • MCP tool handler for 'insert_block'. Decorated with @mcp.tool(), defines input schema via signature and docstring, and implements logic by delegating to LogseqAPIClient.insert_block.
    @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)
  • Helper method in LogseqAPIClient that performs the actual API call to Logseq's insertBlock or prependBlock endpoint.
    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
  • Imports the insert_block tool from blocks.py, facilitating its exposure and registration when the tools module is imported.
    from .blocks import get_page_blocks, get_block, create_block, update_block, remove_block, insert_block, move_block, search_blocks
  • Lists 'insert_block' in __all__, ensuring it's exported from the tools package.
    "insert_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/mikeysrecipes/logseq-mcp'

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