logseq-mcp-server

jimsynz/logseq-mcp-server

3.3

If you are the rightful owner of logseq-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The LogSeq MCP Server is a Model Context Protocol server that integrates with LogSeq's HTTP API, allowing AI assistants to interact with your LogSeq knowledge graph.

Tools
14
Resources
0
Prompts
0

๐Ÿ—ƒ๏ธ LogSeq MCP Server

A Model Context Protocol (MCP) server that provides comprehensive access to LogSeq's HTTP API, enabling AI assistants like Claude to interact with your LogSeq knowledge graph. โœจ

๐Ÿ“‹ Overview

This server bridges LogSeq and MCP clients by exposing LogSeq's HTTP API as MCP tools. It allows AI assistants to:

  • ๐Ÿ“– Read and create pages and blocks
  • ๐Ÿ” Search your knowledge graph
  • ๐Ÿ—„๏ธ Execute powerful Datascript queries
  • โš™๏ธ Access graph metadata and configuration

The server communicates with LogSeq's built-in HTTP API server, which runs locally alongside your LogSeq application. ๐Ÿ–ฅ๏ธ

๐Ÿ“ฆ Installation

Install directly from the Git repository using Cargo:

cargo install --locked --git https://harton.dev/james/logseq-mcp-server.git logseq-mcp-server

๐Ÿ› ๏ธ Setup

1. ๐Ÿ”ง Enable LogSeq HTTP API

Step-by-Step Instructions:
  1. Open LogSeq Settings ๐Ÿ“ฑ

    • Launch LogSeq on your computer
    • Click the Settings icon (usually in the top-right corner)
  2. Navigate to Features ๐ŸŽ›๏ธ

    • In the Settings menu, find and click on Features
    • This opens the features configuration panel
  3. Enable HTTP APIs Server ๐ŸŒ

    • Look for "HTTP APIs Server" in the features list
    • Toggle the switch to enable the HTTP APIs Server
    • The server will start automatically once enabled
  4. Configure Authorization Token ๐Ÿ”‘

    • After enabling the API server, you need to set up authentication
    • Look for "Authorization tokens" section in the API settings
    • Click "Add new token"
    • Fill in the token details:
      • Name: logseq-mcp-server (or any descriptive name)
      • Value: Generate a secure random string (e.g., mcp-token-abc123def456)
    • Save the token configuration
  5. Configure Auto-Start (Recommended) ๐Ÿš€

    • In the "Server configurations" section
    • Enable "Auto start server with the app launched"
    • Click "Save & Apply"
  6. Start the Server โ–ถ๏ธ

    • If auto-start is not enabled, manually start the server
    • Look for "Start Server" button in the API panel
    • The server typically runs on http://localhost:12315

๐Ÿ’ก Pro Tip: Keep your authorization token secure and private. It grants access to your entire LogSeq graph!

2. ๐Ÿ” Configure Environment Variables

The server requires these environment variables:

export LOGSEQ_API_URL="http://localhost:12315"  # Default LogSeq API URL
export LOGSEQ_API_TOKEN="your-api-token-here"  # Token from LogSeq settings

3. ๐Ÿค– Configure Claude Desktop

Add the server to your claude_desktop_config.json:

๐Ÿ“ macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
๐Ÿ“ Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "logseq": {
      "command": "logseq-mcp-server",
      "env": {
        "LOGSEQ_API_URL": "http://localhost:12315",
        "LOGSEQ_API_TOKEN": "your-api-token-here"
      }
    }
  }
}

4. ๐Ÿงช Test Your Connection

Test that the API connection and authentication are working:

logseq-mcp-server --check

If successful, you'll see:

โœ“ Connection successful! Found X pages in LogSeq.

If there are issues, you'll see error messages to help debug the problem.

5. ๐Ÿ”„ Restart Claude Desktop

Restart Claude Desktop to load the new server configuration. ๐Ÿš€

๐Ÿงฐ Available Tools

The server provides 13 MCP tools organized into these categories:

