使用说明
备注MCP服务器
用于与黑曜石笔记交互的MCP(模型上下文协议)服务器。该服务器提供工具,用于搜索和阅读黑曜石金库中的笔记,使您的知识库可供人工智能助手访问。
特性
- 搜索笔记:使用ripgrep在黑曜石保险库中进行全文搜索
- 阅读笔记:从笔记中解析和提取内容、元数据和标签
- 跨平台:适用于Windows、macOS和Linux
- 前线支援:提取YAML frontmatter作为结构化元数据
- 标签提取:自动识别和提取黑曜石标签
先决条件
设置
- 克隆或下载此项目
- 设置
OBSIDIAN_VAULT_PATH环境变量:export OBSIDIAN_VAULT_PATH="/path/to/your/obsidian/vault" - 运行服务器:
# Using Deno directly deno task start # Using mise (if you have mise installed) mise run start
发展
对于具有文件监视功能的开发:
# Using Deno
deno task dev
# Using mise
mise run dev
测试
您可以使用附带的查询CLI工具测试MCP服务器:
# Search for notes containing a pattern (case-insensitive by default)
mise run query search "productivity"
# Case-sensitive search
mise run query search "TODO" --case-sensitive
# Search for whole words only
mise run query search "test" --whole-word
# Multiline search
mise run query search "pattern.*spans.*lines" --multiline
# Search with custom context lines (default: 5)
mise run query search "pattern" --context 10
# Read specific notes
mise run query read "daily-notes/2024-01-15"
mise run query read "note1" "folder/note2"
# Use verbose mode to see the request being sent
mise run query -v search "pattern"
mise run query --verbose read "note1"
查询工具连接到MCP服务器并返回原始JSON响应,这对于测试和调试非常有用。
工具
search_notes
使用ripgrep模式搜索vault中的markdown文件。
参数:
pattern(string,必填):ripgrep的搜索模式flags(数组,可选):其他ripgrep标志
退货: 包含以下内容的搜索结果数组:
path:相对注释路径(不带.md扩展名)matches:具有行号和上下文的匹配数组
read_notes
读取并解析vault中的一个或多个笔记。
参数:
paths(array,必填):相对注释路径数组(带或不带.md扩展名)
退货: 注释对象数组,包含:
name:注释名称(不带.md扩展名的相对路径)contents:Markdown内容(不含封面和标签)metadata:将frontmatter解析为JSON对象tags:提取的黑曜石标签数组
示例用法
连接到MCP客户端后,您可以:
// Search for notes containing "productivity"
await search_notes({
pattern: "productivity",
flags: ["-i"] // case-insensitive
});
// Read specific notes
await read_notes({
paths: ["daily-notes/2024-01-15", "projects/my-project"]
});
配置
服务器需要 OBSIDIAN_VAULT_PATH 将环境变量设置为您的Obsidian vault目录。
Claude桌面集成
要将此MCP服务器与Claude Desktop一起使用,请将其添加到您的Claude配置文件中:
macOS/Linux: ~/.config/claude/claude_desktop_config.json
视窗: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"notes": {
"command": "deno",
"args": [
"run",
"--allow-read=/path/to/your/obsidian/vault",
"--allow-run=rg",
"--allow-env=OBSIDIAN_VAULT_PATH",
"src/index.ts"
],
"cwd": "/path/to/notes-mcp",
"env": {
"OBSIDIAN_VAULT_PATH": "/path/to/your/obsidian/vault"
}
}
}
}
使用mise(如果您安装了mise,建议使用):
{
"mcpServers": {
"notes": {
"command": "/path/to/notes-mcp/start-server.sh",
"env": {
"OBSIDIAN_VAULT_PATH": "/path/to/your/obsidian/vault"
}
}
}
}
这使用了包含的 start-server.sh 处理更改到项目目录并运行的脚本 mise run start.
将路径替换为:
/path/to/notes-mcp:此项目目录的绝对路径/path/to/your/obsidian/vault:通往黑曜石金库的绝对路径
更新配置后,重新启动Claude Desktop。服务器将显示为“注释”,并提供 search_notes 和 read_notes 工具。
