笔记连接服务

SiYuan MCP Server 是一个通过模型上下文协议(MCP)将AI工具与思源笔记连接的服务,支持安全的搜索、阅读、创建和组织笔记。

  • by PurpleLiu
  • TypeScript
  • 本地部署
  • 7 星标
  • 更新于
在 GitHub 查看 PurpleLiu/siyuan-mcp

使用说明

思源MCP服务器

英语 | 繁体中文

由PurpleLiu维护的思源MCP服务器。它将AI工具连接到 思源纸币 通过 模型上下文协议(MCP) 用于安全搜索、阅读、创建和组织笔记。

兼容Claude Desktop、Cursor、OpenClaw和任何兼容MCP的客户端。

特性

  • 66工具 涵盖搜索、文档、块、笔记本、日记、快照和标签
  • 统一搜索 --内容、文件名、标签或组合过滤器
  • 文档树 --按深度浏览笔记本层次结构
  • 每日笔记 --如果不存在,则自动创建今天的笔记
  • 快照管理 --创建/列出/回滚
  • 标准和HTTP 运输
  • TypeScript 完整类型定义

快速开始

安装

git clone https://github.com/PurpleLiu/siyuan-mcp.git
cd siyuan-mcp
npm install && npm run build
npm install -g .

获取您的思源API代币

思源→ 设置→ 关于→ API代币

环境变量(可选)

export SIYUAN_TOKEN=your-token
export SIYUAN_BASE_URL=http://127.0.0.1:6806
export SIYUAN_VERBOSE=1   # optional

配置您的MCP客户端

光标 (~/.cursor/mcp.json):

{
  "mcpServers": {
    "siyuan": {
      "command": "siyuan-mcp",
      "args": ["stdio", "--token", "YOUR_TOKEN", "--baseUrl", "http://127.0.0.1:6806"]
    }
  }
}

克劳德桌面版 (claude_desktop_config.json):

{
  "mcpServers": {
    "siyuan": {
      "command": "siyuan-mcp",
      "args": ["stdio", "--token", "YOUR_TOKEN", "--baseUrl", "http://127.0.0.1:6806"]
    }
  }
}

配置位置:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • 窗户: %APPDATA%\Claude\claude_desktop_config.json

工具

类别 工具 描述
🔍 搜索 unified_search 按内容/文件名/标签或组合过滤器搜索
📄 文件 get_document_content 读取文档内容(分页)
create_document 创建新文档
append_to_document 附加内容
update_document 替换内容
remove_document 删除文档
rename_document 重命名文档
move_documents 移动文档
get_document_tree 按深度获取文档树
get_human_path_by_id 按文档ID显示的人类可读路径
get_human_path_by_path 存储路径中的人类可读路径
get_path_by_id 按文档ID的存储路径
get_ids_by_hpath 按人类可读路径列出的文档ID
📅 每日笔记 append_to_daily_note 附于今天的笔记
📚 笔记本电脑 list_notebooks 列出笔记本
get_recently_updated_documents 最近更新的文件
create_notebook 创建笔记本
open_notebook 打开笔记本
close_notebook 关闭笔记本
rename_notebook 重命名笔记本
remove_notebook 删除笔记本
get_notebook_conf 获取笔记本配置
set_notebook_conf 更新笔记本配置
🧱 积木 delete_block 删除块
move_block 移动一个块
fold_block 折叠一块
unfold_block 展开一个区块
get_child_blocks 获取儿童积木
transfer_block_ref 传输块参考
🧱 积木 delete_block 删除块
move_block 移动一个块
fold_block 折叠一块
unfold_block 展开一个区块
get_child_blocks 获取儿童积木
transfer_block_ref 传输块参考
🧩 属性 get_block_attrs 获取块属性
set_block_attrs 设置块属性
🧮 SQL execute_sql 执行SQL查询
flush_transaction 刷新SQL事务
🧾 模板 render_template 按ID渲染模板
render_sprig 渲染树枝模板
📦 资产 upload_asset_base64 上传资产(base64)
📁 文件 get_file 按路径获取文件
put_file 按路径写入文件
remove_file 按路径删除文件
rename_file 重命名/移动文件
list_files 列出路径下的文件
📤 出口 export_markdown 出口降价
export_files 导出文件/文件夹
🔔 通知 push_message 推送消息
push_error_message 推送错误消息
🖥️ 系统 get_boot_progress 获取启动进度
get_system_version 获取系统版本
get_system_time 获取系统时间
📸 快照 create_snapshot 创建快照
list_snapshots 列出快照
rollback_to_snapshot 回滚快照
🏷️ 标签 list_all_tags 列出所有标签(支持前缀/深度)
batch_replace_tag 批量替换/删除标签

使用示例

"List all notebooks"
"Search notes about kubernetes"
"Show the Work notebook tree with 3 levels"
"Create a meeting note under Projects/2026"
"Append today’s standup notes to my daily note"
"Move these three documents into Archive"
"What tags do I have under 'project/'?"
"Get block attributes for this note"
"Set a custom attribute on a block"
"Run an SQL query to find recently updated notes"
"Render a template with variables"
"Upload an image asset"
"Export this document to markdown"
"List files under /data"
"Push a notification message"
"Check SiYuan system version"

用作图书馆

import { createSiyuanTools } from '@purpleliu/siyuan-mcp';

const siyuan = createSiyuanTools('http://127.0.0.1:6806', 'your-token');

const notebooks = await siyuan.listNotebooks();
const content = await siyuan.getFileContent(documentId);
const results = await siyuan.search.query(
  "SELECT * FROM blocks WHERE content LIKE '%keyword%'"
);

发展

npm install          # Install dependencies
npm run build        # Build
npm run watch        # Watch mode
npm run lint         # Lint
npm run format       # Format

# Manual testing
npm run mcp:stdio -- --token YOUR_TOKEN --baseUrl http://127.0.0.1:6806
npm run mcp:http -- --token YOUR_TOKEN --port 3000 --baseUrl http://127.0.0.1:6806

项目结构

├── src/               # Core library
│   ├── api/           # SiYuan API client
│   ├── types/         # TypeScript types
│   └── utils/         # Helpers
├── mcp-server/        # MCP server
│   ├── bin/           # CLI entry (stdio/http)
│   ├── core/          # Server core & registry
│   └── handlers/      # Tool handlers
└── dist/              # Build output

许可证

阿帕奇-2.0