siyuan-mcp-server
v0.31.0思源笔记 MCP Server - 提供思源笔记API的MCP工具接口
These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.
find_notebooks
查找并列出思源笔记中的笔记本。 适用场景: - 快速获取所有笔记本 ID 以便后续写入/查询工具使用。 - 通过名称关键字做轻量筛选。 使用方法: - name: 可选,大小写不敏感的包含匹配。 - limit: 返回数量上限,默认 10。 注意事项: - 返回结果为笔记本原始信息(含 id/name/icon/closed 等字段)。 - 若需要精确匹配名称,请在调用方自行做二次过滤。 Args: name (Optional[str]): 用于模糊搜索笔记本的名称。如…
| Parameter | Type | Description |
|---|---|---|
limit | integer | |
name |
find_documents
在指定的笔记本中查找文档,支持多种过滤条件。 适用场景: - 按笔记本、标题、创建/更新时间筛选文档块(type='d')。 使用方法: - notebook_id: 指定笔记本范围。 - title: 对文档名称字段做 LIKE 模糊匹配。 - created_after / updated_after: 传入 YYYYMMDDHHMMSS。 注意事项: - 本工具按 blocks.name 过滤标题,不按 hpath 过滤。 - 若需要更复杂条件(例如按 hpath 前缀),请使用 execute_sql。 Args: notebook_id (Optional[str]): 圅
| Parameter | Type | Description |
|---|---|---|
created_after | ||
limit | integer | |
notebook_id | ||
title | ||
updated_after |
search_blocks
根据关键词、类型等多种条件在思源笔记中搜索内容块。 这是最核心和最灵活的查询工具。 适用场景: - 全局关键词检索。 - 按块类型和时间窗口缩小范围。 使用方法: - query: 使用 SQL LIKE 语义匹配 content。 - parent_id: 按直接父块 ID 过滤。 - block_type: 例如 p/h/l。 注意事项: - parent_id 仅匹配直接子块,不会递归后代。 - 返回 content 会做敏感信息打码处理。 Args: query (str): 在块内容中搜索的å……
| Parameter | Type | Description |
|---|---|---|
query * | string | |
block_type | ||
created_after | ||
limit | integer | |
parent_id | ||
updated_after |
get_block_content
获取指定块的完整 Markdown 内容。 适用场景: - 读取单个块的 kramdown 原文并用于审阅或后续处理。 注意事项: - 返回的 kramdown 会进行敏感信息打码。 - 思源属性标记中的块 ID / 时间戳会被保留,便于定位。 Args: block_id (str): 块的 ID Returns: Dict[str, Any]: 包含块内容的字典
| Parameter | Type | Description |
|---|---|---|
block_id * | string |
get_blocks_content
批量获取多个块的完整内容。 适用场景: - 一次性拉取多个块内容,减少多次调用开销。 注意事项: - 单个块失败不会中断整体,失败项会返回 error 字段。 - 返回的 kramdown 与 get_block_content 一样会做敏感信息打码。 Args: block_ids (List[str]): 块 ID 列表 Returns: List[Dict[str, Any]]: 包含每个块内容的字典列表
| Parameter | Type | Description |
|---|---|---|
block_ids * | array |
execute_sql
直接对数据库执行只读的 SELECT 查询。 适用场景: - 需要跨字段、跨表的高级筛选能力。 - 内置查询工具无法覆盖的复杂检索。 使用方法: - 仅支持 SELECT 语句。 - 建议显式 LIMIT,避免一次返回过多数据。 注意事项: - 返回的字符串字段会进行敏感信息打码。 - 如需精确审计原始敏感字段值,不适合使用该工具。 Args: query (str): SQL SELECT 查询语句 Returns: List[Dict[str, Any]]: 查询结果列表 Rai…
| Parameter | Type | Description |
|---|---|---|
query * | string |
push_message
推送前台消息。 适用场景: - 在写入流程中向前台反馈进度或结果。 注意事项: - msg 必须是非空字符串。 - timeout 必须是正整数毫秒值。 Args: msg: 消息内容。 timeout: 消息显示时长(毫秒),默认 7000。 Returns: Dict[str, Any]: 包含消息 id 的字典。
| Parameter | Type | Description |
|---|---|---|
msg * | string | |
timeout | integer |
push_error_message
推送前台错误消息。 适用场景: - 在参数校验或接口调用失败时向前台反馈错误。 注意事项: - msg 必须是非空字符串。 - timeout 必须是正整数毫秒值。 Args: msg: 错误消息内容。 timeout: 消息显示时长(毫秒),默认 7000。 Returns: Dict[str, Any]: 包含消息 id 的字典。
| Parameter | Type | Description |
|---|---|---|
msg * | string | |
timeout | integer |
create_document
通过 Markdown 创建文档。 适用场景: - 根据固定路径批量创建结构化文档。 - 快速写入一篇完整 Markdown 文档。 使用方法: - notebook_id: 目标笔记本 ID。 - path: 以 / 开头的人类可读路径。 - markdown: 文档 Markdown 正文。 注意事项: - path 必须以 / 开头。 - 思源 API 对相同 path 重复创建不会覆盖已有文档。
| Parameter | Type | Description |
|---|---|---|
markdown * | string | |
notebook_id * | string | |
path * | string |
update_block
更新块内容。 适用场景: - 已知块 ID 时,直接替换该块内容。 使用方法: - block_id: 目标块 ID。 - data_type: 仅支持 markdown 或 dom。 - data: 新内容。 注意事项: - 这是整块替换,不是局部 patch。 - 修改前请确保 block_id 指向正确块,避免误改。
| Parameter | Type | Description |
|---|---|---|
block_id * | string | |
data * | string | |
data_type | string |
delete_block
删除指定块。 适用场景: - 清理错误插入或不再需要的块。 注意事项: - 删除操作具破坏性,调用前建议先用查询工具确认 block_id。 - 返回值包含操作记录,可用于审计本次删除结果。
| Parameter | Type | Description |
|---|---|---|
block_id * | string |
insert_block
插入块(next_id / previous_id / parent_id 至少提供一个)。 适用场景: - 需要按相邻块位置插入(前置/后置锚点)。 - 需要按父块插入(指定 parent_id)。 使用方法: - next_id: 插入到 next_id 对应块之前。 - previous_id: 插入到 previous_id 对应块之后。 - parent_id: 插入为 parent_id 的子块。 - 三者可同时提供,但思源 API 优先级为 next_id > previous_id > parent_id。 注意事项: - 如果你要"确保挂到某个标题(如 H3)下面",请昅
| Parameter | Type | Description |
|---|---|---|
data * | string | |
data_type | string | |
next_id | ||
parent_id | ||
previous_id |
prepend_block
插入前置子块。 适用场景: - 需要稳定地插入到某个父块下(强父子关系)。 - 例如把列表、段落挂到某个 H2/H3 下。 使用方法: - parent_id 传入目标父块 ID。 - data 为待插入内容,data_type 支持 markdown 或 dom。 注意事项: - 该工具是"父块优先"的安全写入方式,不依赖 next_id/previous_id。 - 若需要基于相邻块精确定位,请使用 insert_block。 与 insert_block 的区别: - prepend_block 强制作为父块的第一个子块,层纅
| Parameter | Type | Description |
|---|---|---|
data * | string | |
parent_id * | string | |
data_type | string |
append_block
插入后置子块。 适用场景: - 需要稳定地追加到某个父块末尾(强父子关系)。 - 例如把有序/无序列表追加到某个 H2/H3 下。 使用方法: - parent_id 传入目标父块 ID。 - data 为待插入内容,data_type 支持 markdown 或 dom。 注意事项: - 该工具不会使用 next_id/previous_id 锚点,适合避免层级歧义。 - 若需要插入到父块子节点中间位置,请使用 insert_block 并结合锚点。 与 insert_block 的区别: - append_block 强制作为爅
| Parameter | Type | Description |
|---|---|---|
data * | string | |
parent_id * | string | |
data_type | string |
move_block
移动块(previous_id / parent_id 至少提供一个)。 适用场景: - 调整块顺序(基于 previous_id 锚点)。 - 调整父子归属(基于 parent_id)。 - 调整分节或层级结构时,保持相关内容整体移动。 使用方法: - previous_id: 把 block_id 移动到 previous_id 之后。 - parent_id: 把 block_id 移动到 parent_id 之下。 - allow_heading_only_move: 兼容旧参数,已废弃;传 true 会报错。 注意事项: - 若 block_id 是标题块(h1-h6),将按“分节范围 
| Parameter | Type | Description |
|---|---|---|
block_id * | string | |
allow_heading_only_move | boolean | |
parent_id | ||
previous_id |
list_files
列出指定路径下的文件和文件夹(只读)。 常用于探索 '/data' 目录结构,例如查看 '/data/history' 下的快照。 注意事项: - 该工具仅读取目录,不会修改任何文件。 - 返回结果依赖思源工作空间内的实际路径权限。 Args: path: 路径,例如 '/data' 或 '/data/history'。 Returns: list: 包含文件和文件夹信息的字典列表。
| Parameter | Type | Description |
|---|---|---|
path * | string |
get_file
读取指定文件的内容(只读)。 用于读取历史快照或其他数据文件。 注意事项: - 文本内容会进行敏感信息打码。 - 若文件为二进制且无法解码为 UTF-8,将返回 '[Binary Data]'。 Args: path: 文件路径,例如 '/data/history/2023/01/...'。 Returns: str: 文件内容(文本)或二进制数据提示。
| Parameter | Type | Description |
|---|---|---|
path * | string |
get_file_base64
读取指定文件内容并以 Base64 返回(只读)。 适用于需要以 Base64 形式返回的 UTF-8 文本文件(例如历史快照里的 JSON)。 注意事项: - 本实现会先按 UTF-8 解码后再打码并进行 Base64 编码。 - 若文件为纯二进制且无法 UTF-8 解码,将抛出异常(不支持二进制打码)。 Args: path: 文件路径,例如 '/history/.../blocks.msgpack'。 Returns: str: Base64 编码的文件内容(已打码)。
| Parameter | Type | Description |
|---|---|---|
path * | string |
list_history_entries
列出历史快照目录下的文件和文件夹。 注意事项: - path 必须以 '/history' 或 '/data/history' 开头。 - 该工具用于枚举历史目录,不直接返回快照内容。 Args: path: 历史目录路径,默认为 "/history"。 Returns: list: 历史目录下的条目列表。
| Parameter | Type | Description |
|---|---|---|
path | string |
get_history_file
读取历史快照文件内容(只读)。 注意事项: - path 必须以 '/history' 或 '/data/history' 开头。 - 行为与 get_file 一致,文本会做敏感信息打码。 Args: path: 历史快照文件路径,必须以 "/history" 或 "/data/history" 开头。 Returns: str: 历史快照文件内容。
| Parameter | Type | Description |
|---|---|---|
path * | string |
get_block_changes
查询指定时间范围内新增或修改的内容块。 适用场景: - 只需要变更清单/索引, 不关心逐块前后差异。 - 需要快速筛选近期新增或更新的块。 与 get_block_diffs 的区别: - 本函数不做历史快照对比, 不返回 before/after。 - 返回的是当前块的字段快照(例如 content/markdown)。 注意事项: - deleted 当前恒为空;删除块需要结合历史快照比对才能识别。 - include_markdown=true 会显著增大返回体量,建议配合 limit 使用。 Args: start_time: 起…
| Parameter | Type | Description |
|---|---|---|
start_time * | string | |
end_time | ||
include_markdown | boolean | |
limit | integer |
get_block_diffs
查询指定时间范围内修改的内容块并返回前后对比。 适用场景: - 需要审计每个块的具体改动(含 before/after)。 - 需要变更类型(新增/删减/替换)和差异统计。 与 get_block_changes 的区别: - 本函数会读取历史快照并与当前内容对比。 - 返回 before/after 文本和 diff 统计, 但更重且依赖 /history。 注意事项: - 依赖 history_root 可读;若历史目录不可访问,将无法完成比对。 - before/after 为脱敏文本;max_text_length 会对长文本截断。 Args:…
| Parameter | Type | Description |
|---|---|---|
start_time * | string | |
end_time | ||
history_root | string | |
limit | integer | |
max_text_length | integer |