📦
Go
MCP Server GO
0 installs
1 stars
Trust: 56 — Fair
Devtools
Installation
npx mcp-server-goAsk AI about Go
Powered by Claude · Grounded in docs
I know everything about Go. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Loading tools...
Reviews
Documentation
MCP Server (Go Edition)
一个基于Go语言实现的MCP (Model Context Protocol) 服务器,提供高性能的JSON-RPC 2.0接口,兼容Cherry Studio和Dify平台。
特性
- 🚀 高性能: Go语言实现,性能比Python版本提升3-5倍
- 🔌 双平台兼容: 同时支持 Cherry Studio 和 Dify 平台
- 🧩 插件化架构: 工具模块化设计,易于扩展
- ⚙️ 灵活配置: 支持 .env 文件和环境变量配置
- 📊 Web管理界面: 提供工具管理、调用记录、统计分析
- 🔒 状态持久化: 工具启用/禁用状态自动保存
系统要求
- Go 1.21 或更高版本
- 可选: Docker, Prometheus, Jenkins, MySQL (用于对应工具)
快速开始
1. 克隆项目
git clone https://github.com/isYaoNoistu/mcp-server-go.git
cd mcp-server-go
2. 安装依赖
go mod download
3. 配置环境
复制示例配置文件:
cp .env.example .env
编辑 .env 文件配置各工具参数:
# Server Configuration
PORT=8000
HOST=0.0.0.0
GIN_MODE=release
# Read File Tool
READ_FILE_PATH=/path/to/your/file.md
# Prometheus Tool (optional)
PROMETHEUS_API_URL=http://localhost:9090
# MySQL Tool (optional)
MYSQL_DEFAULT_HOST=localhost
MYSQL_DEFAULT_PORT=3306
MYSQL_DEFAULT_USER=root
MYSQL_DEFAULT_PASSWORD=password
MYSQL_DEFAULT_DATABASE=mydb
# Jenkins Tool (optional)
JENKINS_URL=http://localhost:8080
JENKINS_USER=admin
JENKINS_TOKEN=your_token
# Tool Control
ALLOW_AUTO_ENABLE_NEW_TOOLS=true
# TOOL_READ_FILE=1 # Enable specific tool
# TOOL_PROMETHEUS=0 # Disable specific tool
4. 运行服务器
go run main.go
或编译后运行:
go build -o mcp-server-go
./mcp-server-go
服务器将在 http://localhost:8000 启动。
使用说明
Web管理界面
访问 http://localhost:8000 打开Web管理界面,可以:
- 查看所有工具列表
- 启用/禁用工具
- 查看调用记录
- 查看统计数据
- 配置工具参数
Cherry Studio 配置
- 打开 Cherry Studio 设置
- 导入 MCP 配置文件
cherry/cherry_mcp.json - 修改配置中的服务器地址为
http://localhost:8000/mcp - 保存配置
- 在对话中调用MCP工具
Dify 平台配置
- 在 Dify 中添加 MCP 服务器
- 服务器地址:
http://localhost:8000/mcp - 协议: JSON-RPC 2.0
- Dify 会自动调用
initialize和tools/list方法 - 在工作流中使用MCP工具
API 接口
MCP Endpoint
POST /mcp
JSON-RPC 2.0 接口,支持以下方法:
initialize- 初始化服务器tools/list- 列出所有可用工具tools/call- 执行工具
示例请求:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {}
}
REST API
GET /- Web管理界面GET /api/status- 服务器状态GET /api/tools- 工具列表POST /api/tools/toggle- 切换工具状态POST /api/config/save- 保存配置GET /api/records- 调用记录 (分页)GET /api/stats- 统计数据
可用工具
当前实现的工具:
- ✅ read_file - 文件读取工具
- 🚧 prometheus_tools - Prometheus查询工具 (待实现)
- 🚧 docker_tools - Docker管理工具 (待实现)
- 🚧 jenkins_tools - Jenkins集成工具 (待实现)
- 🚧 mysql_query_tools - MySQL查询工具 (待实现)
- 🚧 files_query_tools - 文件查询工具 (待实现)
- 🚧 system_check_tools - 系统检查工具 (待实现)
开发工具
添加新工具
- 在
tools/目录下创建新包 - 实现
core.Tool接口:
package mytool
import "github.com/isYaoNoistu/mcp-server-go/core"
type MyTool struct{}
func NewMyTool() core.Tool {
return &MyTool{}
}
func (t *MyTool) Name() string {
return "my_tool"
}
func (t *MyTool) Description() string {
return "My custom tool"
}
func (t *MyTool) InputSchema() map[string]interface{} {
return map[string]interface{}{
"type": "object",
"properties": map[string]interface{}{
"param1": map[string]interface{}{
"type": "string",
"description": "Parameter 1",
},
},
"required": []string{"param1"},
}
}
func (t *MyTool) Aliases() []string {
return []string{"mytool", "mt"}
}
func (t *MyTool) Run(params map[string]interface{}) (string, error) {
// Implementation
return "Tool executed successfully", nil
}
- 在
tools/tools.go中注册:
import "github.com/isYaoNoistu/mcp-server-go/tools/mytool"
func GetAllTools() []core.Tool {
return []core.Tool{
// ...existing tools
mytool.NewMyTool(),
}
}
运行测试
go test ./...
编译
# 本地编译
go build -o mcp-server-go
# 交叉编译 (Linux)
GOOS=linux GOARCH=amd64 go build -o mcp-server-go-linux
# 交叉编译 (Windows)
GOOS=windows GOARCH=amd64 go build -o mcp-server-go.exe
部署
systemd 服务
- 复制二进制文件到
/opt/mcp-server-go/ - 复制
.env文件到/opt/mcp-server-go/ - 复制 systemd 服务文件:
sudo cp systemd/mcp-server-go.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable mcp-server-go
sudo systemctl start mcp-server-go
Docker (即将支持)
docker build -t mcp-server-go .
docker run -p 8000:8000 --env-file .env mcp-server-go
项目结构
mcp-server-go/
├── main.go # 入口文件
├── core/ # 核心模块
│ ├── types.go # 类型定义
│ ├── protocol.go # JSON-RPC协议
│ ├── state.go # 状态管理
│ ├── records.go # 调用记录
│ ├── registry.go # 工具注册
│ └── api.go # API路由
├── config/ # 配置管理
│ └── config.go
├── tools/ # 工具实现
│ ├── tools.go # 工具注册
│ ├── readfile/
│ ├── prometheus/
│ ├── docker/
│ ├── jenkins/
│ ├── mysql/
│ ├── filesquery/
│ └── systemcheck/
└── web/ # Web界面
└── static/
性能对比
| 指标 | Python版本 | Go版本 | 提升 |
|---|---|---|---|
| 启动时间 | ~2.5s | ~0.3s | 8.3x |
| 内存占用 | ~80MB | ~15MB | 5.3x |
| QPS | ~500 | ~8000 | 16x |
| 并发处理 | 受限 | 优秀 | - |
贡献
欢迎提交 Issue 和 Pull Request!
许可证
MIT License
致谢
本项目基于 Python 版本的 MCP Server 重构而来,感谢原项目作者。
