loading…
Search for a command to run...
loading…
A Model Context Protocol server that enables AI assistants like Claude and Cursor to interact seamlessly with SiYuan Note through 15 specialized tools. It suppo
A 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.
中文文档 | 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.
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:
Use with caution and at your own risk.
中文:
本项目代码主要由 AI 辅助开发,仅进行了功能性测试,未对所有代码进行完整审查。使用本项目前,请充分了解并接受以下内容:
请谨慎使用,并对自己的选择负责。
Fork notice: The block-level tools, SQL query tool, and additional document management tools (get_block, update_block, append_block, insert_block, move_block, get_block_attrs, set_block_attrs, execute_sql, rename_document, remove_document, get_hpath_by_id, get_child_blocks, get_section_content, get_document_for_block, find_block_in_document) were added with AI assistance and have not been fully tested. Use at your own risk.
# Clone the repository
git clone https://github.com/porkll/siyuan-mcp.git
cd siyuan-mcp
# Install dependencies
npm install
# Build the project
npm run build
# Install globally
npm install -g .
# Install globally
npm install -g @porkll/siyuan-mcp
# Or use npx (no installation needed)
npx @porkll/siyuan-mcp
After global installation, the siyuan-mcp command will be available globally.
Get your SiYuan API Token:
Ensure SiYuan is running:
http://127.0.0.1:6806baseUrl accordinglyEdit your MCP configuration file at ~/.cursor/mcp.json:
{
"mcpServers": {
"siyuan-mcp": {
"command": "npx",
"args": [
"-y",
"@porkll/siyuan-mcp",
"stdio",
"--token",
"YOUR_API_TOKEN_HERE",
"--baseUrl",
"http://127.0.0.1:6806"
]
}
}
}
Note: If you installed globally, you can use "command": "siyuan-mcp" instead of "command": "npx".
Edit the configuration file at:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json{
"mcpServers": {
"siyuan-mcp": {
"command": "npx",
"args": [
"-y",
"@porkll/siyuan-mcp",
"stdio",
"--token",
"YOUR_API_TOKEN_HERE",
"--baseUrl",
"http://127.0.0.1:6806"
]
}
}
}
Note: If you installed globally, you can use "command": "siyuan-mcp" instead of "command": "npx".
After configuration, restart your MCP client (Cursor/Claude Desktop) and try:
Once configured, you can interact with SiYuan through natural language. The server provides 32 tools:
types: ["d"] for document-only results)custom-status, custom-priority)prefix parameter)depth parameter, starts from 1, tags separated by /)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?"
"Move document X to the root of my Work notebook"
"Move documents X and Y under document Z"
"Set my daily note format to use year/month folders"
Move one or more documents to a new location.
Parameters:
from_ids (string[]) - Required. Array of document IDs to move["20210101000000-abc1234"]["20210101000000-abc1234", "20210102000000-def5678"]to_parent_id (string) - OPTION 1: Target parent document ID. Documents will be moved under this document as children. Cannot be used together with to_notebook_root.to_notebook_root (string) - OPTION 2: Target notebook ID. Documents will be moved to the root (top level) of this notebook. Cannot be used together with to_parent_id.Important: You must provide EXACTLY ONE destination: either to_parent_id OR to_notebook_root.
Examples:
// Move single document to notebook root
{
from_ids: ["20210101000000-abc1234"],
to_notebook_root: "20210101000000-notebook1"
}
// Move multiple documents under another document
{
from_ids: ["20210101000000-abc1234", "20210102000000-def5678"],
to_parent_id: "20210103000000-parent99"
}
Batch replace all occurrences of a tag across all documents.
Parameters:
old_tag (string) - Required. Tag name to replace (without # symbol)new_tag (string) - Required. New tag name (without # symbol, use empty string to remove)Examples:
// Replace tag
{
old_tag: "project",
new_tag: "work-project"
}
// Remove tag
{
old_tag: "deprecated",
new_tag: ""
}
Configure the folder structure and file naming format for daily notes in a notebook. The setting is saved in SiYuan's notebook configuration and persists across all clients.
Default format produces a structure like:
Daily Notes/
├── 2024/
│ ├── 01 - January/
│ │ └── 2024-01-15
│ └── 03 - March/
│ └── 2024-03-21
└── 2025/
└── 07 - July/
└── 2025-07-04
Parameters:
notebook_id (string) - Required. The notebook ID to configurepath_template (string) - Required. Path template using Go time format via SprigTemplate tokens:
| Token | Output | Example |
|---|---|---|
{{now | date "2006"}} |
4-digit year | 2024 |
{{now | date "01"}} |
2-digit month | 03 |
{{now | date "January"}} |
Full month name | March |
{{now | date "Jan"}} |
Abbreviated month | Mar |
{{now | date "02"}} |
2-digit day | 21 |
{{now | date "2006-01-02"}} |
Full date | 2024-03-21 |
Examples:
// Default: year/month-name/date (Daily Notes/2024/03 - March/2024-03-21)
{
notebook_id: "20210101000000-abc1234",
path_template: '/Daily Notes/{{now | date "2006"}}/{{now | date "01"}} - {{now | date "January"}}/{{now | date "2006-01-02"}}'
}
// Flat: all notes in one folder (Journals/2024-03-21)
{
notebook_id: "20210101000000-abc1234",
path_template: '/Journals/{{now | date "2006-01-02"}}'
}
// Year only: grouped by year (Daily Notes/2024/2024-03-21)
{
notebook_id: "20210101000000-abc1234",
path_template: '/Daily Notes/{{now | date "2006"}}/{{now | date "2006-01-02"}}'
}
While primarily designed as an MCP server, you can also use this package as a TypeScript library in your own projects:
import { createSiyuanTools } from '@porkll/siyuan-mcp';
// 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);
Full TypeScript types are included:
import type {
SiyuanConfig,
SiyuanApiResponse,
Block,
Notebook,
NotebookConf,
DocTreeNode,
SearchOptions
} from '@porkll/siyuan-mcp';
# Clone and install
git clone https://github.com/porkll/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
# 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
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
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}`));
Yes! Just update the baseUrl parameter:
"--baseUrl", "http://127.0.0.1:YOUR_PORT"
Yes! Point baseUrl to your remote instance:
"--baseUrl", "http://your-server.com:6806"
Contributions are welcome! Please feel free to submit issues and pull requests.
Apache-2.0
This project is primarily developed with AI assistance and built on top of the excellent SiYuan Note project.
Добавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"siyuan-mcp-server": {
"command": "npx",
"args": []
}
}
}