list_pages
Retrieve all pages from a LogSeq graph, with an option to filter out journal entries for focused content management.
Instructions
Lists all pages in a LogSeq graph.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| include_journals | No | Whether to include journal/daily notes in the list |
Implementation Reference
- src/mcp_logseq/tools.py:65-125 (handler)ListPagesToolHandler class: implements the core logic for the list_pages tool. Handles arguments, calls LogSeq API to list pages, filters journal pages based on include_journals param, formats and sorts the page list, and returns formatted text output.class ListPagesToolHandler(ToolHandler): def __init__(self): super().__init__("list_pages") def get_tool_description(self): return Tool( name=self.name, description="Lists all pages in a LogSeq graph.", inputSchema={ "type": "object", "properties": { "include_journals": { "type": "boolean", "description": "Whether to include journal/daily notes in the list", "default": False } }, "required": [] } ) def run_tool(self, args: dict) -> list[TextContent]: include_journals = args.get("include_journals", False) try: api = logseq.LogSeq(api_key=api_key) result = api.list_pages() # Format pages for display pages_info = [] for page in result: # Skip if it's a journal page and we don't want to include those is_journal = page.get('journal?', False) if is_journal and not include_journals: continue # Get page information name = page.get('originalName') or page.get('name', '<unknown>') # Build page info string info_parts = [f"- {name}"] if is_journal: info_parts.append("[journal]") pages_info.append(" ".join(info_parts)) # Sort alphabetically by page name pages_info.sort() # Build response count_msg = f"\nTotal pages: {len(pages_info)}" journal_msg = " (excluding journal pages)" if not include_journals else " (including journal pages)" response = "LogSeq Pages:\n\n" + "\n".join(pages_info) + count_msg + journal_msg return [TextContent(type="text", text=response)] except Exception as e: logger.error(f"Failed to list pages: {str(e)}") raise
- src/mcp_logseq/tools.py:69-84 (schema)Tool schema definition for list_pages: defines optional boolean input 'include_journals' with default False.def get_tool_description(self): return Tool( name=self.name, description="Lists all pages in a LogSeq graph.", inputSchema={ "type": "object", "properties": { "include_journals": { "type": "boolean", "description": "Whether to include journal/daily notes in the list", "default": False } }, "required": [] } )
- src/mcp_logseq/server.py:76-76 (registration)Registration of the ListPagesToolHandler instance in the MCP server during tool handler setup.add_tool_handler(tools.ListPagesToolHandler())
- src/mcp_logseq/logseq.py:71-92 (helper)Underlying LogSeq API method list_pages(): makes HTTP POST to LogSeq's logseq.Editor.getAllPages RPC to retrieve all pages.def list_pages(self) -> Any: """List all pages in the LogSeq graph.""" url = self.get_base_url() logger.info("Listing pages") try: response = requests.post( url, headers=self._get_headers(), json={ "method": "logseq.Editor.getAllPages", "args": [] }, verify=self.verify_ssl, timeout=self.timeout ) response.raise_for_status() return response.json() except Exception as e: logger.error(f"Error listing pages: {str(e)}") raise