思源笔记 MCP Server - 提供思源笔记API的MCP工具接口
Project description
思源笔记 MCP 服务器 (官方 SDK 版)
本项目提供了一个基于官方 MCP Python SDK 构建的思源笔记 MCP (Model Context Protocol) 服务器。它允许 AI Agent 通过一套标准化的工具与您的思源笔记知识库进行交互。
该服务器充当一座桥梁,将 MCP 的工具调用转换为对思源笔记 API 的请求,专注于提供强大的只读查询能力。
功能特性
- 基于官方 SDK 构建: 确保了兼容性并遵循最佳实践。
FastMCP集成: 使用高级的FastMCP服务器,兼具简洁与强大。- 生命周期管理: 通过
lifespan机制安全地管理SiyuanAPI客户端的生命周期。 - 装饰器驱动的工具: 使用
@mcp.tool()装饰器,工具定义清晰简洁。 - 兼具高层与底层工具: 同时提供易于使用的高级查询工具和功能强大的底层
execute_sql工具,以实现最大灵活性。 - 敏感数据自动打码: 自动检测并打码返回内容中的敏感信息(如 API 密钥、令牌、密码等),保护用户隐私和数据安全。
环境要求
- Python 3.10+(仅开发时需要,使用 uvx 运行时无需)
- uv(推荐使用,用于
uvx命令) - 思源笔记桌面客户端正在运行
- 思源笔记 API Token(在思源笔记设置中获取)
安装 uv
如果尚未安装 uv:
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
# 或使用包管理器
pip install uv
安装与配置
-
克隆仓库:
git clone <repository-url> cd siyuan-mcp-server
-
安装依赖: 我们推荐使用
uv。uv sync
如何运行
方式一:使用 uvx(推荐,无需安装)
这是最简单的方式,无需预先安装,uvx 会自动从 PyPI 下载并运行。
Claude Desktop 配置:
{
"mcpServers": {
"siyuan": {
"command": "uvx",
"args": ["siyuan-mcp-server"],
"env": {
"SIYUAN_API_TOKEN": "your_token_here"
}
}
}
}
指定版本:
{
"mcpServers": {
"siyuan": {
"command": "uvx",
"args": ["siyuan-mcp-server==0.17.0"],
"env": {
"SIYUAN_API_TOKEN": "your_token_here"
}
}
}
}
uvx 的优势:
- ✅ 无需预先安装包
- ✅ 自动版本管理
- ✅ 隔离的临时环境
- ✅ 自动依赖管理
- ✅ 快速启动(利用 uv 的缓存)
方式二:本地开发运行
在开发期间,可以使用 uv run 直接运行本地代码:
Claude Desktop 配置:
{
"mcpServers": {
"siyuan": {
"command": "uv",
"args": ["run", "siyuan_mcp_server"],
"cwd": "/path/to/siyuan-mcp-server",
"env": {
"SIYUAN_API_TOKEN": "your_token_here"
}
}
}
}
说明:
cwd指向项目根目录uv run会使用项目的虚拟环境- 代码修改后无需重新构建
已实现的工具
所有工具均在 siyuan_mcp_server.py 文件中定义。
find_notebooks: 查找并列出笔记本。find_documents: 根据笔记本、标题和日期等条件查找文档。search_blocks: 根据关键词、父块、块类型和日期等条件搜索内容块。get_block_content: 获取指定块的完整 Markdown 内容。get_blocks_content: 批量获取多个块的完整内容,比多次调用get_block_content更高效。execute_sql: 直接对数据库执行只读的SELECT查询。
未来计划
- 添加更多高级查询工具
- 支持写入操作(创建/更新文档)
- 添加单元测试
安全特性
本项目内置了敏感数据保护机制,通过 tools.py 中的 mask_sensitive_data 函数实现:
-
自动检测敏感信息: 能够识别多种格式的敏感数据,包括:
- AWS Access Key ID 和 Secret Access Key
- GitHub Personal Access Token
- JWT Token
- UUID
- API Key
- OAuth tokens
- Private Key
- 数据库连接字符串中的密码
- Base64 编码的密钥
- 十六进制密钥
- 其他通用密钥格式
-
智能打码策略: 采用中间部分打码的方式,保留字符串的开头和结尾部分,便于识别但不泄露完整信息。
-
全面保护: 在所有返回用户数据的内容中自动应用打码处理,包括:
- 块内容搜索结果
- 块详细内容
- SQL 查询结果
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file siyuan_mcp_server-0.17.0.tar.gz.
File metadata
- Download URL: siyuan_mcp_server-0.17.0.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec1a5dae1e59b79a580de2e3382e59ba74e8a02995c5000d0a14cbed1d4e1e2b
|
|
| MD5 |
d234e61a76bbf6db4accb7105d26d0a9
|
|
| BLAKE2b-256 |
d8144a9c52e2e17f34fbdef642bd21c3d08c3340ebf4ef808113c5a1d10ca65f
|
Provenance
The following attestation bundles were made for siyuan_mcp_server-0.17.0.tar.gz:
Publisher:
publish.yml on leolulu/siyuan-mcp-server
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
siyuan_mcp_server-0.17.0.tar.gz -
Subject digest:
ec1a5dae1e59b79a580de2e3382e59ba74e8a02995c5000d0a14cbed1d4e1e2b - Sigstore transparency entry: 849975432
- Sigstore integration time:
-
Permalink:
leolulu/siyuan-mcp-server@e285f42420b6f5645226355ca6b4f350ca29b944 -
Branch / Tag:
refs/tags/v0.17.0 - Owner: https://github.com/leolulu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e285f42420b6f5645226355ca6b4f350ca29b944 -
Trigger Event:
push
-
Statement type:
File details
Details for the file siyuan_mcp_server-0.17.0-py3-none-any.whl.
File metadata
- Download URL: siyuan_mcp_server-0.17.0-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b4d90ea8e6c961afd8fd5cdd4e37f096975f84a1cafaab196f1695947829d16
|
|
| MD5 |
4fb4a6db2c2216553bd45ec420e4c30a
|
|
| BLAKE2b-256 |
f8ed7510b0d3e38116d35193d1714680524b2ac8d9d53e698969d2704b3f15e8
|
Provenance
The following attestation bundles were made for siyuan_mcp_server-0.17.0-py3-none-any.whl:
Publisher:
publish.yml on leolulu/siyuan-mcp-server
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
siyuan_mcp_server-0.17.0-py3-none-any.whl -
Subject digest:
2b4d90ea8e6c961afd8fd5cdd4e37f096975f84a1cafaab196f1695947829d16 - Sigstore transparency entry: 849975436
- Sigstore integration time:
-
Permalink:
leolulu/siyuan-mcp-server@e285f42420b6f5645226355ca6b4f350ca29b944 -
Branch / Tag:
refs/tags/v0.17.0 - Owner: https://github.com/leolulu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e285f42420b6f5645226355ca6b4f350ca29b944 -
Trigger Event:
push
-
Statement type: