siyuan-note-mcp
Provides tools for interacting with the SiYuan note-taking application, enabling search, read, write, and management of notebooks, documents, and content blocks through the MCP server.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@siyuan-note-mcp search my notes for 'MCP setup'"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
siyuan-note-mcp
把 思源笔记(SiYuan)接入任何 MCP 客户端——Claude Desktop、Cursor、Cline、DeepSeek Harness 等。装上后,你的 agent 就能直接搜索、读取和写入思源里的笔记本、文档与内容块。
特性
13 个工具覆盖日常读写:笔记本、文档、内容块、全文搜索、SQL 查询
零配置起步 — 默认连本机
http://127.0.0.1:6806,本地思源免 token按 ID 或路径寻址 — 文档既可用 ID,也可用
/笔记/我的文档这样的人类可读路径只读 SQL 保护 —
sql_query只放行SELECT/WITH/EXPLAIN错误可自愈 — 内核报错原文回传给模型,附带修正建议
Related MCP server: SiYuan MCP Server
安装
需要 Node.js ≥ 20,且思源笔记正在运行。
免安装,用 npx 直接跑:
npx -y siyuan-note-mcp或全局安装:
npm install -g siyuan-note-mcp
siyuan-note-mcp注意:npm 上已有的
siyuan-mcp是另一个项目,本包名是siyuan-note-mcp。
开发或想改代码时,从源码构建:
git clone https://github.com/Miles1994/siyuan-mcp.git
cd siyuan-mcp
npm install && npm run build从源码运行必须执行
npm run build——仓库不包含lib/构建产物,不构建就没有可运行的文件。(npm 上发布的包里已经带好了lib/。)
客户端配置
推荐:npx 免安装
{
"mcpServers": {
"siyuan": {
"command": "npx",
"args": ["-y", "siyuan-note-mcp"]
}
}
}连接远程或开启鉴权的内核时,再加环境变量:
{
"mcpServers": {
"siyuan": {
"command": "npx",
"args": ["-y", "siyuan-note-mcp"],
"env": {
"SIYUAN_API_URL": "http://192.168.1.5:6806",
"SIYUAN_TOKEN": "你的 API token"
}
}
}
}从源码运行
把 args 换成你 clone 下来的实际路径(Windows 下用正斜杠 /):
{
"mcpServers": {
"siyuan": {
"command": "node",
"args": ["/path/to/siyuan-mcp/lib/cli.js"]
}
}
}API token 在思源的 设置 → 关于 里查看。
Windows 上用 npx 报 spawn ENOENT:部分客户端不解析
npx.cmd包装。把command改为cmd、args改为["/c", "npx", "-y", "siyuan-note-mcp"]即可。
配置项
环境变量 | 默认值 | 说明 |
|
| 思源内核地址,别名 |
| 无 | API token,仅在开启鉴权时需要 |
|
| 单次请求超时(毫秒) |
思源默认只监听 127.0.0.1 且不校验 token。把内核暴露到局域网时请务必在设置里开启鉴权并配置 SIYUAN_TOKEN。
工具一览
工具 | 作用 |
| 列出所有笔记本及 ID、开关状态。需要笔记本 ID 时先调它 |
| 全文搜索,返回块 ID 与文档路径。支持 |
| 按最近更新列出文档,可按笔记本过滤 |
| 读取文档全文(Markdown)。接受文档 ID 或 |
| 读取单个块: |
| 用 Markdown 创建文档,父文档不存在会自动创建 |
| 追加/插入内容块到指定父块或某个块之后 |
| 替换某个块的内容 |
| 删除块(连同子块) |
| 重命名文档 |
| 移动文档到别的父文档或笔记本 |
| 删除文档(进回收站,可从「数据历史」恢复) |
| 对思源索引执行只读 SQL。主表 |
设计说明
为什么 sql_query 只能读
思源的 /api/query/sql 虽然文档上叫查询接口,但内核实际允许通过它执行写入——实测 3.8.4:DELETE FROM blocks WHERE 1=0 正常返回 code: 0。
原样暴露的话,模型就能绕过所有块级写工具直接改索引。因此本项目在本地拦截写操作,且用词法分析而非关键字正则:注释和字符串字面量里的关键字会被忽略,所以 WHERE content = 'please delete this' 能过,SELECT 1; DROP TABLE blocks 会被拒。
索引延迟
思源的 SQL 索引和全文索引是异步更新的,实测写入后约 2 秒才可见;而文档路径解析走文档树接口(getIDsByHPath),立即可见。所以:
刚创建的文档,用路径或 ID 读取立刻可用
list_documents、search_notes、sql_query这类走索引的结果,可能要等一两秒
这是内核的最终一致性设计,不是 bug。测试中的对应处理见 tests/e2e.spec.ts 的 waitFor。
DeepSeek Harness (DSH)
DSH 通过 @deepseek-ai/dsh-mcp-client 挂载外部服务器,配置在 ~/.dsh/profiles/<profile>/cordis.patch.yml。
装了 dsh-skill-mcp-panel 的话,该文件中的 MCP 区块由它托管,不要手改区块内内容(会被覆盖),改用它的 CLI:
dsh-panel mcp add --name siyuan --stdio --command npx \
--args -y --args siyuan-note-mcp --profile web
dsh-panel mcp test siyuan --profile web # 验证连通性
dsh-panel mcp list --profile web # 查看启用状态
--args每次只吃一个值,多个参数要重复写;mcp子命令必须显式给--profile。
否则手动插入这段(cordis.patch.yml 顶层是一个数组):
- insert:
- id: mcp-siyuan
name: "@deepseek-ai/dsh-mcp-client"
config:
serverName: siyuan
transport: stdio
command: npx
args:
- "-y"
- siyuan-note-mcp
env:
SIYUAN_API_URL: http://127.0.0.1:6806
cwd: ""工具会以 mcp__siyuan__search_notes、mcp__siyuan__get_document 这样的名字出现。
args里的路径不要加引号。stdio 直接传参数数组、不经过 shell,写成'"/path/to/cli.js"'会把引号当成文件名的一部分,spawn 时报 ENOENT。
开发
npm run build # 构建到 lib/
npm test # 单元测试
npm run typecheck # 类型检查端到端测试会直接连你本机的思源,创建并删除一个临时文档;检测不到内核时自动跳过:
npx vitest run tests/e2e.spec.ts发布(维护者)
package.json 里的 publishConfig 已把发布目标钉在 registry.npmjs.org——本机 npm 源即使配成镜像站也不会发错地方。
npm 现在强制要求发布者启用 2FA,账号没 2FA 时 npm publish 会直接 403:
Two-factor authentication or granular access token with bypass 2fa enabled is required to publish packages.注意:npm login 拿到的登录 token 不能发布,必须走下面两条之一。
A. 交互发布 — 在 https://www.npmjs.com/settings/~/tfa 启用 Authenticator app(TOTP),然后每次发布带上当次的验证码:
npm publish --otp=<6 位验证码>B. 自动化发布 — 在 https://www.npmjs.com/settings/~/tokens 建 Granular Access Token,权限给 Read and write,并勾选 Bypass 2FA,用环境变量传入(不要写进 .npmrc 提交):
# macOS / Linux
NPM_TOKEN=npm_xxx npm publish "--//registry.npmjs.org/:_authToken=$NPM_TOKEN"# Windows PowerShell
$env:NPM_TOKEN = 'npm_xxx'
npm publish "--//registry.npmjs.org/:_authToken=$env:NPM_TOKEN"完整流程:
npm test && npm run typecheck # 先过测试
npm version patch # 或 minor / major
npm publish --otp=<验证码> # prepare 钩子会自动构建 lib/发布前建议先 npm pack --dry-run 确认打包内容(应只有 lib/、README.md、LICENSE、package.json,共 8 个文件)。
长期建议迁到 trusted publishing (OIDC):npm 计划从 2027 年 1 月起收紧 Bypass-2FA token 的直接发布能力。 npm 页面上的 README 取自发布时的 tarball,改完 README 要发新版本才会同步。
许可
MIT
Available Tools
13 toolscreate_documentCreate documentA
Create a document from Markdown. path is the human-readable path, e.g. /Notes/Idea; missing parent documents are created automatically. An existing path is not overwritten — a new document is created alongside it.
Inputs: path (required), notebook (required), markdown.
delete_blockDelete blockA
Delete a block (and its children) by ID. Deleting a document block removes the whole document. Use get_document or search_notes first to confirm the target.
Inputs: id (required).
get_blockGet blockA
Read one block by ID. kramdown returns the source including block attributes (IDs, made useful for locating nested blocks to edit); children lists direct child blocks.
Inputs: id (required), format.
get_documentGet document contentA
Read a document as Markdown. Accepts a document ID or a human-readable path such as /Notes/My doc. This is the primary way to read note content.
Inputs: doc (required).
insert_blockInsert blockA
Append Markdown as new blocks. With parent_id the content is appended inside that block (use a document ID to append to a document); with previous_id it is inserted directly after that block. Provide exactly one of them.
Inputs: data (required), parent_id, previous_id.
list_documentsList documentsA
List documents in the workspace or in one notebook, most recently updated first. Useful for browsing what exists before searching.
Inputs: limit, notebook.
list_notebooksList notebooksA
List every notebook (思源笔记本) in the workspace with its ID, name and open state. Call this first when you need a notebook ID for other tools.
Inputs: no named parameters.
move_documentMove documentA
Move a document under a different parent document, or into a different notebook. to may be a parent document ID/path, or a notebook ID/name to move it to that notebook's root.
Inputs: to (required), doc (required).
remove_documentRemove documentB
Delete a document. Accepts a document ID or a path. The document is moved to the workspace trash (数据历史) and can be recovered from SiYuan.
Inputs: doc (required).
rename_documentRename documentC
Change the title of a document. Accepts a document ID or a path.
Inputs: doc (required), title (required).
search_notesSearch notesA
Full-text search across the workspace and return matching blocks with their IDs and document paths. Use this to locate content before reading or editing it. Supports SiYuan search syntax, e.g. foo bar (AND), "exact phrase", foo OR bar, -exclude, * wildcard.
Inputs: query (required), page, pageSize.
sql_queryRun SQL queryA
Run a read-only SQL query against the SiYuan index to answer questions the other tools cannot, e.g. counting blocks or filtering by tag/attribute. Main table: blocks (id, parent_id, root_id, box, path, hpath, type, subtype, content, tag, ial, created, updated). Only SELECT/WITH/EXPLAIN are allowed; results are capped at 64 rows by the kernel.
Inputs: stmt (required).
update_blockUpdate blockA
Replace the content of an existing block with new Markdown. The block type may change (e.g. a paragraph into a heading) unless lock_type is true. Get the ID from get_block or search_notes first.
Inputs: id (required), data (required), lock_type.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 13 tools
Most tools target distinct resource+action pairs and descriptions explicitly distinguish reading vs editing. However, delete_block (which can delete a whole document) overlaps with remove_document, and get_document vs get_block require reading descriptions to separate. These are minor and well-clarified.
Nearly every tool follows a clean verb_noun pattern (list_notebooks, get_document, insert_block, update_block, delete_block, create_document, rename_document, remove_document, move_document). The only outlier is sql_query, which is a conventional, idiomatic exception.
13 tools is well within the ideal range and each earns its place across document, block, search, and query operations. No redundant or filler tools.
Document lifecycle (create/read/rename/move/remove) and block CRUD (get/insert/update/delete) are fully covered, plus search and SQL escape hatch. The main gap is notebook-level management — notebooks can only be listed, not created/renamed/deleted.
Related MCP Connectors
Search your AI chat history (ChatGPT, Claude, Codex) from any MCP client. Remote, private, read-only
Connect AI to your flomo notes. Search, create, edit notes and manage tags via MCP.
Linked markdown notes as memory for AI apps: search, read, save and link notes over MCP.
Read and write your Fresh Jots notes from Claude, Cursor, and any MCP client.
Related MCP Servers
- AlicenseNot gradedqualityNot gradedmaintenanceAn MCP server for SiYuan Note that enables comprehensive management of notebooks, documents, and blocks through AI integration. It supports advanced operations like SQL querying, OCR, multi-format exports, and automated content searching for intelligent knowledge management.16 npm5-
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that enables AI assistants like Claude and Cursor to interact seamlessly with SiYuan Note through 15 specialized tools. It supports comprehensive note operations including unified search, document management, daily notes, and tag manipulation.Apache 2.0
- AlicenseNot gradedqualityDmaintenanceMCP server for SiYuan Note, enabling AI integration and smart knowledge management with note, block, search, template, export, asset, SQL, and file operations.MIT
- AlicenseNot gradedqualityDmaintenanceProvides a local MCP stdio server that enables AI clients to read, search, create, update, and delete notes in SiYuan through its Kernel HTTP API, with configurable notebook and tool permissions.1MIT