Skip to main content
Glama
ergut

MCP server for LogSeq

by ergut

update_page

Modify LogSeq pages by adding content or updating properties through API calls.

Instructions

Update a page in LogSeq with new content and/or properties.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
page_nameYesName of the page to update
contentNoNew content to append to the page (optional)
propertiesNoPage properties to update (optional)

Implementation Reference

  • UpdatePageToolHandler class: the core handler implementation for the 'update_page' tool. Includes schema definition and run_tool logic that validates inputs, calls the LogSeq API, and formats the response.
    class UpdatePageToolHandler(ToolHandler):
        def __init__(self):
            super().__init__("update_page")
    
        def get_tool_description(self):
            return Tool(
                name=self.name,
                description="Update a page in LogSeq with new content and/or properties.",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "page_name": {
                            "type": "string",
                            "description": "Name of the page to update"
                        },
                        "content": {
                            "type": "string",
                            "description": "New content to append to the page (optional)"
                        },
                        "properties": {
                            "type": "object",
                            "description": "Page properties to update (optional)",
                            "additionalProperties": True
                        }
                    },
                    "required": ["page_name"]
                }
            )
    
        def run_tool(self, args: dict) -> list[TextContent]:
            if "page_name" not in args:
                raise RuntimeError("page_name argument required")
    
            page_name = args["page_name"]
            content = args.get("content")
            properties = args.get("properties")
            
            # Validate that at least one update is provided
            if not content and not properties:
                return [TextContent(
                    type="text",
                    text="āŒ Error: Either 'content' or 'properties' must be provided for update"
                )]
    
            try:
                api = logseq.LogSeq(api_key=api_key)
                result = api.update_page(page_name, content=content, properties=properties)
                
                # Build detailed success message
                success_msg = f"āœ… Successfully updated page '{page_name}'"
                
                # Show what was updated
                updates = result.get("updates", [])
                update_details = []
                
                for update_type, update_result in updates:
                    if update_type == "properties":
                        update_details.append("šŸ“ Properties updated")
                    elif update_type == "properties_fallback":
                        update_details.append("šŸ“ Properties updated (via fallback method)")
                    elif update_type == "content":
                        update_details.append("šŸ“„ Content appended")
                
                if update_details:
                    success_msg += f"\n{chr(10).join(update_details)}"
                
                success_msg += f"\nšŸ”„ Page '{page_name}' has been updated in LogSeq"
                
                return [TextContent(
                    type="text",
                    text=success_msg
                )]
            except ValueError as e:
                # Handle validation errors (page not found) gracefully
                return [TextContent(
                    type="text", 
                    text=f"āŒ Error: {str(e)}"
                )]
            except Exception as e:
                logger.error(f"Failed to update page: {str(e)}")
                return [TextContent(
                    type="text",
                    text=f"āŒ Failed to update page '{page_name}': {str(e)}"
                )]
  • Registration of the UpdatePageToolHandler in the MCP server using add_tool_handler.
    add_tool_handler(tools.UpdatePageToolHandler())
  • LogSeq.update_page method: the underlying API helper called by the tool handler to perform the actual LogSeq API calls for updating page content and properties, including fallback logic.
    def update_page(self, page_name: str, content: str = None, properties: dict = None) -> Any:
        """Update a LogSeq page with new content and/or properties."""
        url = self.get_base_url()
        logger.info(f"Updating page '{page_name}'")
        
        try:
            # Pre-update validation: verify page exists
            existing_pages = self.list_pages()
            page_names = [p.get("originalName") or p.get("name") for p in existing_pages if p.get("originalName") or p.get("name")]
            
            if page_name not in page_names:
                raise ValueError(f"Page '{page_name}' does not exist")
            
            results = []
            
            # Update properties if provided
            if properties:
                logger.debug(f"Updating properties for page '{page_name}': {properties}")
                try:
                    response = requests.post(
                        url,
                        headers=self._get_headers(),
                        json={
                            "method": "logseq.Editor.updatePage",
                            "args": [page_name, properties]
                        },
                        verify=self.verify_ssl,
                        timeout=self.timeout
                    )
                    response.raise_for_status()
                    prop_result = response.json()
                    results.append(("properties", prop_result))
                except Exception as e:
                    logger.warning(f"Failed to update properties with updatePage, trying setPageProperties: {str(e)}")
                    # Fallback to setPageProperties
                    response = requests.post(
                        url,
                        headers=self._get_headers(),
                        json={
                            "method": "logseq.Editor.setPageProperties",
                            "args": [page_name, properties]
                        },
                        verify=self.verify_ssl,
                        timeout=self.timeout
                    )
                    response.raise_for_status()
                    prop_result = response.json()
                    results.append(("properties_fallback", prop_result))
            
            # Update content if provided
            if content is not None:
                logger.debug(f"Updating content for page '{page_name}'")
                # Strategy: Get existing blocks and update them, or add new content
                # For now, we'll use appendBlockInPage to add new content
                # TODO: In future, implement block-level updates for more sophisticated content management
                
                response = requests.post(
                    url,
                    headers=self._get_headers(),
                    json={
                        "method": "logseq.Editor.appendBlockInPage",
                        "args": [page_name, content]
                    },
                    verify=self.verify_ssl,
                    timeout=self.timeout
                )
                response.raise_for_status()
                content_result = response.json()
                results.append(("content", content_result))
            
            logger.info(f"Successfully updated page '{page_name}'")
            return {"updates": results, "page": page_name}
    
        except ValueError:
            # Re-raise validation errors as-is
            raise
        except Exception as e:
            logger.error(f"Error updating page '{page_name}': {str(e)}")
            raise
  • Input schema definition for the 'update_page' tool, defining parameters: page_name (required), content (optional), properties (optional).
    return Tool(
        name=self.name,
        description="Update a page in LogSeq with new content and/or properties.",
        inputSchema={
            "type": "object",
            "properties": {
                "page_name": {
                    "type": "string",
                    "description": "Name of the page to update"
                },
                "content": {
                    "type": "string",
                    "description": "New content to append to the page (optional)"
                },
                "properties": {
                    "type": "object",
                    "description": "Page properties to update (optional)",
                    "additionalProperties": True
                }
            },
            "required": ["page_name"]
        }
    )
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool updates a page but lacks details on permissions required, whether updates are reversible, how content appends (e.g., overwrite or add), rate limits, or error conditions. This is a significant gap for a mutation tool with zero annotation coverage.

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

Conciseness5/5

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

The description is a single, efficient sentence that front-loads the core purpose ('Update a page in LogSeq') and specifies key aspects ('with new content and/or properties'). There is no wasted verbiage, making it appropriately sized for the tool's complexity.

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

Completeness2/5

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

Given the tool's mutation nature, lack of annotations, and no output schema, the description is incomplete. It doesn't address behavioral traits like side effects, error handling, or return values, which are critical for an update operation. The schema covers parameters well, but overall context for safe and effective use is inadequate.

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 three parameters (page_name, content, properties) with their types and optionality. The description adds minimal value by mentioning 'new content and/or properties', which aligns with but doesn't expand beyond the schema's parameter descriptions.

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

Purpose4/5

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

The description clearly states the action ('Update') and resource ('a page in LogSeq') with specific aspects ('new content and/or properties'). It distinguishes from siblings like 'create_page' (creation vs update) and 'delete_page' (destruction vs modification), though it doesn't explicitly differentiate from all siblings like 'get_page_content' or 'list_pages'.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention prerequisites (e.g., page must exist), exclusions (e.g., cannot update non-existent pages), or comparisons to siblings like 'create_page' for new pages or 'get_page_content' for read-only access.

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

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

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