Skip to main content
Glama
ergut

MCP server for LogSeq

by ergut

create_page

Add new pages to LogSeq with specified titles and content using API integration.

Instructions

Create a new page in LogSeq.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYesTitle of the new page
contentYesContent of the new page

Implementation Reference

  • The CreatePageToolHandler class defines the 'create_page' tool handler, including its schema, description, and execution logic. It validates inputs, creates a LogSeq API client, calls create_page on it, and returns success message.
    class CreatePageToolHandler(ToolHandler): def __init__(self): super().__init__("create_page") def get_tool_description(self): return Tool( name=self.name, description="Create a new page in LogSeq.", inputSchema={ "type": "object", "properties": { "title": { "type": "string", "description": "Title of the new page" }, "content": { "type": "string", "description": "Content of the new page" } }, "required": ["title", "content"] } ) def run_tool(self, args: dict) -> list[TextContent]: if "title" not in args or "content" not in args: raise RuntimeError("title and content arguments required") try: api = logseq.LogSeq(api_key=api_key) api.create_page(args["title"], args["content"]) return [TextContent( type="text", text=f"Successfully created page '{args['title']}'" )] except Exception as e: logger.error(f"Failed to create page: {str(e)}") raise
  • Registration of the CreatePageToolHandler instance in the MCP server using add_tool_handler.
    add_tool_handler(tools.CreatePageToolHandler())
  • Input schema definition for the create_page tool, specifying title and content as required string properties.
    return Tool( name=self.name, description="Create a new page in LogSeq.", inputSchema={ "type": "object", "properties": { "title": { "type": "string", "description": "Title of the new page" }, "content": { "type": "string", "description": "Content of the new page" } }, "required": ["title", "content"] } )
  • The LogSeq client's create_page method that handles the actual API calls to Logseq.Editor.createPage and optionally appendBlockInPage to create the page with content.
    def create_page(self, title: str, content: str = "") -> Any: """Create a new LogSeq page with specified title and content.""" url = self.get_base_url() logger.info(f"Creating page '{title}'") try: # Step 1: Create the page response = requests.post( url, headers=self._get_headers(), json={ "method": "logseq.Editor.createPage", "args": [title, {}, {"createFirstBlock": True}] }, verify=self.verify_ssl, timeout=self.timeout ) response.raise_for_status() page_result = response.json() # Step 2: Add content if provided if content and content.strip(): response = requests.post( url, headers=self._get_headers(), json={ "method": "logseq.Editor.appendBlockInPage", "args": [title, content] }, verify=self.verify_ssl, timeout=self.timeout ) response.raise_for_status() return page_result except Exception as e: logger.error(f"Error creating page: {str(e)}") raise

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