工具搜索MCP
⚠️ 警告:此项目仍处于实验阶段(v0.0.1)。API和功能可能会发生变化。
Claude Code的高性能客户端工具搜索服务,可动态搜索和加载相关的MCP工具,而不是一次加载所有工具。使用Ollama嵌入的语义搜索技术构建,用于智能工具匹配。
🎯 关键利益
技术优势
- 代币减少97.4%:基准显示,每次查询平均节省约12950个令牌
- 100%刀具选择精度:使用基于嵌入的搜索,所有主要测试用例都通过
- 更快的上下文窗口:较小的工具有效载荷意味着实际对话的空间更大
- 智能工具发现:语义搜索即使在自然语言查询中也能找到合适的工具
- 多种搜索方法:在嵌入(最准确)、BM25(最快)或正则表达式(轻量级)之间进行选择
业务影响
- 降低API成本:更少的代币=更低的Claude API账单
- 更好的性能:通过优化工具选择加快响应时间
- 可扩展性:加载数百台MCP服务器而不达到上下文限制
- 开发者体验:自然语言工具发现感觉更直观
基准结果
| 方法 | 快速模式(5次测试) | 扩展(113次测试) | 速度 |
|---|---|---|---|
| 嵌入 | 100% ✓ | 88.5% | 311ms |
| BM25 | 80% | 81.4% | 1ms |
| 正则表达式 | 80% | 79.6% | 7ms |
最准确:嵌入 nomic-embed-text-v2-moe\ 速度最佳:BM25,具有亚毫秒响应
🚀 快速开始
# Run directly without installation
bun x github:ImBIOS/tool-search-mcp
# Or install locally
git clone https://github.com/ImBIOS/tool-search-mcp.git
cd tool-search-mcp
bun install
bun run dev📋 先决条件
1.安装Olama
# Linux/macOS
curl -fsSL https://ollama.ai/install.sh | sh
# Start Ollama server
ollama serve2.拉动嵌入模型
ollama pull nomic-embed-text-v2-moe该模型针对生成嵌入进行了优化,并且比完整的LLM小得多。
⚡ 安装
# Clone and install
git clone https://github.com/ImBIOS/tool-search-mcp.git
cd tool-search-mcp
bun install
# Development mode (with hot reload)
bun run dev
# Production mode
bun run build
bun start🔧 配置
快速配置(环境变量)
export MCP_CONFIG='{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": { "GITHUB_TOKEN": "your-token" }
},
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/dir"]
}
}
}'配置文件
export MCP_CONFIG_PATH=./mcp-config.json哪里 mcp-config.json 包含:
{
"mcpServers": {
"dbhub": {
"command": "npx",
"args": ["-y", "@bytebase/dbhub@latest", "--port", "8082"],
"env": { "DSN": "postgres://user:pass@localhost/db" }
}
}
}📊 用法
基本搜索
curl -X POST http://localhost:3000/search \
-H "Content-Type: application/json" \
-d '{"query": "read a file from disk", "topK": 3}'答复:
{
"type": "tool_result",
"content": {
"type": "tool_search_result",
"tool_references": [
{ "type": "tool_reference", "tool_name": "read_file" },
{ "type": "tool_reference", "tool_name": "list_directory" },
{ "type": "tool_reference", "tool_name": "glob" }
]
},
"meta": {
"model": "nomic-embed-text-v2-moe",
"took": 45,
"results": [...]
}
}健康检查
curl http://localhost:3000/health答复:
{
"status": "healthy",
"ollamaConnected": true,
"model": "nomic-embed-text-v2-moe",
"toolsLoaded": 10
}🧪 基准
运行全面的基准测试以验证工具搜索的准确性:
# Quick benchmark (5 primary tests, one per MCP)
bun run benchmark
# Extended benchmark (113 tests with variations)
bun run benchmark -e
# With Claude CLI validation
bun run benchmark -c
# With verbose output
bun run benchmark -v
# Full benchmark (all models and formats)
bun run benchmark --full配置迁移
# Check current status
bun run config status
# Migrate to Tool Search MCP (regex - fastest)
bun run config migrate
# Migrate with embedding (most accurate)
bun run config migrate embedding
# Restore original config
bun run config restore🏗️ 建筑
┌─────────────┐ ┌──────────────────┐ ┌─────────────┐
│ Claude Code │────▶│ Tool Search API │────▶│ Ollama │
│ │ │ (this service) │ │ nomic-embed-│
│ │◀────│ │◀────│ text-v2-moe │
└─────────────┘ └──────────────────┘ └─────────────┘
│
▼
┌──────────────┐
│ Tools DB │
│ (embeddings) │
└──────────────┘
▲
│
┌──────────────┐
│ MCP │
│ Servers │
└──────────────┘🔍 搜索方法
1.嵌入搜索(推荐)
使用具有余弦相似性的语义嵌入进行最准确的工具匹配。最适合自然语言查询。
{
"type": "tool_search_tool_embedding"
}2.BM25搜索(最快)
基于关键字的统计搜索。闪电般快,但措辞不够灵活。
{
"type": "tool_search_tool_bm25_20251119"
}3.正则表达式搜索(轻量级)
模式匹配与启发式评分。开销最小。
{
"type": "tool_search_tool_regex_20251119"
}📁 项目结构
tool-search-mcp/
├── src/
│ ├── benchmark/ # Benchmark suite
│ │ └── tests/ # Test cases per MCP
│ ├── cli/ # CLI tools
│ ├── search/ # Search engine implementations
│ └── index.ts # Main entry point
├── package.json
└── README.md🛠️ 发展
# Type checking
bun run check-types
# Formatting
bun run format:ws
# Build
bun run build📝 许可证
麻省理工学院
🤝 贡献
欢迎投稿!请先阅读我们的投稿指南。
📧 支持
- 在GitHub上打开一个问题
- 电子邮件:imamuzzaki@gmail.com
