SiYuan MCP Server
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.
README
SiYuan MCP Server
中文文档 | English
A Model Context Protocol (MCP) server for SiYuan Note, enabling AI assistants like Claude, Cursor, and other MCP-compatible tools to interact with your SiYuan notes seamlessly.
⚠️ 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
- 🚀 Full MCP (Model Context Protocol) implementation
- 📝 20+ tools for comprehensive SiYuan Note operations
- 🔍 Advanced search (by filename, content, and SQL)
- 📁 Document management (create, read, update)
- 📅 Daily note support with auto-creation
- 📚 Notebook operations
- 📸 Snapshot management (backup & restore)
- 🔒 Document moving and tree operations
- 💻 Written in TypeScript with full type definitions
- 🌐 Works with Claude Desktop, Cursor, and any MCP-compatible client
📦 Installation
Option 1: Install from Source (Recommended)
# Clone the repository
git clone https://github.com/yourusername/siyuan-mcp.git
cd siyuan-mcp
# Install dependencies
npm install
# Build the project
npm run build
# Install globally
npm install -g .
Option 2: Install from npm (When Published)
npm install -g siyuan-mcp-server
After installation, the siyuan-mcp command will be available globally.
🔧 Configuration
Prerequisites
-
Get your SiYuan API Token:
- Open SiYuan Note
- Go to Settings → About → API Token
- Copy the token
-
Ensure SiYuan is running:
- Default URL:
http://127.0.0.1:6806 - If using a different port, adjust the
baseUrlaccordingly
- Default URL:
Configure for Cursor
Edit your MCP configuration file at ~/.cursor/mcp.json:
{
"mcpServers": {
"siyuan-mcp": {
"command": "siyuan-mcp",
"args": [
"stdio",
"--token",
"YOUR_API_TOKEN_HERE",
"--baseUrl",
"http://127.0.0.1:6806"
]
}
}
}
Configure for Claude Desktop
Edit the configuration file at:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"siyuan-mcp": {
"command": "siyuan-mcp",
"args": [
"stdio",
"--token",
"YOUR_API_TOKEN_HERE",
"--baseUrl",
"http://127.0.0.1:6806"
]
}
}
}
Verify Installation
After configuration, restart your MCP client (Cursor/Claude Desktop) and try:
- "List all my SiYuan notebooks"
- "Search for documents containing 'project plan'"
- "Create a new meeting note in my work notebook"
- "Show me the 5 most recently modified documents"
🛠️ Available MCP Tools
Once configured, you can interact with SiYuan through natural language. The server provides 20+ tools:
📝 Search & Query
- search_by_filename - Search documents by filename
- search_by_content - Search blocks/documents by content
- sql_query - Execute custom SQL queries on SiYuan database (advanced)
📄 Document Operations
- get_document_content - Get the markdown content of a document
- create_document - Create a new document
- append_to_document - Append content to an existing document
- update_document - Update (overwrite) document content
- move_document - Move document(s) to a new location
- get_document_tree - Get document tree structure with specified depth
📅 Daily Note
- append_to_daily_note - Append to today's daily note (auto-creates if needed)
📚 Notebook Management
- list_notebooks - List all notebooks
- get_recently_updated_documents - Get recently updated documents
📸 Snapshot Management
- create_snapshot - Create a data snapshot for backup
- list_snapshots - List available snapshots
- rollback_snapshot - Rollback to a specific snapshot
Usage Examples
Ask your AI assistant naturally:
"List all my SiYuan notebooks"
"Search for documents about machine learning"
"Create a new document called 'Project Ideas' in my Work notebook"
"Show me the 10 most recently modified documents"
"Append 'Meeting notes: discussed Q4 goals' to today's daily note"
"Create a snapshot before I make major changes"
"What's the tree structure of my 'Projects' notebook?"
🔧 Advanced: Using as TypeScript Library
While primarily designed as an MCP server, you can also use this package as a TypeScript library in your own projects:
import { createSiyuanTools } from 'siyuan-mcp-server';
// Create an instance
const siyuan = createSiyuanTools('http://127.0.0.1:6806', 'your-token');
// Search operations
const files = await siyuan.searchByFileName('keyword', 10);
const blocks = await siyuan.searchByContent('content', 20);
// Document operations
const content = await siyuan.getFileContent(documentId);
await siyuan.createFile('notebookId', '/path/to/doc', '# Title\n\nContent');
await siyuan.appendToFile(documentId, 'New content');
await siyuan.overwriteFile(documentId, 'Replaced content');
// Daily note
await siyuan.appendToDailyNote('notebookId', 'Today I learned...');
// Notebook operations
const notebooks = await siyuan.listNotebooks();
// SQL queries
const results = await siyuan.search.query(`
SELECT * FROM blocks
WHERE type='d' AND content LIKE '%keyword%'
ORDER BY updated DESC
LIMIT 10
`);
// Direct API access
await siyuan.block.insertBlockAfter(blockId, 'New block content');
await siyuan.document.moveDocument(['doc1', 'doc2'], 'targetNotebookId');
const tree = await siyuan.document.getDocTree('notebookId', 2);
Type Definitions
Full TypeScript types are included:
import type {
SiyuanConfig,
SiyuanApiResponse,
Block,
Notebook,
NotebookConf,
DocTreeNode,
SearchOptions
} from 'siyuan-mcp-server';
💻 Development
Setup
# Clone and install
git clone https://github.com/yourusername/siyuan-mcp.git
cd siyuan-mcp
npm install
# Build
npm run build
# Watch mode (auto-rebuild)
npm run watch
# Lint
npm run lint
# Format
npm run format
Manual Testing
# Start stdio server manually
npm run mcp:stdio -- --token YOUR_TOKEN --baseUrl http://127.0.0.1:6806
# Start HTTP server (for web clients)
npm run mcp:http -- --token YOUR_TOKEN --port 3000 --baseUrl http://127.0.0.1:6806
🏗️ Architecture
siyuan-mcp/
├── src/ # Core TypeScript library
│ ├── api/ # SiYuan API clients
│ ├── types/ # Type definitions
│ └── utils/ # Helper utilities
├── mcp-server/ # MCP server implementation
│ ├── bin/ # CLI entry points
│ ├── core/ # MCP server core
│ ├── handlers/ # Tool handlers
│ └── transports/ # Stdio/HTTP transports
└── dist/ # Compiled JavaScript
🔧 Tech Stack
- Language: TypeScript 5.3+
- Runtime: Node.js 18+
- Module System: ES Modules
- MCP SDK: @modelcontextprotocol/sdk
- Protocol: MCP (Model Context Protocol)
❓ FAQ
How do I get my SiYuan API Token?
- Open SiYuan Note
- Go to Settings → About → API Token
- Copy the token
How do I find my notebook ID?
Ask your MCP client: "List all my SiYuan notebooks" and it will show IDs.
Or programmatically:
const notebooks = await siyuan.listNotebooks();
console.log(notebooks.map(nb => `${nb.name}: ${nb.id}`));
The server isn't working, what should I check?
- Is SiYuan running? (default: http://127.0.0.1:6806)
- Is your API token correct?
- Did you restart your MCP client after configuration?
- Check the logs in your MCP client
Can I use a different SiYuan port?
Yes! Just update the baseUrl parameter:
"--baseUrl", "http://127.0.0.1:YOUR_PORT"
Does this work with remote SiYuan instances?
Yes! Point baseUrl to your remote instance:
"--baseUrl", "http://your-server.com:6806"
🤝 Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
📄 License
Apache-2.0
🔗 Related Projects
- SiYuan Note - Official SiYuan Note repository
- Model Context Protocol - MCP documentation
- MCP TypeScript SDK - Official MCP SDK
🙏 Acknowledgments
This project is primarily developed with AI assistance and built on top of the excellent SiYuan Note project.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。