Go标准MCP服务器
中文文档 |英语
用于智能Go代码质量分析的模型上下文协议(MCP)服务,将行业标准linter与自定义规则引擎集成在一起。
特性
- MCP协议:与Claude Desktop和其他MCP客户端无缝集成
- 双重分析模式:完整存储库扫描或基于Git的增量检测
- 自定义规则:上传和管理团队特定的编码标准
- 多用户就绪:专为隔离用户上下文的共享部署而设计
- CLI+服务器:灵活的部署选项
快速开始
先决条件
- 转到1.21+
- golangci lint(可选,用于增强分析)
安装
# Build both server and CLI
make build-all
# Or build separately
make build-server # MCP server
make build-cli # Standalone CLI toolMCP服务器设置
配置Claude桌面(%APPDATA%\Claude\claude_desktop_config.json):
{
"mcpServers": {
"go-standards": {
"command": "D:\\path\\to\\bin\\mcp-server.exe",
"args": []
}
}
}CLI使用情况
# Full analysis
go-standards-cli --path ./myproject
# Incremental analysis (Git changes only)
go-standards-cli --path ./myproject --incremental
# Custom config
go-standards-cli --path ./myproject --config rules.yaml使用指南
1.全代码分析
使用默认设置分析整个Go项目:
使用MCP客户端(克劳德桌面):
Please analyze the Go code at /path/to/project using analyze_go_code tool使用CLI:
go-standards-cli --path /path/to/project使用特定的过梁:
{
"path": "/path/to/project",
"mode": "full",
"linters": ["golangci-lint", "govet"]
}预期产量:
- 按严重程度(错误、警告、信息)列出的问题计数
- 包含文件位置和行号的详细问题列表
- 建议的修复和最佳实践
- 总体质量得分
2.Git增量分析
只分析Git中已更改的文件,对于大型项目来说要快得多。
2.1快速检查项目是否为Git仓库
# Using CLI
go-standards-cli --path /path/to/project --git-check
# Or use git_check tool in MCP答复:
{
"is_git_repo": true,
"path": "/path/to/project",
"message": "This is a valid Git repository"
}2.2启用Git集成
步骤1:为您的项目启用Git集成
# Using CLI
go-standards-cli --path /path/to/project --git-enable
# Or use git_config tool in MCP with action="enable"这创建了一个 .go-standards.json 项目根目录中的配置文件:
{
"enabled": true,
"auto_commit": false,
"auto_push": false,
"base_branch": "origin/main",
"fail_on_error": true,
"hooks_installed": false
}步骤2:配置Git集成(可选)
# Set base branch for comparison
go-standards-cli --path /path/to/project --git-config \
--base-branch main
# Configure via git_config tool完整配置选项:
{
"action": "set",
"path": "/path/to/project",
"config": {
"enabled": true,
"base_branch": "main",
"auto_commit": true,
"auto_push": false,
"config_file": ".golangci.yml",
"fail_on_error": true
}
}2.3运行增量分析
分析暂存文件(提交前):
go-standards-cli --path /path/to/project --incremental --mode staged分析修改的文件(工作目录):
go-standards-cli --path /path/to/project --incremental --mode modified分析从分支更改的文件:
go-standards-cli --path /path/to/project --incremental \
--mode branch --base main使用MCP工具:
{
"path": "/path/to/project",
"mode": "incremental",
"linters": ["golangci-lint"]
}2.4安装Git钩子(提交/推送时自动检查)
# Install pre-commit hook
go-standards-cli --path /path/to/project --install-hooks commit
# Install pre-push hook
go-standards-cli --path /path/to/project --install-hooks push
# Install both
go-standards-cli --path /path/to/project --install-hooks all安装后,当您执行以下操作时,该工具将自动运行:
git commit-检查暂存文件git push-检查从基本分支更改的文件
挂钩行为:
- 通过:如果没有问题,提交/推送正常进行
- 失败:如果发现问题,提交/推送将被阻止,并显示问题
- 配置
fail_on_error: false允许带有警告的提交
3.自定义编码标准
上传团队的编码标准并自动生成linter配置。
3.1上传标准文档
支持的格式: PDF、Markdown、文本
# Using CLI
go-standards-cli --upload-document /path/to/team-standard.pdf \
--name "team-v1" \
--description "Company Go coding standards v1.0"
# Using MCP upload_document tool发生了什么:
- 文档被解析和分析
- 规则会自动提取
.golangci.yml配置已生成- 配置已保存到
storage/shared/configs/
3.2使用自定义标准进行分析
go-standards-cli --path /path/to/project --config team-v13.3列出可用标准
go-standards-cli --list-standards
# Or use list_standards MCP tool输出:
Available Coding Standards:
1. strict - Highest standards (complexity ≤ 5, coverage ≥ 85%)
2. standard - Balanced standards (complexity ≤ 10, coverage ≥ 70%)
3. relaxed - Basic standards (complexity ≤ 15, coverage ≥ 60%)
4. team-v1 - Company Go coding standards v1.04.高级配置
4.1定制过梁配置
创建 .golangci.yml 在项目根目录中:
linters:
enable:
- gofmt
- golint
- govet
- errcheck
- staticcheck
- gosec
linters-settings:
gocyclo:
min-complexity: 10
govet:
check-shadowing: true
errcheck:
check-type-assertions: true
issues:
exclude-rules:
- path: _test\.go
linters:
- gocyclo4.2多项目批量分析
# Analyze multiple projects
go-standards-cli --batch \
--projects "project1,project2,project3" \
--output batch-report.json4.3 CI/CD集成
GitHub操作示例:
name: Code Quality Check
on: [push, pull_request]
jobs:
quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install go-standards
run: |
wget https://github.com/MOONL0323/go-standards-mcp-server/releases/latest/download/go-standards-cli
chmod +x go-standards-cli
- name: Run analysis
run: |
./go-standards-cli --path . --incremental --mode branch --base origin/mainGitLab CI示例:
code_quality:
script:
- go-standards-cli --path . --incremental
only:
- merge_requests建筑
flowchart TB
subgraph Clients[MCP Clients Layer]
Claude[Claude Desktop]
VSCode[VS Code Extension]
Other[Other MCP Clients]
end
subgraph Server[Go Standards MCP Server]
direction TB
subgraph Protocol[MCP Protocol Layer]
Tools[MCP Tools: analyze_go_code, git_check/config, list_standards, upload_document, get/set_config]
Resources[Resources: standards, configs]
end
subgraph Service[Service Layer]
Analyzer[Analyzer Engine]
DocService[Document Service]
GitDetector[Git Detector]
ConfigMgr[Config Manager]
StorageMgr[Storage Manager]
SessionMgr[Session Manager]
end
subgraph Linters[Linter Integration]
Golangci[golangci-lint]
GoVet[go vet]
StaticCheck[staticcheck]
end
end
subgraph Storage[Storage Layer]
Shared[Shared: checklists, configs, templates]
UserData[User Isolated: history, settings, reports]
end
Claude -->|stdio| Protocol
VSCode -->|stdio| Protocol
Other -->|http/sse| Protocol
Protocol --> Service
Service --> Linters
Service --> Storage
classDef serverStyle fill:#e1f5ff,stroke:#0288d1,stroke-width:2px
classDef protocolStyle fill:#fff3e0,stroke:#f57c00,stroke-width:2px
classDef serviceStyle fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
classDef linterStyle fill:#e8f5e9,stroke:#388e3c,stroke-width:2px
classDef storageStyle fill:#fce4ec,stroke:#c2185b,stroke-width:2px
class Server serverStyle
class Protocol protocolStyle
class Service serviceStyle
class Linters linterStyle
class Storage storageStyle架构组件:
- MCP协议层:8个用于代码分析、git集成和配置管理的工具
- 服务层:具有并行执行、缓存和会话管理的核心业务逻辑
- 林特尔集成:golangci lint(40+跳棋),去兽医,统计检查
- 存储层:共享资源和用户隔离数据,会话超时30分钟
MCP工具
analyze_go_code
使用可配置的linter和规则分析Go代码。
参数:
path(必填):目标目录mode(可选):"full"或"incremental"(默认值:"full")linters(可选):例如。,["golangci-lint", "govet"]config(可选):自定义配置文件路径
例子:
{
"path": "/path/to/project",
"mode": "incremental",
"linters": ["golangci-lint"]
}git_check
快速检查路径是否为Git存储库。
list_standards
列出所有可用的编码标准文件。
upload_document
上传团队编码标准(PDF/Markdown)。
参数:
file_path:文档路径doc_type:"checklist"或"guideline"language:"go","python"等等。
get_config / set_config
获取或更新Git集成配置。
配置
Git集成(.go-standards-git.yaml)
git_integration:
enabled: true
base_branch: "main"
ignored_paths:
- "vendor/"
- "*.pb.go"
max_file_size_kb: 500分析配置
linters:
golangci:
enabled: true
config_file: ".golangci.yml"
govet:
enabled: true
rules:
max_function_lines: 100
require_comments: true多用户部署
存储结构:
storage/
├─ shared/ # Shared resources
│ ├─ checklists/ # Team standards
│ └─ configs/ # Default configs
└─ users/{userID}/ # User-isolated data (future)
├─ history/
└─ settings/Docker:
docker build -t go-standards-mcp .
docker run -d -p 8080:8080 \
-v /path/to/storage:/app/storage \
go-standards-mcp发展
make test # Run tests
make lint # Lint code
make fmt # Format code
make help # View commands常见问题解答
Q: 如何使用增量分析?\ A: 确保您的项目是Git存储库,然后使用 "mode": "incremental" 或 --incremental 旗帜。
Q: 我可以使用自定义编码标准吗?\ A: 是的,使用 upload_document 上传团队特定标准。
Q: 多语言支持?\ A: 目前专注于Go。框架支持扩展。
Q: 多用户部署?\ A: 使用带有持久存储的Docker/Kubernetes。用户隔离架构已准备就绪(请参阅 internal/usercontext/).
许可证
MIT许可证-请参阅 许可证
