logseq-api-mcp

logseq-api-mcp

AI assistant integration with Logseq knowledge graph: 21 tools to read, write, query, and search notes, enabling seamless interaction with your notes.

Category
访问服务器

README

logseq-api-mcp

Your AI assistant starts every session blind to your Logseq knowledge graph. logseq-api-mcp fixes that: 21 tools to read, write, query, and search your notes — auto-registered the moment you drop a Python file into src/tools/.

Python License: MIT CI Coverage Tests Stars

<picture> <source media="(prefers-color-scheme: dark)" srcset="assets/architecture-dark.svg"> <source media="(prefers-color-scheme: light)" srcset="assets/architecture-light.svg"> <img src="assets/architecture-light.svg" alt="Architecture: AI Client → logseq-api-mcp (21 tools, privacy) → Logseq API → Knowledge Graph" width="960"> </picture>


Quick Start

Step 1 — Install

git clone https://github.com/gustavo-meilus/logseq-api-mcp.git
cd logseq-api-mcp
uv sync

Step 2 — Configure

cp .env.template .env
# open .env and set LOGSEQ_API_ENDPOINT and LOGSEQ_API_TOKEN

Getting your token: open Logseq, go to Settings → Features → Developer mode, enable HTTP APIs server, and copy the token shown. The default endpoint is http://127.0.0.1:12315/api.

Step 3 — Connect

// ~/.claude/claude_desktop_config.json
{
  "mcpServers": {
    "logseq-api": {
      "command": "uv",
      "args": ["run", "--directory", "/path/to/logseq-api-mcp", "python", "src/server.py"],
      "env": {
        "LOGSEQ_API_ENDPOINT": "http://127.0.0.1:12315/api",
        "LOGSEQ_API_TOKEN": "your_token_here"
      }
    }
  }
}

Restart Claude Desktop. All 21 tools are live.


Tools

Read (12 tools)

Tool What it does
get_all_pages Every page with ID, UUID, journal flag, and namespace
get_page_blocks Hierarchical block tree with IDs, UUIDs, and child counts
get_page_links Pages linking to a target page
get_page_backlinks Full backlink analysis including block-level references
get_block_content Block detail with properties and immediate children
get_all_page_content Complete page: properties, blocks, DB refs expanded
get_linked_flashcards Q&A flashcard pairs from a page and all linked pages
search Full-text search across blocks, pages, and file names
query Raw Datalog / DSL queries against the graph
find_pages_by_property Filter pages by property key and optional value
get_pages_from_namespace All pages under a Logseq namespace
get_pages_tree_from_namespace Nested tree of namespace pages

Write (10 tools)

Tool What it does
create_page Create a page with optional properties and format
delete_page Remove a page permanently
rename_page Rename a page and update all references
update_page Append or replace content on an existing page
append_block_in_page Add blocks at the end of a page
edit_block Replace a block's content by UUID
update_block Update block content by UUID
insert_nested_block Insert a child or sibling block relative to another block
delete_block Delete a block by UUID
set_block_properties Set structured properties on a block (DB-mode only)

Configuration

Variable Default Description
LOGSEQ_API_ENDPOINT http://127.0.0.1:12315/api Logseq HTTP API base URL
LOGSEQ_API_TOKEN (required) Bearer auth token
LOGSEQ_VERIFY_SSL true Set false to skip TLS verification
LOGSEQ_DB_MODE false Enable Logseq database-format API paths
LOGSEQ_EXCLUDE_TAGS (empty) Comma-separated tags — pages with any tag are hidden
LOGSEQ_LOG_LEVEL WARNING Log level: DEBUG, INFO, WARNING, ERROR

DB-Mode

Logseq's newer database format stores graph data in SQLite rather than markdown files. Set LOGSEQ_DB_MODE=true to unlock set_block_properties, UUID-reference resolution in get_all_page_content, and Datalog-powered queries in find_pages_by_property. Tools that do not apply in DB-mode return a clear error rather than silently failing.


Privacy

Any page tagged with a tag from LOGSEQ_EXCLUDE_TAGS disappears from every read operation. Enforcement runs at query time, so toggling the variable takes effect immediately.

Operation Behavior when page is excluded
get_all_pages Excluded pages absent from the listing
search Excluded pages and their blocks stripped from results
query Results post-filtered against excluded page names
find_pages_by_property Results post-filtered
get_page_backlinks Excluded source pages removed
get_all_page_content Returns ❌ Access denied for the excluded page

Adding a Tool

Create src/tools/my_tool.py. No imports, no registration, no config changes needed. The discovery system picks it up on the next server start.

from typing import List
from mcp.types import TextContent
from src.client.logseq_client import LogseqClient
from src.client.config import LogseqConfig, load_config
from src.logging_setup import get_logger

_log = get_logger(__name__)

async def _run(
    client: LogseqClient, config: LogseqConfig, param: str
) -> List[TextContent]:
    try:
        _log.debug("%s called", __name__)
        result = await client.some_api_method(param)
        return [TextContent(type="text", text=str(result))]
    except Exception as exc:
        _log.error("exception in %s: %s", __name__, exc, exc_info=True)
        return [TextContent(type="text", text=f"❌ Error: {exc}")]

async def my_tool(param: str) -> List[TextContent]:
    """One-line description — this becomes the MCP tool description."""
    cfg = load_config()
    return await _run(LogseqClient(cfg), cfg, param)

The _run(client, config, ...) pattern keeps the logic testable via FakeLogseqClient in tests/conftest.py. Function names starting with _ are not registered.


Development

uv sync --dev                                                        # all deps
uv run --group test pytest tests/ -v                                 # test suite (345 tests)
uv run --group test pytest tests/ --cov=src --cov-fail-under=85      # coverage gate
uv run ruff check --fix && uv run ruff format                        # lint + format
uv run mypy src/ --ignore-missing-imports                            # type check
uv run bandit -r src/                                                # security scan
uv run mcp dev src/server.py                                         # MCP inspector

Star History

Star History Chart


License

MIT — see LICENSE.


Made for the Logseq and MCP communities.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选