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
| Name | Required | Description | Default |
|---|---|---|---|
| before | No | ||
| content | Yes | ||
| parent_block_id | Yes | ||
| properties | No |
Implementation Reference
- src/logseq_mcp/tools/blocks.py:79-107 (handler)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
- src/logseq_mcp/tools/__init__.py:1-18 (registration)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", ]