insert_block
Add a new block as a child to an existing parent block in Logseq. Specify content, optional properties, and position (beginning or end) to organize hierarchical knowledge structures efficiently.
Instructions
Inserts a new block as a child of the specified parent block.
Creates hierarchical content by adding children to existing blocks.
The new block is inserted at the beginning (before=True) or end (before=False)
of the parent's children.
Args:
parent_block_id: The ID of the parent block to insert under.
content: The content of the new block.
properties: Optional properties to set on the new block.
before: Whether to insert at the beginning of children (default: False).
Returns:
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:63-81 (handler)MCP tool handler for 'insert_block', decorated with @mcp.tool() for automatic registration and schema generation from signature/docstring. Delegates 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. Creates hierarchical content by adding children to existing blocks. The new block is inserted at the beginning (before=True) or end (before=False) of the parent's children. Args: parent_block_id: The ID of the parent block to insert under. content: The content of the new block. properties: Optional properties to set on the new block. before: Whether to insert at the beginning of children (default: False). Returns: Information about the created block. """ return logseq_client.insert_block(parent_block_id, content, properties, before)
- Core implementation in LogseqAPIClient that calls the Logseq API ('logseq.Editor.insertBlock' or 'prependBlock') based on parameters.def insert_block(self, parent_block_id: str, content: str, properties: Optional[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