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
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | Title of the new page | |
| content | Yes | Content of the new page |
Implementation Reference
- src/mcp_logseq/tools.py:25-64 (handler)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
- src/mcp_logseq/server.py:75-75 (registration)Registration of the CreatePageToolHandler instance in the MCP server using add_tool_handler.add_tool_handler(tools.CreatePageToolHandler())
- src/mcp_logseq/tools.py:30-47 (schema)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"] } )
- src/mcp_logseq/logseq.py:31-70 (helper)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