MCP GO工具
    
一个以Go为中心的模型上下文协议(MCP)服务器,提供惯用的Go代码生成、样式指南和最佳实践。该工具帮助语言模型理解并按照既定的模式和惯例生成高质量的Go代码。
备注:该项目正在积极开发中。目前正在实施以下功能: - Go特定代码模式识别和生成 - 习惯性Go代码风格实施 - Go项目结构模板 该项目遵循干净的架构原则,并为可扩展性而设计。
关于MCP协议
模型上下文协议(MCP)使用 github.com/metoro-io/mcp-golang 图书馆。服务器:
- 使用stdio传输进行通信
- 支持优雅关机
- 使用errgroups处理并发操作
- 提供Go特定的代码生成工具
安装
go install github.com/ksysoev/mcp-go-tools/cmd/mcp-go-tools@latest特性
- Go特定的代码生成和样式指南
- 使用Cobra构建的命令行界面
- 使用YAML/JSON文件进行灵活配置
- 带slog的结构化测井
- 带有--log文件标志的文件输出支持(写入文件而不是stdout) - JSON和文本格式 - 可配置的日志级别 - 用于请求跟踪的调试日志记录
- 服务器管理命令
- 优雅关机的信号处理
快速开始
基本指挥结构
mcp-go-tools [command] [flags]有关详细的使用示例和模式,请参阅 用法.md.
常用命令
启动服务器
使用指定的配置启动MCP服务器:
mcp-go-tools start --config config.yaml使用文件日志记录运行
运行服务器时,将日志写入文件而不是stdout:
# JSON format (default)
mcp-go-tools start --config config.yaml --log-file=server.log
# Text format with debug level for request tracking
mcp-go-tools start --config config.yaml --log-file=server.log --log-text --log-level=debug注意:当提供--log文件时,日志将仅写入指定的文件,而不会写入stdout。
建筑
该应用程序遵循Go项目典型的干净、分层的架构:
- API层 (
pkg/api)
- 通过stdio传输处理MCP协议通信 - 通过优雅关机管理服务器生命周期 - 实现Go代码生成工具 - 使用errgroups进行并发操作
- 核心层 (
pkg/core)
- 实现Go代码模式识别 - 管理代码样式规则 - 处理MCP请求 - 设计用于基于界面的组件的可扩展性
- 库层 (
pkg/repo)
- 管理Go代码模式和模板 - 支持命名资源定义 - 实现简单的数据持久化 - 使用Viper进行资源配置映射
- 命令层 (
pkg/cmd)
- 执行CLI命令 - 处理配置和日志设置
全球旗帜
--config string Config file path
--log-level string Log level (debug, info, warn, error) (default "info")
--log-text Log in text format, otherwise JSON
--log-file string Log file path (if set, logs to stdout)配置文件
该工具支持通过JSON/YAML文件进行配置。使用指定配置文件路径 --config 旗帜。有关Go特定的模式和规则,请参阅example.config.yaml。
项目结构
.
├── cmd/
│ └── mcp-go-tools/ # Main application entry point
├── pkg/
│ ├── api/ # API service implementation
│ ├── cmd/ # Command implementations
│ ├── core/ # Core business logic
│ └── repo/ # Data repositories依赖项
- 达到1.23.4或更高
- github/metoro-io/mcp-golang-mcp协议实现
- github/spf13/cobra-命令行界面框架
- github/spf13/viper-配置管理
- golang.org/x/sync-同步原语
发展
项目状态
该项目正在积极开发中,包括以下组成部分:
- ✅ CLI框架和命令结构
- ✅ 配置管理
- ✅ MCP协议集成
- ✅ 成语Go代码生成
- ✅ Go项目模板
- ✅ 模拟支持
- 🚧 添加集成过梁
从源头构建
go build -o mcp-go-tools ./cmd/mcp-go-tools运行测试
go test ./...与Cline一起使用
要将此MCP服务器与Cline一起使用,请将其添加到Cline的MCP设置中
将以下配置添加到 mcpServers 设置文件中的对象:
{
"mcpServers": {
"code-tools": {
"command": "mcp-go-tools",
"args": ["server", "--config=/Users/user/mcp-go-tools/example.config.yaml"],
"env": {}
}
}
}
自定义说明示例:
Use project template to initialize new applications in GoLang, it's available in MCP server code-tools `codestyle` with category `template`
Every time you need to generate code use MCP server code-tools to `codestyle` for required category `code`, `documentation`, `testing`
example of request to MCP server code-tool:
{
"method": "tools/call",
"params": {
"name": "codestyle",
"arguments": {
"categories": "testing" #Comma separate list
},
}
}
Before finishing task you should run `golangci-lint` and recursively address issues until all issues are fixed
to fix field alignment issues you should use `fieldalignment -fix ./...`许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。

