Skip to main content
Glama
dailydaniel

Logseq MCP Server

logseq_insert_block

Insert new blocks into Logseq to create page-level or nested blocks, manage properties, and set custom UUIDs. Specify positioning relative to parent blocks for precise organization and reference.

Instructions

Insert a new block into Logseq. Can create: - Page-level blocks (use is_page_block=true with page name as parent_block) - Nested blocks under existing blocks - Blocks with custom UUIDs for precise reference Supports before/after positioning and property management.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
beforeNoInsert before parent
contentYesContent of the new block
custom_uuidNoCustom UUID for block
is_page_blockNoPage-level block flag
parent_blockNoUUID or content of parent block

Implementation Reference

  • Handler implementation within @server.call_tool(): parses InsertBlockParams, calls Logseq API method 'logseq.Editor.insertBlock' with parameters, formats and returns the result as TextContent.
    if name == "logseq_insert_block":
        args = InsertBlockParams(**arguments)
        result = make_request(
            "logseq.Editor.insertBlock",
            [
                args.parent_block,
                args.content,
                {
                    "isPageBlock": args.is_page_block,
                    "before": args.before,
                    "customUUID": args.custom_uuid
                }
            ]
        )
        return [TextContent(
            type="text",
            text=format_block_result(result)
        )]
  • Pydantic model defining input schema for logseq_insert_block tool with fields: parent_block, content, is_page_block, before, custom_uuid, including validator for block references.
    class InsertBlockParams(LogseqBaseModel):
        """Parameters for inserting a new block in Logseq."""
        parent_block: Annotated[
            Optional[str],
            Field(default=None, description="UUID or content of parent block")
        ]
        content: Annotated[
            str,
            Field(description="Content of the new block")
        ]
        is_page_block: Annotated[
            Optional[bool],
            Field(default=False, description="Page-level block flag")
        ]
        before: Annotated[
            Optional[bool],
            Field(default=False, description="Insert before parent")
        ]
        custom_uuid: Annotated[
            Optional[str],
            Field(default=None, description="Custom UUID for block")
        ]
    
        @field_validator('parent_block', 'custom_uuid', mode='before')
        @classmethod
        def validate_block_references(cls, value):
            """Validate block/page references"""
            if value and isinstance(value, str):
                if value.startswith('((') and value.endswith('))'):
                    return value.strip('()')
            return value
  • Tool registration in @server.list_tools() defining name, description, and inputSchema from InsertBlockParams.
    Tool(
        name="logseq_insert_block",
        description="""Insert a new block into Logseq. Can create:
        - Page-level blocks (use is_page_block=true with page name as parent_block)
        - Nested blocks under existing blocks
        - Blocks with custom UUIDs for precise reference
        Supports before/after positioning and property management.""",
        inputSchema=InsertBlockParams.model_json_schema(),
    ),
  • Helper function to format the result of block insertion into a readable string used in handler response.
    def format_block_result(result: dict) -> str:
        """Format block creation result into readable text."""
        return (
            f"Created block in {result.get('page', {}).get('name', 'unknown page')}\n"
            f"UUID: {result.get('uuid')}\n"
            f"Content: {result.get('content')}\n"
            f"Parent: {result.get('parent', {}).get('uuid') or 'None'}"
        )
  • Prompt registration in @server.list_prompts() for logseq_insert_block with argument definitions.
    Prompt(
        name="logseq_insert_block",
        description="Create a new block in Logseq",
        arguments=[
            PromptArgument(
                name="parent_block",
                description="Parent block UUID or page name (for page blocks)",
                required=False,
            ),
            PromptArgument(
                name="content",
                description="Block content in Markdown/Org syntax",
                required=True,
            ),
            PromptArgument(
                name="is_page_block",
                description="Set true for page-level blocks",
                required=False,
            ),
        ],
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses key behavioral traits like support for 'before/after positioning and property management,' which are not obvious from the schema alone. However, it lacks details on permissions needed, error conditions, or what happens on failure, leaving gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, starting with the core action and immediately listing capabilities in a bullet-like structure. Every sentence adds value, though the formatting with colons and dashes could be slightly cleaner for optimal readability.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a block insertion tool with 5 parameters, no annotations, and no output schema, the description is moderately complete. It covers key use cases and parameters but lacks information on return values, error handling, or integration with sibling tools, leaving some contextual gaps for an agent to operate effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds minimal value by mentioning 'before/after positioning' (hinting at the 'before' parameter) and 'custom UUIDs' (referencing 'custom_uuid'), but does not provide additional semantics beyond what the schema specifies, meeting the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Insert a new block') and resource ('into Logseq'), distinguishing it from siblings like logseq_create_page (creates pages) and logseq_edit_block (modifies existing blocks). It provides concrete examples of what can be created, making the purpose unambiguous and differentiated.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context on when to use this tool by listing the types of blocks it can create (page-level, nested, with custom UUIDs). However, it does not explicitly state when NOT to use it or name specific alternatives among the sibling tools, such as using logseq_create_page for creating new pages instead of page-level blocks.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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

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