使用说明
黑曜石CliMcp
MCP服务器公开 黑曜石CLI 作为AI代理的结构化工具。使用Go 1.26和 mcp走.
先决条件
- 转到1.26+
- 启用CLI的黑曜石1.12.0+(
Settings → General → Command line interface) obsidianPATH中的二进制文件(用验证which obsidian)
安装
去安装(推荐)
go install github.com/mitasych/obsidian-cli-mcp@latest
从源代码构建
git clone https://github.com/mitasych/obsidian-cli-mcp
cd obsidian-cli-mcp
go build -o obsidian-cli-mcp .
用法
Claude 桌面版
增添 ~/.config/claude/claude_desktop_config.json:
{
"mcpServers": {
"obsidian-cli-mcp": {
"command": "/absolute/path/to/obsidian-cli-mcp"
}
}
}
Claude 代码
claude mcp add obsidian ~/go/bin/obsidian-cli-mcp
或手动添加到 ~/.claude.json:
{
"mcpServers": {
"obsidian-cli-mcp": {
"command": "/absolute/path/to/obsidian-cli-mcp"
}
}
}
自定义二进制路径
如果 obsidian 不在PATH中,请设置 OBSIDIAN_PATH 环境变量:
{
"mcpServers": {
"obsidian-cli-mcp": {
"command": "/absolute/path/to/obsidian-cli-mcp",
"env": {
"OBSIDIAN_PATH": "/usr/bin/obsidian"
}
}
}
}
自定义超时
每次工具调用都会运行 obsidian CLI默认超时30秒。启动黑曜石感冒(尚未运行时)可能需要更长的时间;提高限额 OBSIDIAN_TIMEOUT。它接受Go持续时间字符串(45s, 2m)或者仅仅几秒钟(60):
{
"mcpServers": {
"obsidian-cli-mcp": {
"command": "/absolute/path/to/obsidian-cli-mcp",
"env": {
"OBSIDIAN_TIMEOUT": "60s"
}
}
}
}
工具
| 工具 | 说明 |
|---|---|
note_read |
按名称或vault相对路径读取笔记内容 |
note_create |
使用可选模板和内容创建新笔记 |
note_append |
将内容附加到现有注释中 |
note_prepend |
将内容预置到现有注释中 |
vault_search |
跨vault的全文搜索(JSON输出) |
files_list |
列出具有可选文件夹/扩展名筛选器的文件 |
property_set |
在笔记上设置frontmatter属性 |
tags_list |
列出vault中的标签(JSON输出) |
参数
工具接受 file (像维基链接一样解析)或 path (精确的vault相对路径)到目标笔记。每个工具的关键参数:
- note_read:
fileOrPath(必填) - note_create:
name(必填),path,content,template,overwrite - note_append/note_pender:
file或path,content(必填) - vault_search:
query(必填),path,limit,case - 文件列表:
folder - 属性设置:
name(必填),value(必填),type,file或path - tags_list:
file,path,counts,total
测试
go test ./...
与MCP检查员一起测试MCP
npx @modelcontextprotocol/inspector
项目结构
├── main.go # Entry point: MCP server init + stdio transport
├── internal/
│ ├── cli/
│ │ ├── runner.go # exec.Command wrapper with context timeout
│ │ └── runner_test.go
│ └── tools/
│ ├── tools.go # Tool registry (RegisterAll)
│ ├── notes.go # note_read, note_create, note_append, note_prepend
│ ├── search.go # vault_search
│ ├── files.go # files_list
│ ├── properties.go # property_set
│ └── tags.go # tags_list
└── DEVELOPMENT.md # Architecture and design decisions
许可证
麻省理工学院
