内容
# MCPHub
**适用于所有AI编码CLI的单一MCP网关**
不再需要为每个CLI(OpenCode、Claude Code、Cursor、Zed、Pi)配置其自己的MCP服务器设置,只需运行一个中心枢纽并将它们全部指向一个URL即可。
```sh
npm install -g @taraksh011/mcphub
mcphub add my-server --stdio "npx -y some-mcp-server"
mcphub start
```
所有来自所有服务器的工具都出现在 `http://localhost:5431/mcp` 下。
## 安装
```sh
npm install -g @taraksh011/mcphub
```
或直接使用而无需安装:
```sh
npx @taraksh011/mcphub <command>
```
## 快速开始
```sh
# 添加服务器
mcphub add filesystem --stdio "npx -y @modelcontextprotocol/server-filesystem /tmp"
mcphub add github --stdio "npx -y @modelcontextprotocol/server-github"
# 列出已配置的服务器
mcphub list
# 启动中心枢纽(前台运行)
mcphub start
# 或以守护进程运行
mcphub start --daemon
# 显示中心枢纽状态(PID、端口、已配置的服务器)
mcphub status
# 停止守护进程
mcphub stop
# 显示配置文件路径
mcphub config
# 安装为开机自启动服务(系统启动时启动)
mcphub install-service
# 删除开机自启动服务
mcphub uninstall-service
```
中心枢纽默认监听 `http://localhost:5431/mcp`。可以使用 `--port` 参数覆盖:
```sh
mcphub start --port 8080
```
健康检查 `GET /health` 返回 `{ "status": "ok" }`。
## 配置您的CLI
### OpenCode
添加到 `~/.config/opencode/opencode.jsonc` 中:
```json
{
"mcp": {
"MCPHub": {
"type": "remote",
"url": "http://localhost:5431/mcp"
}
}
}
```
### Pi(终端AI)
添加到 `~/.pi/agent/mcp.json` 中:
```json
{
"mcpServers": {
"MCPHub": {
"url": "http://localhost:5431/mcp"
}
}
}
```
### Claude Code
```sh
claude mcp add --transport http mcphub http://localhost:5431/mcp
```
### Cursor
添加到项目中的 `.cursor/mcp.json` 中:
```json
{
"mcpServers": {
"MCPHub": {
"type": "http",
"url": "http://localhost:5431/mcp"
}
}
}
```
### Zed
添加到 `~/.config/zed/settings.json` 中:
```json
{
"mcp_servers": {
"MCPHub": {
"url": "http://localhost:5431/mcp"
}
}
}
```
## 添加MCP服务器
```sh
# 标准输入输出服务器(作为子进程运行)
mcphub add my-tools --stdio "npx -y @some/mcp-server --flag value"
# 使用环境变量
mcphub add my-tools --stdio "npx -y @some/mcp-server" -e API_KEY=abc -e DEBUG=true
# 远程HTTP服务器
mcphub add gh_grep --url https://mcp.grep.app
```
## 配置文件位置
- Linux: `~/.config/mcphub/config.json`
- macOS: `~/Library/Application Support/mcphub/config.json`
- Windows: `%APPDATA%\mcphub\config.json`
使用 `--config` 参数覆盖:
```sh
mcphub --config /path/to/config.json start
```
或设置 `MCPHUB_CONFIG` 环境变量。
## CLI参考
```
用法:mcphub [选项] [命令]
选项:
-V, --version 输出版本号
-c, --config <路径> 配置文件路径
-h, --help 显示命令帮助
命令:
start [选项] 启动MCP中心枢纽
stop 停止中心枢纽守护进程
add [选项] <名称> 添加服务器
remove <名称> 删除服务器
list 列出已配置的服务器
status 显示中心枢纽状态(PID、端口、服务器)
config 显示配置文件路径
install-service 安装为开机自启动服务(systemd/launchd/schtasks)
uninstall-service 删除开机自启动服务
help [命令] 显示命令帮助
```