๐Ÿ“„ Page Management

  • list_pages ๐Ÿ“‹ - List all pages in your LogSeq graph
  • get_page ๐Ÿ“ƒ - Get specific page information by name or UUID
  • get_page_content ๐Ÿ“ - Get page content formatted as markdown
  • create_page โž• - Create new pages with optional properties (tags, template, alias, etc.)
  • get_current_page ๐Ÿ‘๏ธ - Get the currently active page

๐Ÿงฑ Block Operations

  • get_block ๐ŸŸฆ - Get specific block by UUID
  • create_block โœ๏ธ - Insert new blocks with positioning options
  • update_block ๐Ÿ“ - Update the content of an existing block
  • get_current_block ๐ŸŽฏ - Get the currently active block

๐Ÿ” Search & Query

  • search ๐Ÿ•ต๏ธ - Search across all pages using LogSeq's built-in search
  • datascript_query ๐Ÿ—„๏ธ - Execute Datascript queries against the LogSeq database

โš™๏ธ Application Info

  • get_current_graph ๐ŸŒ - Get information about the current graph
  • get_user_configs ๐Ÿ‘ค - Get user configuration settings
  • get_state_from_store ๐Ÿ’พ - Get application state values (theme, UI settings, etc.)

๐Ÿš€ Example Usage with Claude

Once configured, you can ask Claude to:

"Show me all my pages about machine learning" ๐Ÿค–
"Create a new page called 'Project Ideas' with the tag 'brainstorming'" ๐Ÿ’ก
"Search for blocks containing 'TODO' and show me the results" โœ…
"What's the current theme setting in my LogSeq?" ๐ŸŽจ
"Execute this Datascript query to find all pages created this week" ๐Ÿ“…

๐Ÿ”ฌ Advanced: Datascript Queries

Use the datascript_query tool for powerful database queries:

# Find all blocks with content
[:find ?e :where [?e :block/content]]

# Find all pages
[:find ?page :where [?page :block/name]]

# Find all TODO/DOING blocks
[:find ?h :where [?h :block/marker]]

# Find blocks referencing a specific page
[:find ?b :where [?b :block/refs ?r] [?r :block/name "Project Ideas"]]

๐Ÿ”ง Troubleshooting

โš ๏ธ Common Issues

  1. "401 Unauthorized" ๐Ÿšซ - Check that your API token is correct
  2. "Connection refused" ๐Ÿ”Œ - Ensure LogSeq is running and HTTP API is enabled
  3. "Method not found" โ“ - Verify you're using the correct API method names

๐Ÿ“Š Logging

The server logs to stderr. To see detailed logs:

RUST_LOG=debug logseq-mcp-server

๐Ÿงช Testing with MCP Inspector

You can test the server using the MCP Inspector:

npx @modelcontextprotocol/inspector

Configure it to use logseq-mcp-server as the command.

๐Ÿ“‹ Supported LogSeq API Methods

This server exposes the following confirmed working LogSeq HTTP API methods:

  • โœ… logseq.Editor.getAllPages
  • โœ… logseq.Editor.getPage
  • โœ… logseq.Editor.getPageBlocksTree
  • โœ… logseq.Editor.createPage
  • โœ… logseq.Editor.getBlock
  • โœ… logseq.Editor.getCurrentPage
  • โœ… logseq.Editor.getCurrentBlock
  • โœ… logseq.Editor.insertBlock
  • โœ… logseq.Editor.updateBlock
  • โœ… logseq.DB.datascriptQuery
  • โœ… logseq.App.getCurrentGraph
  • โœ… logseq.App.getStateFromStore
  • โœ… logseq.App.getUserConfigs

๐Ÿค Contributing

This project welcomes contributions! Please feel free to:

  • ๐Ÿ› Report bugs and issues
  • ๐Ÿ’ก Suggest new features
  • ๐Ÿ”ง Submit pull requests
  • ๐Ÿ“š Improve documentation

๐Ÿ“„ License

This project is licensed under the MIT License - see the file for details.

๐Ÿ‘จโ€๐Ÿ’ป Author

James Harton james@harton.nz

๐Ÿ”— Links

Github Mirror

This repository is mirrored on Github from it's primary location on my Forgejo instance. Feel free to raise issues and open PRs on Github.