工具中心mcp
无服务器MCP聚合器 -减少AI上下文令牌消耗
问题
当将多个MCP服务器与AI客户端(Claude Code、OpenCode等)一起使用时,每个服务器都会将其所有工具暴露给AI上下文窗口。更多的服务器=在您开始工作之前消耗的令牌更多。
解决方案
tool-hub-mcp 充当仅公开的单个MCP网关 2元工具:
| 工具 | 说明 |
|---|---|
hub_search | 跨服务器语义搜索工具(BM25+强盗排名) |
hub_execute | 从服务器执行工具(带学习系统) |
人工智能调用这些元工具来按需发现和执行工具,而不是预先加载所有工具定义。
基准
使用Claude Code v2.1.6进行测量 --output-format json 为了准确 input_tokens 计数。
测试:6台MCP服务器 (jira,剧作家,mcp大纲,shadcn,chrome开发工具,Figma)
| 配置 | 输入令牌 |
|---|---|
| 6个单独的MCP | 48,371 |
| 仅限工具中心 | 29,758 |
| 令牌已保存 | 18,613 |
| 减少 | 38.48% |
更大的测试:7台MCP服务器 (共98个工具)
| 配置 | 输入令牌 |
|---|---|
| 7个单独的MCP | 15,150 |
| 仅限工具中心 | 461 |
| 令牌已保存 | 14,689 |
| 减少 | 96.9% |
令牌优化(v1.2.0):
- 紧凑型JSON(无缩进):减少约35%
- 删除冗余字段:每个搜索结果约40%
- 结果:2个结果节省43.7%,10个结果节省约70%
安装
# Zero-install (recommended) - works with npx, bunx, pnpm dlx, yarn dlx
npx @khanglvm/tool-hub-mcp setup
# Alternative: Go install
go install github.com/khanglvm/tool-hub-mcp/cmd/tool-hub-mcp@latest快速开始
# 1. Import your existing MCP configs
tool-hub-mcp setup
# 2. Add to your AI client
# Claude Code:
claude mcp add -s user tool-hub -- npx -y @khanglvm/tool-hub-mcp serve用法
从AI工具导入配置
# Auto-detect and import from Claude Code, OpenCode, etc.
tool-hub-mcp setup手动添加MCP服务器
# Paste any MCP config format (auto-detected)
tool-hub-mcp add --json '{
"mcpServers": {
"jira": {"command": "npx", "args": ["-y", "@lvmk/jira-mcp"]},
"outline": {"command": "uvx", "args": ["mcp-outline"]}
}
}'
# Or use flags
tool-hub-mcp add jira --command npx --arg -y --arg @lvmk/jira-mcp管理服务器
# List all servers
tool-hub-mcp list
# Remove a server
tool-hub-mcp remove jira
# Verify configuration
tool-hub-mcp verify运行MCP服务器
# Start server (stdio transport)
tool-hub-mcp serve
# Via AI client (already configured)
claude mcp add tool-hub -- tool-hub-mcp serveBash/Grep导出工具索引
生成用于离线工具搜索的本地索引文件,而无需MCP开销:
# Export to default location (~/.tool-hub-mcp-index.jsonl)
tool-hub-mcp export-index
# Custom output path
tool-hub-mcp export-index --output ./my-tools.jsonl
# JSON array format (instead of JSONL)
tool-hub-mcp export-index --format json自动再生:运行时索引会自动更新 setup, add,或 remove 命令。
Bash/Grep使用示例:
# Find tools by server
grep '"jira"' ~/.tool-hub-mcp-index.jsonl
# Search tool descriptions
grep -i "search" ~/.tool-hub-mcp-index.jsonl | jq -r '.tool'
# List all tools
cat ~/.tool-hub-mcp-index.jsonl | jq -r '.tool'
# Count tools per server
cat ~/.tool-hub-mcp-index.jsonl | jq -r '.server' | sort | uniq -c
# Complex query: Find Jira tools with "issue" in description
grep '"jira"' ~/.tool-hub-mcp-index.jsonl | grep -i "issue" | jq .为什么要使用bash/grep?
- 零MCP开销(无进程生成)
- 脱机工作(本地文件)
- 标准Unix工具(无依赖关系)
- 可编写脚本和可组合
基准性能
# Compare token consumption
tool-hub-mcp benchmark
# Measure latency
tool-hub-mcp benchmark speed命令
| 命令 | 描述 |
|---|---|
setup | 从AI CLI工具导入MCP配置 |
add | 添加MCP服务器-粘贴JSON或使用标志 |
remove | 删除MCP服务器 |
list | 列出已注册的服务器 |
verify | 验证配置 |
serve | 运行MCP服务器(stdio) |
export-index | 导出bash/grep搜索工具索引(离线) |
benchmark | 比较代币消费 |
benchmark speed | 测量每台服务器的延迟 |
learning | 管理学习系统(状态、导出、清除、启用、禁用) |
支持的配置源
- 克劳德代码(
~/.claude.json,.mcp.json) - OpenCode(
~/.opencode.json) - 谷歌反重力(
~/.gemini/antigravity/mcp_config.json) - Gemini CLI(
~/.gemini/settings.json) - 光标(
~/.cursor/mcp.json) - 风帆冲浪(
~/.codeium/windsurf/mcp_config.json)
运作原理
┌─────────────────────────────────────────────────────────┐
│ AI Client │
│ (Claude Code, OpenCode, etc.) │
└───────────────────────┬─────────────────────────────────┘
│ 2 meta-tools
▼
┌─────────────────────────────────────────────────────────┐
│ tool-hub-mcp │
│ hub_search │ hub_execute │
└───────────────────────┬─────────────────────────────────┘
│ On-demand spawning
┌───────────────┼───────────────┐
▼ ▼ ▼
┌─────────┐ ┌─────────┐ ┌─────────┐
│ Jira │ │ Outline │ │ Figma │
│ MCP │ │ MCP │ │ MCP │
└─────────┘ └─────────┘ └─────────┘AI工作流程:
- 呼叫
hub_search("what I need")查找具有排名结果的工具 - 呼叫
hub_execute(server, tool, args, searchId)执行(学习跟踪使用情况)
结果: 按需加载工具定义,智能排名会随着时间的推移而提高。
建筑
技术栈:
- 语言: 转到1.22+(0.88ms启动)
- 分布: 零安装npm+Go二进制
- 运输: 基于stdio的JSON-RPC 2.0
- 协议: MCP 2024-11-05
关键设计决策:
- 懒惰产卵: 进程仅在访问工具时启动
- 进程池: 重用生成的进程(默认值:3)
- 安全请求ID: 原子计数器(非UnixNano)与JS兼容
- 标准排水: 防止管道缓冲区死锁
演出
令牌效率:
- 与传统方法相比减少38-97%
- v1.2.0:每次搜索可额外节省43-70%
- 使用更多服务器可以更好地扩展
- Bash/grep替代方案:零令牌(离线)
速度:
- 冷启动:约845ms(第一次工具调用)
- 热启动:~50ms(过程重复使用)
- 平均:5台服务器上307毫秒
内存:
- 配置:每台服务器约1KB
- 进程:每台活动服务器~5-10MB
- 池:~15-30MB(3个进程)
配置
配置位置: ~/.tool-hub-mcp.json
格式:
{
"servers": {
"serverName": {
"command": "npx",
"args": ["-y", "@package/name"],
"env": {"KEY": "value"},
"source": "claude-code"
}
},
"settings": {
"cacheToolMetadata": true,
"processPoolSize": 3,
"timeoutSeconds": 30
}
}开发工作流程
设置
安装git挂钩进行自动测试:
make setup-hooks测试
# Run all tests
make test
# Run tests with race detector
make test-race
# Run fast tests (pre-commit)
make test-fast
# Run full suite with coverage check (pre-push)
make test-coverageGit挂钩
- 预承诺: 对更改的包运行快速测试(约10秒)
- 预推: 运行全套保险检查(~60s,需要80%的保险)
- 旁路: 使用
git commit --no-verify或git push --no-verify紧急情况
钩子可以防止失败的代码到达远程存储库。覆盖率阈值强制为80%。
文档
全面的文档可在 /docs/:
- 项目概述和初步设计评审:
/docs/project-overview-pdr.md - 规范标准:
/docs/code-standards.md - 代码库摘要:
/docs/codebase-summary.md - 系统架构:
/docs/system-architecture.md - 设计指南:
/docs/design-guidelines.md - 部署指南:
/docs/deployment-guide.md - 项目路线图:
/docs/project-roadmap.md
贡献
欢迎投稿!请参阅:
/docs/架构和设计指南/CLAUDE.md用于开发工作流- GitHub错误报告和功能请求问题
许可证
麻省理工学院
链接
- npm: https://www.npmjs.com/package/@khanglvm/工具中心mcp
- github: https://github.com/khanglvm/tool-hub-mcp
- MCP协议: https://modelcontextprotocol.io/
