Provides comprehensive tools for interacting with SiYuan Note API, enabling document creation, content search, file operations, daily note management, and notebook operations through a complete TypeScript interface.
SiYuan Tools
思源笔记工具库 - 基于 TypeScript 的思源笔记 API 操作库
A TypeScript library for SiYuan Note API operations, designed to be compatible with MCP (Model Context Protocol) servers like Gemini CLI and Claude Code.
⚠️ Important Notice | 重要声明
English:
The code in this project is primarily developed with AI assistance. While functional testing has been performed, comprehensive code review has not been completed. Before using this project, please be aware of and accept the following:
The code may contain undiscovered issues or potential risks
Conduct necessary code reviews and testing before use
Users assume all risks and responsibilities arising from the use of this project
Thorough validation is recommended before production use
Use with caution and at your own risk.
中文:
本项目代码主要由 AI 辅助开发,仅进行了功能性测试,未对所有代码进行完整审查。使用本项目前,请充分了解并接受以下内容:
代码可能存在未发现的问题或潜在风险
请在使用前进行必要的代码审查和测试
使用者需自行承担使用本项目所产生的风险和责任
建议在生产环境使用前进行充分的验证
请谨慎使用,并对自己的选择负责。
特性 Features
完整的 TypeScript 类型定义
模块化设计,易于扩展
符合 Gemini CLI 和 Claude Code 的技术栈标准
支持所有常用的思源笔记 API 操作
安装 Installation
快速开始 Quick Start
核心功能 Core Features
1. 搜索 Search
根据文件名搜索
根据内容搜索
高级搜索
2. 文件操作 File Operations
查看文件内容
覆盖文件内容
追加到文件
创建新文件
3. 今日笔记 Daily Note
追加到今日笔记
获取或创建今日笔记
在今日笔记开头插入
4. 笔记本操作 Notebook Operations
列出所有笔记本
创建笔记本
获取笔记本配置
高级用法 Advanced Usage
直接使用 API 模块
辅助工具方法
提供额外的便捷功能,按需使用:
使用 SQL 查询
自定义配置
API 文档 API Documentation
SiyuanTools
主工具类,��供所有功能的统一入口。
属性 Properties
search: SiyuanSearchApi
- 搜索相关操作block: SiyuanBlockApi
- 块操作document: SiyuanDocumentApi
- 文档操作notebook: SiyuanNotebookApi
- 笔记本操作dailyNote: DailyNoteUtils
- 今日笔记工具
便捷方法 Convenience Methods
searchByFileName(fileName, limit?)
- 根据文件名搜索searchByContent(content, limit?)
- 根据内容搜索getFileContent(blockId)
- 获取文件内容overwriteFile(blockId, content)
- 覆盖文件内容appendToFile(blockId, content)
- 追加到文件createFile(notebookId, path, content)
- 创建新文件appendToDailyNote(notebookId, content)
- 追加到今日笔记listNotebooks()
- 列出所有笔记本
模块 API
详细的 API 文档请参考各个模块:
SiyuanSearchApi - 搜索操作
SiyuanBlockApi - 块操作
SiyuanDocumentApi - 文档操作
SiyuanNotebookApi - 笔记本操作
DailyNoteUtils - 今日笔记工具
类型定义 Type Definitions
所有类型定义都可以从主模块导入:
开发 Development
技术栈 Tech Stack
Language: TypeScript 5.3+
Runtime: Node.js 18+
Module System: ES Modules
Package Manager: npm
MCP 服务器 MCP Server
本项目提供了完整的 MCP (Model Context Protocol) 服务器实现,可以与 Claude Code、Claude Desktop、Gemini CLI 等工具集成。
快速配置到 Claude Code
一键添加到 Claude Code:
获取 API Token: 在思源笔记中:设置 → 关于 → API Token
使用示例: 配置完成后,在 Claude Code 中可以直接使用:
"列出我的所有思源笔记本"
"搜索包含'项目计划'的文档"
"在工作笔记本创建一个会议记录"
"显示最近修改的5个文档"
可用的 MCP 工具(12个)
search_by_filename - 按文件名搜索文档
search_by_content - 按内容搜索块
sql_query - 执行自定义 SQL 查询
get_file_content - 获取文档内容
create_file - 创建新文档
append_to_file - 追加内容到文档
update_file - 更新(覆盖)文档内容
append_to_daily_note - 追加到今日笔记
list_notebooks - 列出所有笔记本
get_notebook_config - 获取笔记本配置
get_recent_documents - 获取最近修改的文档
get_document_outline - 获取文档大纲
两种服务器模式
Stdio 模式(推荐用于 Claude Code/Desktop)
HTTP/SSE 模式(用于 Web 应用)
其他工具集成
Claude Desktop 配置:
编辑 ~/Library/Application Support/Claude/claude_desktop_config.json
:
详细文档:
MCP 使用指南 - 完整的使用说明
Claude Code 配置 - 详细配置指南
架构说明 - 服务器架构文档
兼容性 Compatibility
本项目采用与 Gemini CLI 和 Claude Code 相同的技术栈:
TypeScript + ES Modules
Node.js 18+
符合 MCP (Model Context Protocol) 标准
许可证 License
Apache-2.0
贡献 Contributing
欢迎提交 Issue 和 Pull Request!
相关项目 Related Projects
思源笔记 - 官方项目
Gemini CLI - Google 的 AI 终端工具
Claude Code - Anthropic 的 AI 编程助手
常见问题 FAQ
如何获取 API Token?
在思源笔记中:设置 -> 关于 -> API Token
如何找到笔记本 ID?
如何处理错误?
所有 API 方法在失败时会抛出错误,建议使用 try-catch:
示例 Examples
更多示例请查看 examples 目录。
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
Enables interaction with SiYuan Note through its API for comprehensive note management. Supports searching, creating, editing documents, managing notebooks, and daily notes operations through natural language commands.