智能连接CLI和MCP服务器
用于智能连接的命令行工具和MCP(模型上下文协议)服务器-在黑曜石保险库中查找语义连接。
特性
- 🔍 查找连接 -发现语义上与特定注释相似的注释
- 🔎 语义搜索 -在vault中执行基于文本的搜索
- 📊 统计 -查看嵌入统计信息和vault覆盖率
- 📤 多个输出 -纯文本或JSON格式
- 🚀 独立 -无黑曜石跑步
- 🤖 MCP服务器 -用于AI代理集成的模型上下文协议服务器
需求
- Node.js>=18.0.0
- 安装了智能连接插件,并在黑曜石中建立了保险库索引
安装
CLI安装
# Install globally
npm install -g @yejianye/smart-connections-mcp全局安装后,您可以使用 smart-cli 命令:
export OBSIDIAN_VAULT=/path/to/your/vault
smart-cli connection "path/to/note.md"
smart-cli lookup "AI Coding"
smart-cli statsMCP服务器安装
安装用于AI代理集成的MCP服务器(例如,使用Claude Desktop):
选项1:使用Claude MCP CLI
claude mcp add ob-smart-connections -e OBSIDIAN_VAULT=/path/to/your/vault @yejianye/smart-connections-mcp选项2:手动配置
将以下json添加到您的MCP客户端配置中(例如, claude_desktop_config.json):
{
"mcpServers": {
"smart-connections": {
"command": "npx",
"args": ["-y", "@yejianye/smart-connections-mcp"],
"env": {
"OBSIDIAN_VAULT": "/path/to/your/vault"
}
}
}
}用法
设置Vault路径
# Set via environment variable (recommended)
export OBSIDIAN_VAULT=/path/to/your/vault
# Or use --vault flag with each command
smart-cli --vault=/path/to/vault 查找连接
查找语义上与特定注释相似的注释:
smart-cli connection "ML/Neural Networks.md"
# JSON output
smart-cli connection "Projects/Project A.md" --format=json
# Limit results
smart-cli connection "Daily/2024-01-15.md" --limit=5输出示例:
Found 5 connection(s):
[0.85] Machine Learning Basics
[0.78] Deep Learning
[0.72] AI Applications
[0.68] Data Science
[0.65] Python Programming查看统计信息
显示vault嵌入统计信息:
smart-cli stats
# JSON output
smart-cli stats --format=json输出示例:
Smart Connections Vault Statistics
===================================
Sources:
Total entries: 1234
Files: 1100
Blocks: 134
Embeddings:
With embeddings: 1200
Without embeddings: 34
Coverage: 97.2%
Model Info:
Embedding model(s): TaylorAI/bge-micro-v2
Vector dimension: 384
Estimated size: 1.85 MB
Settings:
Min characters: 200
File exclusions: Untitled
Folder exclusions: (none)
Exclude blocks: false验证数据
检查智能连接数据完整性:
smart-cli validate输出示例:
Validating Smart Connections data...
✓ Vault path is valid
✓ Smart Connections data found
✓ Data file is valid JSON
✓ Plugin settings found
✓ All embeddings are valid
✓ No orphaned files detected
==================================================
Validation Summary
==================================================
Checks passed: 6
Issues: 0
Warnings: 0
✅ All checks passed!语义搜索
在vault中执行基于文本的搜索:
smart-cli lookup "machine learning concepts"
# With options
smart-cli lookup "React hooks best practices" --limit=10 --skip-blocks
# JSON output
smart-cli lookup "project management" --format=json______________________________________________________________________
MCP工具
MCP服务器为AI代理提供以下工具:
可用的MCP工具
connection 工具
查找语义上与指定注释相似的注释。
{
"name": "connection",
"arguments": {
"note_path": "projects/my-project.md",
"limit": 10
}
}lookup 工具
使用查询文本执行语义搜索。
{
"name": "lookup",
"arguments": {
"query": "machine learning algorithms",
"limit": 15
}
}stats 工具
获取vault嵌入统计信息。
{
"name": "stats",
"arguments": {}
}validate 工具
验证智能连接数据完整性。
{
"name": "validate",
"arguments": {}
}MCP配置
通过以下方式配置vault访问权限:
- 环境变量:
OBSIDIAN_VAULT=/path/to/vault(安装时设置) - 工具参数:通行证
vault_path每个工具调用的参数
______________________________________________________________________
运作原理
CLI和MCP服务器读取Smart Connections Obsidian插件生成的嵌入数据:
- 数据源:阅读
.smart-env/smart_sources.json(单个文件)或.smart-env/multi/(多文件AJSON)从您的保管库中 - 设置:尊重来自的插件配置
.obsidian/plugins/smart-connections/data.json - 搜索算法:使用余弦相似度对连接进行排序
- MCP协议:通过AI代理的标准模型上下文协议公开功能
- 无依赖关系:独立工具-在没有完整智能包生态系统的情况下工作
发展
# Clone the repository
git clone https://github.com/smart-connections/cli.git
cd cli
# Install dependencies
npm install
# Run locally
npm start -- connection "path/to/note.md"
# Run MCP server
npm run mcp
# Run tests
npm test故障排除
“未找到智能源数据”
确保:
- 黑曜石中安装了智能连接插件
- 你打开了黑曜石的保险库,让它索引
- 要么
.smart-env/smart_sources.json或.smart-env/multi/目录已存在于vault中
“未指定保险库路径”
要么:
- 集
OBSIDIAN_VAULT环境变量 - 使用
--vault标志:smart-cli --vault=/path/to/vault command
“未找到或未嵌入源”
该说明可能:
- 保险库中不存在
- 太短(小于min_chars设置)
- 被文件/文件夹排除设置排除
- 尚未编入索引
跑 smart-cli validate 诊断问题。
许可证
麻省理工学院
