Token导航 LogoToken导航TokenDH.com
Golang MCP logo
运维云端stdio官方级别未说明来源级核验

Golang MCP

MCP Server

MCP Go Server是一个为AI助手提供全面Go项目执行、优化和管理工具的服务实现,作为AI助手与Go运行时之间的桥梁。

工具数

22

提示词数

0

GitHub Stars

4

资源数

0
代码执行GoClaude性能优化Claude DesktopClaudeCursorWindsurfClineVS Code

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

inja-online

提供方

inja-online

最后核验

2026/5/17 20:19

运行时

Docker

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

docker run -it --rm \

详细介绍

MCP Go服务器

](https://golang.org) ![License](LICENSE) ![Release](https://github.com/inja-online/golang-mcp/releases) ![CI](https://github.com/inja-online/golang-mcp/actions) ![Contributors](https://github.com/inja-online/golang-mcp/graphs/contributors) ![Changelog](CHANGELOG.md)

MCP Go Server是一个模型上下文协议(MCP)服务器实现,旨在为AI助手提供执行、优化和管理Go项目的全面工具。该项目充当了AI助手(如Claude)和Go运行时之间的桥梁,使AI能够与基于Go的开发工作流程进行交互和控制。

目录

- 代码执行工具 - Go工具 - 优化工具 - 服务器管理工具 - 软件包文档工具 - LSP工具

快速开始

选择您的平台以快速开始:

热门平台

安装方法

  1. 去安装 -通过Go工具链安装(推荐)
  2. 来源 -从GitHub存储库构建
  3. 预构建二进制文件 -下载现成的二进制文件
  4. 码头工人 -使用容器化版本

你首先需要什么

  • 达到1.24或更高 -查看 go version
  • Git -用于克隆存储库(如果从源构建)

快速参考表

平台兼容性

平台macOSWindowsLinux难度
克劳德桌面⭐ 简单
光标⭐ 简单
VS代码⭐ 简单
Docker⭐⭐ 中等
JetBrains集成开发环境✅⭐⭐ 中等
风浪⭐ 简单
Zed⭐ 简单

安装方法比较

方法速度需要Go需要Docker最适合
转到安装⚡ 快速✅ 是❌ 否大多数用户
预构建二进制文件⚡ 快速❌ 否❌ 否未安装Go
来源🐌 较慢✅ 是❌ 否开发
Docker⚡ 快速❌ 否✅ 是容器

按操作系统配置文件位置

平台macOSWindowsLinux
克劳德桌面~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json~/.config/Claude/claude_desktop_config.json
VS代码~/.vscode/settings.json 或工作空间 .vscode/settings.json%APPDATA%\Code\User\settings.json~/.config/Code/User/settings.json
光标~/.cursor/settings.json%APPDATA%\Cursor\User\settings.json~/.config/Cursor/User/settings.json

常见问题快速解决

问题快速修复
找不到命令添加到PATH: export PATH=$PATH:$HOME/go/bin
权限被拒绝chmod +x /path/to/mcp-go
配置不起作用验证JSON,检查路径,重新启动客户端
工具未出现重新启动客户端,验证配置,检查日志
LSP不可用安装gopls: go install golang.org/x/tools/gopls@latest

快速参考

工具(共22个)

代码执行(1):

  • go_run -直接执行Go文件

Go操作(7):

  • go_build -构建Go包
  • go_test -运行覆盖率测试
  • go_fmt -设置Go代码格式
  • go_mod -管理Go模块
  • go_doc -生成文档
  • go_lint -Lint Go代码
  • go_cross_compile -跨平台交叉编译

优化(6):

  • go_profile -生成性能配置文件
  • go_trace -生成执行跟踪
  • go_benchmark -运行基准测试
  • go_race_detect -检测比赛状态
  • go_memory_profile -生成内存配置文件
  • go_optimize_suggest -获取优化建议

服务器管理(5):

  • go_server_start -启动后台服务器
  • go_server_stop -停止服务器
  • go_server_list -列出正在运行的服务器
  • go_server_logs -获取服务器日志
  • go_server_status -获取服务器状态

包装文件(3):

  • go_pkg_docs -从go.dev获取包文档
  • go_pkg_search -搜索包裹
  • go_pkg_examples -摘录示例

LSP工具(5个,可选-需要 ENABLE_LSP=true):

  • lsp_start_session -启动LSP会话
  • lsp_shutdown_session -关闭LSP会话
  • lsp_request -发送LSP请求
  • lsp_notify -发送LSP通知
  • lsp_subscribe_diagnostics -订阅诊断

资源(共8个)

  • go://modules -Go模块和依赖关系
  • go://build-tags -构建标签和约束
  • go://tests -测试文件和基准测试
  • go://workspace -工作空间结构
  • go://pkg-docs/{path} -包装文件
  • go://tools -列出所有可用工具
  • go://prompts -列出所有可用提示
  • go://resources -列出所有可用资源

提示(共7条)

  • setup-go-project -项目设置指南
  • write-go-tests -测试写作模板
  • optimize-go-performance -性能优化指南
  • debug-go-issue -调试指南
  • add-go-dependency -依赖管理指南
  • go-code-review -代码审查清单
  • go-server-deployment -部署指南

特性

  • 22个综合工具:代码执行、Go操作、优化、服务器管理、包文档和可选的LSP支持
  • 8探索资源:Access Go模块、构建标签、测试、工作区结构和包文档
  • 7引导提示:项目设置、测试、优化、调试、依赖关系、代码审查和部署的分步指南
  • 代码执行:直接使用执行Go文件 go run
  • Go操作:构建、测试、格式化和管理Go模块
  • 优化工具:性能分析、基准测试和种族检测
  • 服务器管理:启动、停止和监视长时间运行的Go服务器
  • 包文档:从go.dev(pkg.go.dev)获取包文档
  • 项目发现:发现Go模块、构建标签、测试文件和工作区结构
  • LSP支持:可选语言服务器协议集成(需要 ENABLE_LSP=true)
  • 交叉平台的:支持Linux、macOS和Windows
  • 交叉编译:为不同的平台和架构构建

先决条件

必修的:

  • 达到1.24或更高 -查看 go version
  • Git -用于克隆存储库(如果从源构建)

✅ 验证先决条件:

go version  # Should show go1.24 or higher
git --version  # Should show git version

安装方法

选择最适合您的安装方法:

方法最适合速度难度
去安装大多数用户⚡ 快速⭐ 简单
预构建二进制文件无需执行⚡ 快速⭐ 简单
来源发展🐌 较慢⭐⭐ 中等
码头工人集装箱⚡ 快速⭐⭐ 中等

使用Go安装

✅ 推荐给大多数用户

步骤:

  1. 运行安装命令:
go install github.com/inja-online/golang-mcp/cmd/mcp-go@latest
  1. 验证安装:
mcp-go --version

✅ 成功: 您应该看到版本号(例如。, mcp-go v0.0.1)

💡 提示: 二进制文件将安装到 $GOPATH/bin$HOME/go/bin。确保这在您的路径中。

⚠️ 故障排除:

  • 如果 mcp-go 找不到命令,请添加 $HOME/go/bin 到你的路径
  • 在macOS/Linux上: export PATH=$PATH:$HOME/go/bin
  • 在Windows上:添加 %USERPROFILE%\go\bin 到你的路径

来源

🔧 最适合开发或自定义构建

步骤:

  1. 克隆存储库:
git clone https://github.com/inja-online/golang-mcp.git
cd golang-mcp
  1. 构建项目:
make build
  1. 验证安装:
./bin/mcp-go --version

✅ 成功: 二进制文件将在 bin/ 目录

💡 提示: 您还可以使用 go build -o mcp-go ./cmd/mcp-go 如果你没有 make

使用预构建的二进制文件

✅ 最快的方法-无需Go安装

步骤:

  1. 下载自 发布页面
  1. 对于Linux/macOS:
curl -L https://github.com/inja-online/golang-mcp/releases/latest/download/golang-mcp_Linux_x86_64.tar.gz | tar xz
sudo mv mcp-go /usr/local/bin/
  1. 对于Windows:
  • 下载 .zip Windows文件
  • 抽出并移动 mcp-go.exe 到PATH中的某个目录(例如。, C:\Program Files\mcp-go\)
  1. 验证安装:
mcp-go --version

✅ 成功: 您应该看到版本号

💡 提示: 选择与您的操作系统和体系结构相匹配的二进制文件(Linux/MOSC/Windows,x86_64/arm64)

使用Docker

🔧 最适合容器化环境

从GitHub容器注册表中提取

步骤:

  1. 拉取图像:
docker pull ghcr.io/inja-online/golang-mcp:latest
  1. 验证:
docker images | grep golang-mcp

✅ 成功: 您应该看到列出的图像

从源代码构建

步骤:

  1. 克隆和构建:
git clone https://github.com/inja-online/golang-mcp.git
cd golang-mcp
docker build -t mcp-go:latest .
  1. 验证:
docker images | grep mcp-go

✅ 成功: 您应该看到列出的图像

使用Docker运行

基本用法:

docker run -it --rm \
  -v $(pwd):/workspace \
  -w /workspace \
  mcp-go:latest

使用docker编写:

docker-compose up

Docker编写配置

该项目包括 docker-compose.yml 地方发展:

命令:

docker-compose up              # Start the server
docker-compose up --build      # Build and start
docker-compose up -d           # Run in detached mode
docker-compose logs -f         # View logs
docker-compose down            # Stop the server

✅ 成功: 服务器应无错误启动

Docker镜像包括:

  • Alpine Linux基础版,体积小巧
  • Go运行时环境
  • 预配置的工作目录
  • 环境变量支持

配置

🔧 配置MCP Go服务器 使用环境变量或配置文件设置。

可以使用环境变量配置服务器:

export DISABLE_NOTIFICATIONS=true  # Disable permission prompts
export DEBUG_MCP=true               # Enable debug logging
export ENABLE_LSP=true              # Enable LSP tools (optional)
export GOROOT=/path/to/go           # Custom GOROOT
export GOPATH=/path/to/gopath        # Custom GOPATH
export GOOS=linux                    # Target OS for cross-compilation
export GOARCH=amd64                  # Target architecture
export GOPROXY=https://proxy.golang.org  # Go proxy URL

配置选项

变量类型默认值描述
DISABLE_通知布尔值false设置为 true 禁用命令执行的权限提示
DEBUG_MCP布尔值false设置为 true 启用调试日志记录(有助于故障排除)
ENABLE_LSP布尔值false设置为 true 以启用LSP工具。需要PATH中的gopls
戈鲁特string自动检测自定义Go根目录
GOPATHstring默认自定义Go工作区路径
string当前操作系统交叉编译的目标操作系统
果阿string当前arch交叉编译的目标架构
GOPROXY字符串https://proxy.golang.orgGo模块代理URL

这意味着:

  • DISABLE_通知:防止权限提示(对自动化有用)
  • DEBUG_MCP:显示详细日志(有助于排除故障)
  • ENABLE_LSP:启用语言服务器协议工具(需要 gopls 已安装)
  • GOROOT/GOPATH:覆盖Go安装路径(通常自动检测)
  • GOOS/GOARCH:设置交叉编译的目标平台
  • GOPROXY:更改Go从何处获取模块

常见配置示例

💡 在LSP支持下开发:

export DEBUG_MCP=true
export ENABLE_LSP=true
export DISABLE_NOTIFICATIONS=true

✅ 生产构建配置:

export DISABLE_NOTIFICATIONS=true
export GOOS=linux
export GOARCH=amd64
export GOPROXY=https://proxy.golang.org

🔧 自定义Go安装:

export GOROOT=/usr/local/go
export GOPATH=$HOME/go

⚠️ 注: 需要将shell中设置的环境变量传递给MCP客户端的配置文件 env 让它们生效。

平台特定指南

为您的平台配置MCP Go服务器。每个指南都包括分步说明、配置文件位置和验证步骤。

快速平台参考

平台配置位置难度
克劳德桌面~/Library/Application Support/Claude/claude_desktop_config.json (macOS)
%APPDATA%\Claude\claude_desktop_config.json (Windows)⭐ 简单
光标设置→ MCP服务器⭐ 简单
VS代码.vscode/settings.json 或用户设置⭐ 简单
Dockerdocker-compose.yml 或命令行⭐⭐ 中等
  1. Claude Desktop - ⭐ Easy - Most popular desktop app

先决条件:

  • 已安装Claude Desktop
  • mcp-go 已安装二进制文件(请参见 安装方法)

步骤:

  1. 查找您的配置文件位置:

- macOS: ~/Library/Application Support/Claude/claude_desktop_config.json - 窗户: %APPDATA%\Claude\claude_desktop_config.json - Linux: ~/.config/Claude/claude_desktop_config.json

  1. 打开或创建配置文件
  1. 添加MCP服务器配置:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": [],
      "env": {
        "DISABLE_NOTIFICATIONS": "true"
      }
    }
  }
}
  1. 更新命令路径:

- 替换 /usr/local/bin/mcp-go 与你的实际 mcp-go 路径 - 通过以下方式查找: which mcp-go (macOS/Linux)或 where mcp-go (Windows)

  1. 重新启动克劳德桌面

✅ 验证:

  • 打开克劳德桌面
  • 检查MCP工具是否可用
  • 尝试让Claude运行Go命令

⚠️ 故障排除:

  • 如果工具未出现,请检查配置文件JSON是否有效
  • 验证二进制路径是否正确
  • 检查Claude Desktop日志是否有错误
  1. Cursor - ⭐ Easy - AI-powered code editor

先决条件:

  • 光标已安装
  • mcp-go 已安装二进制文件

步骤:

  1. 打开光标设置:

- 按 Cmd+, (macOS)或 Ctrl+, (Windows/Linux) - 或:光标→ 设置→ 设置

  1. 导航到MCP服务器:

- 在设置中搜索“MCP” - 或转到:设置→ 特性→ MCP服务器

  1. 添加服务器配置:

- 点击“添加服务器”或编辑JSON设置 - 添加配置:

{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": [],
      "env": {
        "DISABLE_NOTIFICATIONS": "true"
      }
    }
  }
}
  1. 更新命令路径 以匹配您的安装
  1. 重新加载光标 (重新启动或重新加载窗口)

✅ 验证:

  • 打开Go文件
  • 检查命令选项板中的MCP工具是否可用
  • 尝试使用Go相关的AI功能
  1. VS Code - ⭐ Easy - Popular code editor with MCP support

先决条件:

  • 安装了MCP扩展的VS代码
  • mcp-go 已安装二进制文件

步骤:

  1. 选择配置位置:

- 工作区: .vscode/settings.json (项目特定) - 用户: 用户设置JSON(全局)

  1. 打开设置JSON:

- 按 Cmd+Shift+P (macOS)或 Ctrl+Shift+P (Windows/Linux) - 键入“首选项:打开设置(JSON)” - 或编辑 .vscode/settings.json 在您的工作空间中

  1. 添加MCP服务器配置:
{
  "mcp.servers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": [],
      "env": {
        "DISABLE_NOTIFICATIONS": "true"
      }
    }
  }
}
  1. 更新命令路径
  1. 重新加载VS代码窗口

✅ 验证:

  • 检查MCP服务器消息的输出面板
  • 验证Go环境: go version 集成终端
  • 测试工具:尝试调用 go_fmtgo_test

💡 提示: 对于工作区设置,请创建 .vscode/settings.json 在项目根目录中

  1. Cline (VS Code Extension) - ⭐ Easy - VS Code extension for AI coding

先决条件:

  • 安装了Cline扩展的VS代码
  • mcp-go 已安装二进制文件

步骤:

  1. 安装Cline扩展 来自VS Code市场
  1. 打开临床设置:

- 转到:设置→ 扩展→ Cline - 或编辑JSON设置

  1. 添加MCP服务器:
{
  "cline.mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新命令路径并重新加载

✅ 验证: Cline应该认识MCP Go工具

  1. Windsurf - ⭐ Easy - AI-powered IDE

先决条件:

  • 安装挡风玻璃
  • mcp-go 已安装二进制文件

步骤:

  1. 打开风帆设置:

- 转到“设置”→ MCP服务器

  1. 添加配置:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": [],
      "env": {
        "DISABLE_NOTIFICATIONS": "true"
      }
    }
  }
}
  1. 更新路径并重新启动Windsurf

✅ 验证: Windsurf中提供的MCP工具

  1. Zed - ⭐ Easy - Modern code editor

先决条件:

  • Zed已安装
  • mcp-go 已安装二进制文件

步骤:

  1. 打开Zed设置:

- Cmd+, (macOS)或 Ctrl+, (Windows/Linux)

  1. 导航到MCP配置:

- 设置→ 特性→ MCP

  1. 添加服务器:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径并重新启动Zed

✅ 验证: MCP集成工作

  1. JetBrains AI Assistant - ⭐⭐ Medium - Works with all JetBrains IDEs

先决条件:

  • 启用AI助手的JetBrains IDE
  • mcp-go 已安装二进制文件

步骤:

  1. 打开IDE设置:

- 转到:设置/首选项→ 工具→ AI助手→ MCP服务器

  1. 添加MCP服务器:

- 点击“添加”或编辑配置 - 添加:

{
  "mcp-go": {
    "command": "/usr/local/bin/mcp-go",
    "args": [],
    "env": {
      "DISABLE_NOTIFICATIONS": "true"
    }
  }
}
  1. 更新路径并重新启动IDE

✅ 验证: AI助手可以使用Go工具

💡 提示: 与IntelliJ IDEA、GoLand、WebStorm、PyCharm等合作。

  1. Perplexity Desktop - ⭐ Easy - Desktop AI assistant

先决条件:

  • 困惑桌面已安装
  • mcp-go 已安装二进制文件

步骤:

  1. 打开困惑设置:

- 设置→ 集成→ MCP服务器

  1. 添加配置:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径并重新启动

✅ 验证: 困惑可以访问Go工具

  1. Amazon Q Developer CLI - ⭐ Easy - AWS AI coding assistant CLI

先决条件:

  • 已安装Amazon Q Developer CLI
  • mcp-go 已安装二进制文件

步骤:

  1. 创建或编辑配置文件:

- 地点: ~/.aws-q/config.json%USERPROFILE%\.aws-q\config.json

  1. 添加MCP服务器:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径

✅ 验证:aws-q 支持Go的命令

  1. Smithery - ⭐ Easy - MCP server management tool

先决条件:

  • Smithery已安装
  • mcp-go 已安装二进制文件

步骤:

  1. 打开Smithery配置:

- 编辑 ~/.smithery/config.json 或使用Smithery UI

  1. 添加服务器:
{
  "servers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径并重新启动Smithery

✅ 验证: 服务器出现在Smithery

  1. Claude Code CLI - ⭐ Easy - Command-line Claude interface

先决条件:

  • 已安装Claude Code CLI
  • mcp-go 已安装二进制文件

步骤:

  1. 编辑配置文件:

- 地点: ~/.claude-code/config.json

  1. 添加配置:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径

✅ 验证: CLI可以使用Go工具

  1. Amp - ⭐ Easy - AI coding assistant

先决条件:

  • 已安装放大器
  • mcp-go 已安装二进制文件

步骤:

  1. 打开放大器设置:

- 设置→ MCP服务器

  1. 添加服务器:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径并重新启动

✅ 验证: 放大器集成工作

  1. Warp Terminal - ⭐ Easy - Modern terminal with AI

先决条件:

  • 已安装曲速终端
  • mcp-go 已安装二进制文件

步骤:

  1. 打开扭曲设置:

- Cmd+, (macOS)或 Ctrl+, (Windows/Linux)

  1. 导航到AI→ MCP服务器
  1. 添加配置:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径并重新启动Warp

✅ 验证: Warp中的AI功能可以使用Go工具

  1. Copilot Coding Agent - ⭐ Easy - GitHub Copilot agent

先决条件:

  • 已安装副驾驶编码代理
  • mcp-go 已安装二进制文件

步骤:

  1. 编辑配置:

- 地点: ~/.copilot/config.json

  1. 添加MCP服务器:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径

✅ 验证: Copilot代理可以使用Go工具

  1. Copilot CLI - ⭐ Easy - GitHub Copilot command line

先决条件:

  • 已安装GitHub Copilot CLI
  • mcp-go 已安装二进制文件

步骤:

  1. 配置Copilot CLI:

- 编辑 ~/.github/copilot/config.json

  1. 添加服务器:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径

✅ 验证: CLI命令与Go配合使用

  1. LM Studio - ⭐ Easy - Local LLM interface

先决条件:

  • LM Studio已安装
  • mcp-go 已安装二进制文件

步骤:

  1. 打开LM Studio设置:

- 设置→ MCP服务器

  1. 添加配置:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径并重新启动

✅ 验证: LM Studio可以使用Go工具

  1. Visual Studio 2022 - ⭐⭐ Medium - Microsoft IDE

先决条件:

  • 带MCP扩展的Visual Studio 2022
  • mcp-go 已安装二进制文件

步骤:

  1. 安装MCP扩展 适用于Visual Studio 2022
  1. 打开工具→ 选项→ MCP服务器
  1. 添加服务器:

- 姓名: mcp-go - 命令:路径 mcp-go.exe - Args:(空)

  1. 保存并重新启动Visual Studio

✅ 验证: Visual Studio中提供的MCP工具

  1. Roo Code - ⭐ Easy - AI coding assistant

先决条件:

  • Roo代码已安装
  • mcp-go 已安装二进制文件

步骤:

  1. 打开Roo代码设置:

- 设置→ MCP配置

  1. 添加服务器:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径并重新启动

✅ 验证: Roo代码集成工作

  1. Gemini CLI - ⭐ Easy - Google Gemini command line

先决条件:

  • 已安装Gemini CLI
  • mcp-go 已安装二进制文件

步骤:

  1. 编辑配置:

- 地点: ~/.gemini/config.json

  1. 添加MCP服务器:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径

✅ 验证: Gemini CLI可以使用Go工具

  1. Qwen Coder - ⭐ Easy - AI coding assistant

先决条件:

  • 已安装Qwen编码器
  • mcp-go 已安装二进制文件

步骤:

  1. 打开设置:

- 设置→ MCP服务器

  1. 添加配置:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径并重新启动

✅ 验证: Qwen编码器集成工作

  1. Opencode - ⭐ Easy - Open-source AI coding tool

先决条件:

  • 已安装Opencode
  • mcp-go 已安装二进制文件

步骤:

  1. 编辑配置:

- 地点: ~/.opencode/config.json

  1. 添加服务器:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径

✅ 验证: Opencode可以使用Go工具

  1. OpenAI Codex - ⭐ Easy - OpenAI coding assistant

先决条件:

  • OpenAI Codex访问
  • mcp-go 已安装二进制文件

步骤:

  1. 配置Codex:

- 编辑 ~/.openai/codex/config.json

  1. 添加MCP服务器:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径

✅ 验证: 食典一体化工作

  1. Kiro - ⭐ Easy - AI coding assistant

先决条件:

  • Kiro已安装
  • mcp-go 已安装二进制文件

步骤:

  1. 打开Kiro设置:

- 设置→ MCP服务器

  1. 添加配置:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径并重新启动

✅ 验证: Kiro可以使用Go工具

  1. Trae - ⭐ Easy - AI development tool

先决条件:

  • Trae已安装
  • mcp-go 已安装二进制文件

步骤:

  1. 编辑配置:

- 地点: ~/.trae/config.json

  1. 添加服务器:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径

✅ 验证: Trae集成工作

  1. Bun Runtime - ⭐ Easy - JavaScript runtime with MCP support

先决条件:

  • Bun已安装
  • mcp-go 已安装二进制文件

步骤:

  1. 创建MCP配置:

- 地点: ~/.bun/mcp/config.json

  1. 添加配置:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径

✅ 验证: Bun可以使用MCP Go服务器

  1. Deno Runtime - ⭐ Easy - JavaScript/TypeScript runtime

先决条件:

  • Deno已安装
  • mcp-go 已安装二进制文件

步骤:

  1. 配置Deno MCP:

- 编辑 ~/.deno/mcp/config.json

  1. 添加服务器:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径

✅ 验证: Deno MCP集成工作

  1. Docker - ⭐⭐ Medium - Container-based installation

先决条件:

  • Docker已安装
  • Docker Compose(可选,便于管理)

步骤:

  1. 拉取图像:
docker pull ghcr.io/inja-online/golang-mcp:latest
  1. 运行容器:
docker run -it --rm \
  -v $(pwd):/workspace \
  -w /workspace \
  ghcr.io/inja-online/golang-mcp:latest
  1. 或者使用docker compose:

- 创建 docker-compose.yml:

version: '3.8'
services:
  mcp-go:
    image: ghcr.io/inja-online/golang-mcp:latest
    volumes:
      - .:/workspace
    working_dir: /workspace
    stdin_open: true
    tty: true
  1. 从docker compose开始:
docker-compose up

✅ 验证:

docker run --rm ghcr.io/inja-online/golang-mcp:latest mcp-go --version

💡 提示: 使用卷将Go项目装载到容器中

  1. Desktop Extension (.mcpb) - ⭐ Easy - MCP bundle format for easy installation

先决条件:

  • 支持MCP的兼容客户端 .mcpb 文件

步骤:

  1. 下载.mcpb文件 从释放
  1. 安装捆绑包:

- 双击 .mcpb 文件,或 - 使用MCP客户端的“安装捆绑包”功能

  1. 按照客户端特定的安装提示进行操作

✅ 验证: 捆绑包出现在MCP客户端的服务器列表中

💡 提示: .mcpb 文件是包含所有依赖项的自包含捆绑包

  1. Windows (Detailed) - ⭐ Easy - Complete Windows installation guide

先决条件:

  • Windows 10/11
  • 安装1.24+(可选,用于从源代码构建)

步骤:

  1. 下载Windows二进制文件:

- 首选 发布页面 - 下载 golang-mcp_Windows_x86_64.zip

  1. 提取存档:

- 右击→ 全部提取 - 或使用: Expand-Archive golang-mcp_Windows_x86_64.zip

  1. 移动到永久位置:

- 创建文件夹: C:\Program Files\mcp-go\ - 移动 mcp-go.exe 那里

  1. 添加到路径:

- 开放系统属性→ 环境变量 - 编辑“Path”变量 - 添加: C:\Program Files\mcp-go - 在所有对话框中单击“确定”

  1. 验证安装:

- 打开PowerShell或命令提示符 - 运行: mcp-go --version

✅ 成功: 您应该看到版本号

⚠️ 故障排除:

  • 如果找不到命令,请在添加到PATH后重新启动终端
  • 检查路径: $env:PATH (PowerShell)或 echo %PATH% (CMD)
  • 验证文件是否存在: Test-Path "C:\Program Files\mcp-go\mcp-go.exe"
  1. BoltAI - ⭐ Easy - AI coding assistant

先决条件:

  • 已安装BoltAI
  • mcp-go 已安装二进制文件

步骤:

  1. 打开BoltAI设置:

- 设置→ MCP服务器

  1. 添加配置:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径并重新启动

✅ 验证: BoltAI集成工作

  1. Rovo Dev CLI - ⭐ Easy - Development CLI tool

先决条件:

  • 已安装Rovo Dev CLI
  • mcp-go 已安装二进制文件

步骤:

  1. 编辑配置:

- 地点: ~/.rovo/config.json

  1. 添加MCP服务器:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径

✅ 验证: Rovo CLI可以使用Go工具

  1. Zencoder - ⭐ Easy - AI code generation tool

先决条件:

  • Zencoder已安装
  • mcp-go 已安装二进制文件

步骤:

  1. 打开Zencoder设置:

- 设置→ MCP配置

  1. 添加服务器:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径并重新启动

✅ 验证: Zencoder可以使用Go工具

  1. Qodo Gen - ⭐ Easy - AI code generator

先决条件:

  • Qodo Gen已安装
  • mcp-go 已安装二进制文件

步骤:

  1. 编辑配置:

- 地点: ~/.qodo/config.json

  1. 添加MCP服务器:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径

✅ 验证: Qodo Gen集成工作

  1. Factory - ⭐ Easy - AI development platform

先决条件:

  • 工厂安装
  • mcp-go 已安装二进制文件

步骤:

  1. 打开出厂设置:

- 设置→ MCP服务器

  1. 添加配置:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径并重新启动

✅ 验证: 工厂可以使用Go工具

  1. Crush - ⭐ Easy - AI coding assistant

先决条件:

  • 已安装压碎装置
  • mcp-go 已安装二进制文件

步骤:

  1. 编辑配置:

- 地点: ~/.crush/config.json

  1. 添加服务器:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径

✅ 验证: 粉碎集成工作

  1. Augment Code - ⭐ Easy - AI code augmentation tool

先决条件:

  • 已安装增强代码
  • mcp-go 已安装二进制文件

步骤:

  1. 打开增强代码设置:

- 设置→ MCP服务器

  1. 添加配置:
{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}
  1. 更新路径并重新启动

✅ 验证: Augment Code可以使用Go工具

独立使用

直接运行MCP Go服务器:

mcp-go

服务器使用JSON-RPC 2.0协议通过stdio(标准输入/输出)进行通信。

💡 提示: 适用于测试或自定义集成

Troubleshooting - Common issues and their solutions

常见问题及其解决方案。利用症状快速找到你的问题。

安装问题

❌ “找不到命令:mcp-go”

症状:

  • 终端说 mcp-go: command not found
  • 二进制文件存在,但无法运行

解决:

  1. 检查是否安装了二进制文件:
   which mcp-go  # macOS/Linux
   where mcp-go   # Windows
  1. 添加到路径:

- macOS/Linux: 添加 $HOME/go/bin 前往PATH

     export PATH=$PATH:$HOME/go/bin

- 窗户: 添加 %USERPROFILE%\go\bin 环境变量中的PATH

  1. 验证路径:
   echo $PATH  # macOS/Linux
   echo %PATH% # Windows

✅ 成功: mcp-go --version 应该工作

❌ “权限被拒绝”

症状:

  • Permission denied 运行时出错 mcp-go

解决:

  1. 使二进制文件可执行:
   chmod +x /path/to/mcp-go
  1. 检查文件权限:
   ls -l /path/to/mcp-go
  1. 在Windows上: 如果需要,以管理员身份运行

❌ “Go版本太旧”

症状:

  • Go版本错误
  • 需要Go 1.24+

解决:

  1. 检查Go版本:
   go version
  1. 更新Go:

- 访问 golang.org - 下载最新版本 - 安装并重新启动终端

配置问题

❌ “找不到配置文件”

症状:

  • 平台找不到配置文件
  • 服务器未启动

解决:

  1. 创建配置文件 如果它不存在
  2. 检查文件位置 (见平台特定指南)
  3. 验证JSON语法 有效
  4. 检查文件权限 (可读)

❌ “配置中的JSON无效”

症状:

  • 配置文件存在语法错误
  • 服务器无法启动

解决:

  1. 验证JSON:

- 使用在线JSON验证器 - 或者: python -m json.tool config.json

  1. 常见错误:

- 缺少逗号 - 尾随逗号 - 未闭合支架

  1. 修复并重新启动 您的MCP客户端

❌ “二进制路径不正确”

症状:

  • 服务器找不到 mcp-go 二进制
  • 日志中的路径错误

解决:

  1. 找到正确的路径:
   which mcp-go  # macOS/Linux
   where mcp-go  # Windows
  1. 使用绝对路径 在配置中(非相对)
  1. 在Windows上: 使用正斜杠或双反斜杠:
   "command": "C:/Program Files/mcp-go/mcp-go.exe"
   // or
   "command": "C:\\Program Files\\mcp-go\\mcp-go.exe"

平台特定问题

❌ Claude Desktop:工具未显示

症状:

  • 配置文件看起来正确
  • Claude中没有可用的工具

解决:

  1. 重新启动克劳德桌面 完全
  2. 检查配置文件位置:

- macOS: ~/Library/Application Support/Claude/claude_desktop_config.json - 窗户: %APPDATA%\Claude\claude_desktop_config.json

  1. 验证JSON 语法
  2. 检查克劳德桌面日志 对于错误
  3. 验证二进制路径 正确且可执行

❌ VS代码:MCP扩展不工作

症状:

  • MCP扩展已安装但无法工作
  • 没有可用的工具

解决:

  1. 检查扩展是否已启用
  2. 重新加载VS代码窗口: Cmd+Shift+P → “重新加载窗口”
  3. 检查输出面板 对于MCP消息
  4. 验证设置JSON 语法
  5. 尝试工作区设置 而不是用户设置

❌ Docker:容器无法启动

症状:

  • Docker容器立即退出
  • 权限错误

解决:

  1. 检查Docker是否正在运行:
   docker ps
  1. 检查图像是否存在:
   docker images | grep golang-mcp
  1. 检查卷装载量:

- 验证路径是否正确 - 检查已装载目录的权限

  1. 查看日志:
   docker logs 

运行时问题

❌ “未找到Go命令”

症状:

  • MCP服务器找不到 go 命令
  • Go工具失败

解决:

  1. 验证Go是否已安装:
   go version
  1. 检查路径是否包括Go:
   echo $PATH  # Should include Go bin directory
  1. 设置GOROOT 如果需要:
   export GOROOT=/usr/local/go

❌ “LSP工具不可用”

症状:

  • LSP工具未出现
  • ENABLE_LSP=true 但没有工具

解决:

  1. 检查gopls是否已安装:
   which gopls
   go install golang.org/x/tools/gopls@latest
  1. 验证ENABLE_LSP是否已设置:
   echo $ENABLE_LSP  # Should be "true"
  1. 重新启动MCP服务器 设置环境变量后

❌ “权限提示不断出现”

症状:

  • 每个命令的权限提示
  • 想要禁用它们

解决:

  1. 设置禁用通知:
   export DISABLE_NOTIFICATIONS=true
  1. 添加到配置文件 env 章节:
   "env": {
     "DISABLE_NOTIFICATIONS": "true"
   }
  1. 重新启动MCP客户端

性能问题

❌ “服务器速度慢”

症状:

  • 命令执行时间过长
  • 超时

解决:

  1. 启用调试日志记录:
   export DEBUG_MCP=true
  1. 检查系统资源 (CPU、内存)
  1. 检查Go代理:
   go env GOPROXY
  1. 尝试不同的GOPROXY:
   export GOPROXY=https://proxy.golang.org

获取更多帮助

还有问题吗?

  1. 检查日志:

- 启用 DEBUG_MCP=true - 检查平台特定的日志位置

  1. 验证安装:
   mcp-go --version
   go version
  1. 独立测试:
   echo '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | mcp-go
  1. 查看GitHub问题:

- 搜索现有问题 - 使用以下内容创建新问题: - 错误消息 - 平台信息 - 配置文件(已清理) - 调试日志

常见问题解答

常见问题和快速答案。

安装

Q: 我需要安装Go才能使用MCP Go服务器吗?\ A. 不可以。您可以使用预构建的二进制文件或Docker。只有从源代码构建时才需要Go。

Q: 我应该使用哪种安装方法?\ A.

  • 大多数用户: 去安装(最简单)
  • 未安装Go: 预构建二进制文件
  • 发展: 来源
  • 容器: 码头工人

Q: 我可以在Windows上安装吗?\ A. 对。从版本中下载Windows二进制文件或使用Go Install。看 Windows(详细) 导游。

Q: 我需要在PATH中添加mcp吗?\ A. 是的,如果使用Go Install或二进制文件。Docker不需要PATH设置。

配置

Q: 配置文件在哪里?\ A. 这取决于你的平台。看 平台特定指南 根据您平台的位置。

Q: 我可以使用环境变量吗?\ A. 对。看 配置 可用变量部分。

Q: 更改配置后是否需要重新启动?\ A. 对。更改配置后重新启动MCP客户端(Claude Desktop、VS Code等)。

Q: 我可以使用多个MCP服务器吗?\ A. 对。在您的 mcpServers 对象。

平台支持

Q: 它适用于\[Platform X\]吗?\ A. 如果您的平台支持MCP协议,它应该可以工作。请参阅 平台特定指南 有关设置说明。

Q: 我可以在多个IDE中使用它吗?\ A. 对。在每个IDE的设置中单独配置它。

Q: 它离线工作吗?\ A. 大多数功能都可以脱机工作。包文档工具需要互联网才能从go.dev获取。

特性

Q: 有哪些可用的工具?\ A. 总共22个工具。看 快速参考可用工具 查看完整列表。

Q: 我需要LSP支持吗?\ A. 可选。集 ENABLE_LSP=true 并安装 gopls 如果你想要LSP工具。

Q: 我可以运行Go测试吗?\ A. 对。使用 go_test 该工具具有各种覆盖范围、基准等选项。

Q: 我可以为不同的平台进行构建吗?\ A. 对。使用 go_cross_compile 为不同操作系统/架构构建的工具。

故障排除

Q: 我的客户端中没有显示工具。发生了什么?\ A.

  1. 检查配置文件JSON是否有效
  2. 验证二进制路径是否正确
  3. 重新启动MCP客户端
  4. 检查日志是否有错误

Q: “找不到命令”错误?\ A. 添加 mcp-go 到你的路径。看 故障排除 部分。

Q: 权限提示一直出现?\ A.DISABLE_NOTIFICATIONS=true 在您的配置或环境中。

Q: 如何启用调试日志记录?\ A.DEBUG_MCP=true 环境变量或配置文件中。

发展

Q: 我可以捐款吗?\ A. 对!看 贡献 部分。欢迎拉取请求。

Q: 我在哪里报告bug?\ A. 在GitHub上创建一个问题,并提供有关该问题的详细信息。

Q: 如何从源代码构建?\ A.来源 在安装方法部分。

Q: 我可以自定义服务器吗?\ A. 是的,如果从源头开始构建。分叉存储库并根据需要进行修改。

可用工具

22种综合工具 用于Go开发、测试、优化和管理。

View detailed tool documentation

代码执行工具

✅ go_run

使用直接执行Go文件 go run.

参数:

  • file (string,必填):要运行的Go文件的路径
  • args (\[\]string,可选):传递给程序的命令行参数
  • working_dir (string,可选):命令的工作目录
  • env_vars (map\[string\]字符串,可选):其他环境变量

示例:

运行一个简单的Go文件:

{
  "name": "go_run",
  "arguments": {
    "file": "main.go"
  }
}

使用命令行参数运行:

{
  "name": "go_run",
  "arguments": {
    "file": "server.go",
    "args": ["--port", "8080", "--host", "localhost"]
  }
}

使用环境变量运行:

{
  "name": "go_run",
  "arguments": {
    "file": "app.go",
    "env_vars": {
      "DEBUG": "true",
      "LOG_LEVEL": "info"
    }
  }
}

Go工具

🔧 7工具 用于构建、测试、格式化和管理Go代码。

✅ go_build

使用各种构建标志构建Go包和依赖项。

参数:

  • package (字符串,可选):要构建的包路径(默认:当前目录)
  • output (字符串,可选):输出文件名
  • race (bool,可选):启用种族检测器
  • tags (\[\]字符串,可选):构建标记
  • ldflags (字符串,可选):链接器标志
  • trimpath (bool,可选):从可执行文件中删除文件系统路径
  • working_dir (字符串,可选):工作目录

示例:

基本构建:

{
  "name": "go_build",
  "arguments": {
    "output": "myapp"
  }
}

使用种族检测器构建:

{
  "name": "go_build",
  "arguments": {
    "output": "myapp",
    "race": true
  }
}

使用构建标签和版本信息构建:

{
  "name": "go_build",
  "arguments": {
    "output": "myapp",
    "tags": ["production", "linux"],
    "ldflags": "-X main.version=1.0.0 -X main.buildTime=$(date +%s)",
    "trimpath": true
  }
}

go_test

Run-Go测试具有覆盖率、基准测试和种族检测功能。

参数:

  • package (字符串,可选):要测试的包路径
  • cover (bool,可选):启用覆盖率分析
  • cover_pkg (字符串,可选):要覆盖的包
  • bench (bool,可选):运行基准测试
  • race (bool,可选):启用种族检测器
  • verbose (bool,可选):详细输出
  • timeout (字符串,可选):测试超时

示例:

运行所有测试:

{
  "name": "go_test",
  "arguments": {
    "verbose": true
  }
}

运行覆盖率测试:

{
  "name": "go_test",
  "arguments": {
    "cover": true,
    "cover_pkg": "./..."
  }
}

使用基准测试和种族检测运行测试:

{
  "name": "go_test",
  "arguments": {
    "bench": true,
    "race": true,
    "timeout": "30s"
  }
}

go_fmt

使用格式化Go代码 go fmt.

参数:

  • paths (\[\]字符串,可选):格式化路径(默认:当前目录)
  • working_dir (字符串,可选):工作目录

示例:

格式化当前目录:

{
  "name": "go_fmt",
  "arguments": {}
}

格式化特定文件:

{
  "name": "go_fmt",
  "arguments": {
    "paths": ["./cmd", "./internal"]
  }
}

go_mod

管理Go模块(初始化、整理、下载、供应商、获取)。

参数:

  • operation (string,必填):模块操作:初始化、整理、下载、供应商、获取
  • module_path (string,可选):模块路径(用于init或get)
  • packages (\[\]字符串,可选):包路径(用于get)
  • working_dir (字符串,可选):工作目录

示例:

初始化新模块:

{
  "name": "go_mod",
  "arguments": {
    "operation": "init",
    "module_path": "github.com/user/project"
  }
}

整洁的依赖关系:

{
  "name": "go_mod",
  "arguments": {
    "operation": "tidy"
  }
}

添加依赖关系:

{
  "name": "go_mod",
  "arguments": {
    "operation": "get",
    "packages": ["github.com/gin-gonic/gin@latest"]
  }
}

供应商依赖关系:

{
  "name": "go_mod",
  "arguments": {
    "operation": "vendor"
  }
}

go_doc

为Go包生成文档。

参数:

  • package (字符串,必填):包路径
  • all (bool,可选):显示所有文档
  • working_dir (字符串,可选):工作目录

示例:

查看软件包文档:

{
  "name": "go_doc",
  "arguments": {
    "package": "net/http"
  }
}

查看所有文档,包括未导出的符号:

{
  "name": "go_doc",
  "arguments": {
    "package": "./internal/utils",
    "all": true
  }
}

go_lint

Lint-Go代码使用golangci Lint或Go vet。

参数:

  • package (string,可选):到lint的包路径
  • linter (string,可选):要使用的Linter:golangci lint或vet(默认:vet)
  • working_dir (字符串,可选):工作目录

示例:

带宠物的猫:

{
  "name": "go_lint",
  "arguments": {
    "package": "./..."
  }
}

golangci棉绒:

{
  "name": "go_lint",
  "arguments": {
    "linter": "golangci-lint",
    "package": "./cmd"
  }
}

go_cross_compile

为不同平台交叉编译Go代码。

参数:

  • package (字符串,可选):要构建的包路径
  • output (字符串,必填):输出文件名
  • goos (string,必填):目标操作系统(例如linux、darwin、windows)
  • goarch (string,必填):目标架构(例如amd64、arm64)
  • working_dir (字符串,可选):工作目录

示例:

为Linux构建:

{
  "name": "go_cross_compile",
  "arguments": {
    "output": "myapp-linux",
    "goos": "linux",
    "goarch": "amd64"
  }
}

Windows版本:

{
  "name": "go_cross_compile",
  "arguments": {
    "output": "myapp.exe",
    "goos": "windows",
    "goarch": "amd64"
  }
}

为macOS ARM构建:

{
  "name": "go_cross_compile",
  "arguments": {
    "output": "myapp-darwin-arm64",
    "goos": "darwin",
    "goarch": "arm64"
  }
}

优化工具

⚡ 6工具 用于分析、基准测试和优化Go代码性能。

✅ go_profile

使用pprf生成性能配置文件。

参数:

  • type (string,必填):配置文件类型:cpu或mem
  • output (字符串,必填):输出配置文件路径
  • duration (字符串,可选):配置文件持续时间
  • package (字符串,可选):打包到配置文件
  • working_dir (字符串,可选):工作目录

示例:

生成CPU配置文件:

{
  "name": "go_profile",
  "arguments": {
    "type": "cpu",
    "output": "cpu.prof"
  }
}

生成内存配置文件:

{
  "name": "go_profile",
  "arguments": {
    "type": "mem",
    "output": "mem.prof",
    "package": "./internal/handlers"
  }
}

go_trace

为Go程序生成执行跟踪。

参数:

  • output (字符串,必填):输出跟踪文件路径
  • package (字符串,可选):要跟踪的包
  • working_dir (字符串,可选):工作目录

例子:

{
  "name": "go_trace",
  "arguments": {
    "output": "trace.out",
    "package": "./..."
  }
}

go_benchmark

运行基准测试并分析结果。

参数:

  • pattern (字符串,可选):要匹配的基准模式
  • count (int,可选):迭代次数
  • timeout (字符串,可选):基准超时
  • package (字符串,可选):打包到基准测试
  • working_dir (字符串,可选):工作目录

示例:

运行所有基准测试:

{
  "name": "go_benchmark",
  "arguments": {}
}

运行特定的基准模式:

{
  "name": "go_benchmark",
  "arguments": {
    "pattern": "BenchmarkSort",
    "count": 5
  }
}

运行带有超时的基准测试:

{
  "name": "go_benchmark",
  "arguments": {
    "timeout": "10m",
    "package": "./internal/cache"
  }
}

go_race_detect

在Go代码中检测比赛条件。

参数:

  • package (字符串,可选):要测试的包
  • working_dir (字符串,可选):工作目录

例子:

{
  "name": "go_race_detect",
  "arguments": {
    "package": "./..."
  }
}

go_memory.profile

生成内存配置文件以供分析。

参数:

  • output (字符串,必填):输出配置文件路径
  • package (字符串,可选):打包到配置文件
  • working_dir (字符串,可选):工作目录

例子:

{
  "name": "go_memory_profile",
  "arguments": {
    "output": "mem.prof",
    "package": "./internal/processor"
  }
}

go_optimize_建议

分析代码,并根据分析和基准测试提供优化建议。

参数:

  • package (字符串,可选):要分析的包
  • working_dir (字符串,可选):工作目录

示例:

分析当前包:

{
  "name": "go_optimize_suggest",
  "arguments": {}
}

分析特定包:

{
  "name": "go_optimize_suggest",
  "arguments": {
    "package": "./internal/processor"
  }
}

该工具运行基准测试和静态分析,以提供优化建议,包括:

  • 绩效基准的基准结果
  • 静态分析问题 go vet
  • 一般优化建议
  • 关于种族检测、分析和并发改进的建议

服务器管理工具

🚀 5工具 用于在后台管理长时间运行的Go服务器。

✅ go_server_start

在后台启动一个长时间运行的Go服务器。

参数:

  • id (字符串,必填):唯一服务器ID
  • name (字符串,必填):服务器名称
  • command (string,必填):要运行的命令(通常是'go'或二进制路径)
  • args (\[\]string,必填):命令参数
  • working_dir (字符串,可选):工作目录
  • env_vars (map\[string\]字符串,可选):环境变量
  • log_size (int,可选):要保留的最大日志行数(默认值:1000)

go_server_stop

停止正在运行的服务器。

参数:

  • id (字符串,必填):服务器ID
  • force (bool,可选):强制终止服务器(SIGKILL)

go_server_list

列出所有正在运行的服务器。

go_server_logs

从正在运行的服务器获取日志。

参数:

  • id (字符串,必填):服务器ID
  • count (int,可选):最近的日志行数(全部为0)

go_server_status

获取服务器的详细状态。

参数:

  • id (字符串,必填):服务器ID

软件包文档工具

📚 3工具 用于发现和探索Go包文档。

✅ go_pkg_docs

从go.dev(pkg.go.dev)获取包文档。返回包概述、函数、类型和示例。

参数:

  • package (string,必填):包路径(例如,github/gin-gonic/gin,net/http)
  • version (字符串,可选):包版本

示例:

获取标准库文档:

{
  "name": "go_pkg_docs",
  "arguments": {
    "package": "net/http"
  }
}

获取第三方软件包文档:

{
  "name": "go_pkg_docs",
  "arguments": {
    "package": "github.com/gin-gonic/gin",
    "version": "v1.9.1"
  }
}

工具返回:

  • 包装概述和说明
  • 带有签名和描述的功能列表
  • 类型及其种类和描述列表
  • 代码示例(如果可用)

go_pkg_search

在go.dev上搜索包。返回匹配的包路径列表。

参数:

  • query (字符串,必填):搜索查询

示例:

搜索HTTP路由器:

{
  "name": "go_pkg_search",
  "arguments": {
    "query": "http router"
  }
}

搜索数据库驱动程序:

{
  "name": "go_pkg_search",
  "arguments": {
    "query": "database driver postgres"
  }
}

该工具返回与您的查询匹配的包路径列表,然后您可以使用该列表 go_pkg_docs 审查文件。

go_pkg_示例

从软件包文档中提取示例。

参数:

  • package (字符串,必填):包路径
  • version (字符串,可选):包版本

示例:

从标准库中提取示例:

{
  "name": "go_pkg_examples",
  "arguments": {
    "package": "net/http"
  }
}

从第三方软件包中提取示例:

{
  "name": "go_pkg_examples",
  "arguments": {
    "package": "github.com/gin-gonic/gin",
    "version": "v1.9.1"
  }
}

LSP工具

🔌 5工具 用于语言服务器协议集成(可选)。

⚠️ 备注:LSP工具是可选的,需要 ENABLE_LSP=true 要设置的环境变量。这些工具为高级IDE功能提供了语言服务器协议集成。

✅ lsp_start_session

为工作区根URI启动LSP会话。

参数:

  • root_uri (字符串,必填):工作区根URI(文件://路径)
  • gopls_path (字符串,可选):gopls二进制文件的路径(默认:搜索Path)
  • args (\[\]string,可选):gopls的其他参数
  • env (map\[string\]string,可选):gopls的环境变量

示例:

使用默认gopls启动会话:

{
  "name": "lsp_start_session",
  "arguments": {
    "root_uri": "file:///path/to/workspace"
  }
}

使用自定义gopls路径启动会话:

{
  "name": "lsp_start_session",
  "arguments": {
    "root_uri": "file:///path/to/workspace",
    "gopls_path": "/usr/local/bin/gopls",
    "args": ["-rpc.trace"],
    "env": {
      "GOPATH": "/custom/gopath"
    }
  }
}

lsp_shutdown_session

关闭工作区根URI的LSP会话。

参数:

  • root_uri (字符串,必填):工作区根URI

例子:

{
  "name": "lsp_shutdown_session",
  "arguments": {
    "root_uri": "file:///path/to/workspace"
  }
}

lsprequest

向LSP会话发送请求并等待结果。

参数:

  • root_uri (字符串,必填):工作区根URI
  • method (字符串,必填):LSP方法名称(例如,“textDocument/hover”、“textDocument/cognition”)
  • params (对象,可选):请求参数

示例:

获取悬停信息:

{
  "name": "lsp_request",
  "arguments": {
    "root_uri": "file:///path/to/workspace",
    "method": "textDocument/hover",
    "params": {
      "textDocument": {
        "uri": "file:///path/to/workspace/main.go"
      },
      "position": {
        "line": 10,
        "character": 5
      }
    }
  }
}

获取代码完成:

{
  "name": "lsp_request",
  "arguments": {
    "root_uri": "file:///path/to/workspace",
    "method": "textDocument/completion",
    "params": {
      "textDocument": {
        "uri": "file:///path/to/workspace/main.go"
      },
      "position": {
        "line": 15,
        "character": 20
      }
    }
  }
}

lspnotify

向LSP会话发送通知(不等待响应)。

参数:

  • root_uri (字符串,必填):工作区根URI
  • method (字符串,必填):LSP方法名称(例如,“textDocument/didChange”、“textDocument/dedOpen”)
  • params (对象,可选):通知参数

例子:

{
  "name": "lsp_notify",
  "arguments": {
    "root_uri": "file:///path/to/workspace",
    "method": "textDocument/didOpen",
    "params": {
      "textDocument": {
        "uri": "file:///path/to/workspace/main.go",
        "languageId": "go",
        "version": 1,
        "text": "package main\n\nfunc main() {\n}"
      }
    }
  }
}

lspsubscribe_dignostics

订阅LSP会话发布的诊断。

参数:

  • root_uri (字符串,必填):工作区根URI

例子:

{
  "name": "lsp_subscribe_diagnostics",
  "arguments": {
    "root_uri": "file:///path/to/workspace"
  }
}

这允许从指定工作区的LSP服务器接收诊断通知(错误、警告等)。

可用资源

📦 8发现资源 用于探索您的Go工作区和访问软件包文档。

✅ go://模块

当前工作区中的Go模块和依赖项列表。

用途: 了解项目依赖关系、检查版本、计划更新

✅ go://构建标签

生成项目中的标记和约束。

用途: 查找特定于平台的代码、功能标志、条件构建

✅ go://测试

项目中的测试文件和基准测试列表。

用途: 发现测试覆盖率、发现基准、理解测试结构

✅ go://工作空间

转到工作区结构和配置。

用途: 了解项目布局,查找主要包,规划重构

✅ go://pkg-docs/{path}

从go.dev获取包文档。支持版本化路径(例如go://pkg-docs/encoding/json@v1.0.0).

用途: 快速访问标准库文档,查看第三方软件包文档

✅ go://工具

所有可用工具及其名称、描述和参数模式的列表。使用此资源了解MCP服务器中可用的工具。

用途: 发现可用工具,了解工具参数,找到合适的工具

✅ go://提示

所有可用提示及其名称、描述和参数的列表。使用此资源可以发现可用于指导工作流的提示。

用途: 查找特定任务的提示,理解提示参数,发现工作流程

✅ go://资源

所有可用资源及其URI、名称和描述的列表。使用此资源可以发现MCP服务器中可用的资源。

用途: 了解可用资源,查找资源URI,规划基于资源的工作流

可用提示

💡 7个引导提示 了解分步工作流程和最佳实践。

提示为常见的Go开发任务提供了指导性的工作流程和分步说明。每个提示都接受参数以自定义指导。

✅ 设置go项目

使用模块初始化、目录结构和最佳实践设置新Go项目的指南。

论据:

  • project_name (string,必填):要设置的Go项目的名称
  • module_path (string,可选):Go模块路径(例如github.com/username/project)

使用案例:

  • 从头开始初始化新的Go项目
  • 按照Go最佳实践设置项目结构
  • 创建一个适当的基于模块的项目

例子:

{
  "name": "setup-go-project",
  "arguments": {
    "project_name": "my-api",
    "module_path": "github.com/user/my-api"
  }
}

此提示将指导您完成以下操作:

  1. 正在初始化Go模块
  2. 创建标准目录结构(cmd/、internal/、pkg/等)
  3. 设置README和.gitignore
  4. 创建初始main.go
  5. 运行去mod整洁

✅ 写go测试

用于编写全面Go测试的模板,包括单元测试、基准测试和表驱动测试。

论据:

  • package_path (string,必填):用于编写测试的包路径
  • test_type (字符串,可选):要编写的测试类型:单元、基准、集成或全部(默认值:全部)

使用案例:

  • 为新包编写测试
  • 向现有代码添加测试覆盖率
  • 为性能关键型代码创建基准
  • 设置集成测试

示例:

编写所有测试类型:

{
  "name": "write-go-tests",
  "arguments": {
    "package_path": "./internal/processor",
    "test_type": "all"
  }
}

只编写单元测试:

{
  "name": "write-go-tests",
  "arguments": {
    "package_path": "./internal/utils",
    "test_type": "unit"
  }
}

此提示提供以下指导:

  • 表驱动测试模式
  • 包含子测试的测试组织
  • 错误案例测试
  • 基准创建
  • 集成测试设置

✅ 优化go性能

使用pprf、基准测试和竞争检测分析和优化Go代码性能的指南。

论据:

  • package_path (string,必填):要优化的包
  • optimization_goal (字符串,可选):优化目标:cpu、内存、并发性或常规(默认值:常规)

使用案例:

  • 识别性能瓶颈
  • 优化CPU密集型代码
  • 减少内存分配
  • 提高并发性能

示例:

一般优化:

{
  "name": "optimize-go-performance",
  "arguments": {
    "package_path": "./internal/processor",
    "optimization_goal": "general"
  }
}

以CPU为中心的优化:

{
  "name": "optimize-go-performance",
  "arguments": {
    "package_path": "./internal/processor",
    "optimization_goal": "cpu"
  }
}

此提示将指导您完成以下操作:

  1. 用基准建立基线
  2. 分析CPU和内存使用情况
  3. 使用pprf分析配置文件
  4. 识别并解决瓶颈
  5. 衡量改进
  6. 比赛状态检测

✅ 调试go问题

调试Go程序的系统方法,包括竞争条件、恐慌和性能问题。

论据:

  • issue_type (字符串,可选):问题类型:恐慌、竞争、性能、死锁或未知(默认值:未知)
  • package_path (string,可选):问题发生的包

使用案例:

  • 调试恐慌和崩溃
  • 查找比赛条件
  • 调查性能问题
  • 解决死锁

示例:

引发恐慌:

{
  "name": "debug-go-issue",
  "arguments": {
    "issue_type": "panic",
    "package_path": "./internal/handlers"
  }
}

调试竞争条件:

{
  "name": "debug-go-issue",
  "arguments": {
    "issue_type": "race",
    "package_path": "./internal/worker"
  }
}

此提示提供:

  • 逐步调试工作流程
  • 针对特定问题的调试策略
  • 工具建议(go_test、go_race_detect、go_trace等)
  • 修复后的验证步骤

✅ 添加go依赖项

使用Go-mod添加和管理Go依赖项的指南。

论据:

  • package_path (string,必填):要添加的包路径(例如,github.com/gin-gonic/gin)
  • version (字符串,可选):特定版本或最新版本(默认:最新)

使用案例:

  • 向项目添加新的依赖项
  • 更新现有依赖关系
  • 管理依赖关系版本

示例:

添加最新版本:

{
  "name": "add-go-dependency",
  "arguments": {
    "package_path": "github.com/gin-gonic/gin"
  }
}

添加特定版本:

{
  "name": "add-go-dependency",
  "arguments": {
    "package_path": "github.com/gin-gonic/gin",
    "version": "v1.9.1"
  }
}

此提示将指导您完成以下操作:

  1. 首先审查软件包文档
  2. 使用go-mod-get添加依赖关系
  3. 查看go.mod和go.sum的更改
  4. 运行去mod整洁
  5. 验证构建
  6. 依赖关系管理的最佳实践

✅ go代码审查

检查Go代码的清单,包括样式、性能、安全性和最佳实践。

论据:

  • package_path (字符串,可选):要查看的包

使用案例:

  • 代码审查准备
  • 质量保证检查
  • 提交前验证
  • 发布准备

例子:

{
  "name": "go-code-review",
  "arguments": {
    "package_path": "./internal/api"
  }
}

该提示提供了一个全面的检查表,包括:

  1. 代码质量(格式化、linting、错误处理)
  2. 测试(覆盖率、边缘情况、基准测试)
  3. 并发性(竞争条件、同步)
  4. 性能(分配、数据结构)
  5. 文档(注释、示例、自述文件)
  6. 依赖关系(安全性、版本、清理)
  7. 构建和部署(编译、交叉编译)

✅ go服务器部署

构建和部署Go服务器的指南,包括交叉编译、优化和生产最佳实践。

论据:

  • target_os (字符串,可选):目标操作系统:linux、darwin、windows(默认:linux)
  • target_arch (字符串,可选):目标架构:amd64、arm64、386(默认:amd66)

使用案例:

  • 准备生产构建
  • 针对不同平台的交叉编译
  • 设置部署管道
  • 生产服务器配置

示例:

为Linux部署:

{
  "name": "go-server-deployment",
  "arguments": {
    "target_os": "linux",
    "target_arch": "amd64"
  }
}

为macOS ARM部署:

{
  "name": "go-server-deployment",
  "arguments": {
    "target_os": "darwin",
    "target_arch": "arm64"
  }
}

该提示包括:

  1. 部署前测试和验证
  2. 生产构建配置
  3. 交叉编译设置
  4. 安全注意事项
  5. 性能优化
  6. 监控和记录设置
  7. 部署后核查

Usage Examples - Practical examples and workflows

本节提供了实用的、可复制粘贴的示例,演示了常见的工作流程、工具组合和现实场景。

通用开发工作流

快速启动工作流

初始化新项目、格式化代码、运行测试和构建:

{
  "name": "go_mod",
  "arguments": {
    "operation": "init",
    "module_path": "github.com/user/myproject"
  }
}
{
  "name": "go_fmt",
  "arguments": {
    "paths": ["./..."]
  }
}
{
  "name": "go_test",
  "arguments": {
    "verbose": true
  }
}
{
  "name": "go_build",
  "arguments": {
    "output": "myapp"
  }
}

测试工作流程

运行覆盖率和种族检测的全面测试:

{
  "name": "go_test",
  "arguments": {
    "cover": true,
    "cover_pkg": "./...",
    "race": true,
    "verbose": true
  }
}
{
  "name": "go_race_detect",
  "arguments": {
    "package": "./..."
  }
}

性能分析工作流程

基准测试、分析和优化代码:

{
  "name": "go_benchmark",
  "arguments": {
    "pattern": "Benchmark.*",
    "count": 5
  }
}
{
  "name": "go_profile",
  "arguments": {
    "type": "cpu",
    "output": "cpu.prof",
    "duration": "30s",
    "package": "./internal/processor"
  }
}
{
  "name": "go_memory_profile",
  "arguments": {
    "output": "mem.prof",
    "package": "./internal/processor"
  }
}

交叉编译工作流程

为多个平台构建:

{
  "name": "go_cross_compile",
  "arguments": {
    "output": "myapp-linux-amd64",
    "goos": "linux",
    "goarch": "amd64"
  }
}
{
  "name": "go_cross_compile",
  "arguments": {
    "output": "myapp-darwin-arm64",
    "goos": "darwin",
    "goarch": "arm64"
  }
}
{
  "name": "go_cross_compile",
  "arguments": {
    "output": "myapp-windows-amd64.exe",
    "goos": "windows",
    "goarch": "amd64"
  }
}

多工具示例

完整的CI/CD式工作流

格式化、lint、测试和构建带有生产标志:

{
  "name": "go_fmt",
  "arguments": {
    "paths": ["./..."]
  }
}
{
  "name": "go_lint",
  "arguments": {
    "linter": "golangci-lint",
    "package": "./..."
  }
}
{
  "name": "go_test",
  "arguments": {
    "cover": true,
    "cover_pkg": "./...",
    "race": true
  }
}
{
  "name": "go_build",
  "arguments": {
    "output": "myapp",
    "trimpath": true,
    "ldflags": "-X main.version=1.0.0 -X main.buildTime=$(date +%s)"
  }
}

服务器开发工作流程

构建、启动、监视和停止服务器:

{
  "name": "go_build",
  "arguments": {
    "output": "server"
  }
}
{
  "name": "go_server_start",
  "arguments": {
    "id": "api-server",
    "name": "API Server",
    "command": "./server",
    "args": ["--port", "8080"],
    "env_vars": {
      "ENV": "development",
      "LOG_LEVEL": "debug"
    }
  }
}
{
  "name": "go_server_logs",
  "arguments": {
    "id": "api-server",
    "count": 50
  }
}
{
  "name": "go_server_status",
  "arguments": {
    "id": "api-server"
  }
}
{
  "name": "go_server_stop",
  "arguments": {
    "id": "api-server"
  }
}

包装研究工作流程

搜索包、获取文档并提取示例:

{
  "name": "go_pkg_search",
  "arguments": {
    "query": "http router"
  }
}
{
  "name": "go_pkg_docs",
  "arguments": {
    "package": "github.com/gin-gonic/gin"
  }
}
{
  "name": "go_pkg_examples",
  "arguments": {
    "package": "github.com/gin-gonic/gin"
  }
}

集成示例

Claude桌面设置

macOS配置:

{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": [],
      "env": {
        "DISABLE_NOTIFICATIONS": "true",
        "GOPROXY": "https://proxy.golang.org"
      }
    }
  }
}

Windows配置:

{
  "mcpServers": {
    "mcp-go": {
      "command": "C:\\Program Files\\mcp-go\\mcp-go.exe",
      "args": [],
      "env": {
        "DISABLE_NOTIFICATIONS": "true"
      }
    }
  }
}

Linux配置:

{
  "mcpServers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": [],
      "env": {
        "DISABLE_NOTIFICATIONS": "true",
        "GOROOT": "/usr/local/go"
      }
    }
  }
}

故障排除:

  • 验证安装:检查 mcp-go --version 在码头工作
  • 检查权限:确保二进制文件可执行(chmod +x /path/to/mcp-go)
  • 测试连接:配置更改后重新启动Claude Desktop
  • 查看日志:检查Claude Desktop日志中的连接错误

VS代码设置

工作区设置(.vcode/Settings.json):

{
  "mcp.servers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": [],
      "env": {
        "DISABLE_NOTIFICATIONS": "true"
      }
    }
  }
}

用户设置(全局):

{
  "mcp.servers": {
    "mcp-go": {
      "command": "/usr/local/bin/mcp-go",
      "args": []
    }
  }
}

调试提示:

  • 在VS代码设置中启用MCP日志记录
  • 检查MCP服务器消息的输出面板
  • 验证Go环境:确保 go version 在集成终端中工作
  • 测试工具:尝试调用 go_fmtgo_test 验证连接

独立使用

直接测试服务器:

echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}' | mcp-go

JSON-RPC请求示例:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "go_run",
    "arguments": {
      "file": "main.go"
    }
  }
}

JSON-RPC响应示例:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "content": [
      {
        "type": "text",
        "text": "Hello, World!"
      }
    ]
  }
}

现实世界场景

构建REST API

开发和测试REST API的完整工作流程:

{
  "name": "go_pkg_search",
  "arguments": {
    "query": "gin echo fiber"
  }
}
{
  "name": "go_pkg_docs",
  "arguments": {
    "package": "github.com/gin-gonic/gin"
  }
}
{
  "name": "go_mod",
  "arguments": {
    "operation": "get",
    "packages": ["github.com/gin-gonic/gin@latest"]
  }
}
{
  "name": "go_server_start",
  "arguments": {
    "id": "rest-api",
    "name": "REST API Server",
    "command": "go",
    "args": ["run", "main.go"],
    "env_vars": {
      "PORT": "8080",
      "ENV": "development"
    }
  }
}
{
  "name": "go_server_logs",
  "arguments": {
    "id": "rest-api",
    "count": 100
  }
}
{
  "name": "go_profile",
  "arguments": {
    "type": "cpu",
    "output": "api-cpu.prof",
    "duration": "60s"
  }
}
{
  "name": "go_server_stop",
  "arguments": {
    "id": "rest-api"
  }
}

图书馆发展

开发和发布Go库的工作流程:

{
  "name": "go_fmt",
  "arguments": {
    "paths": ["./..."]
  }
}
{
  "name": "go_lint",
  "arguments": {
    "linter": "golangci-lint",
    "package": "./..."
  }
}
{
  "name": "go_test",
  "arguments": {
    "cover": true,
    "cover_pkg": "./...",
    "bench": true
  }
}
{
  "name": "go_benchmark",
  "arguments": {
    "pattern": "Benchmark.*",
    "count": 10
  }
}
{
  "name": "go_doc",
  "arguments": {
    "package": "./...",
    "all": false
  }
}
{
  "name": "go_cross_compile",
  "arguments": {
    "output": "lib-test-linux",
    "goos": "linux",
    "goarch": "amd64"
  }
}

调试性能问题

识别并解决性能瓶颈:

{
  "name": "go_benchmark",
  "arguments": {
    "pattern": "BenchmarkSlowFunction",
    "count": 20
  }
}
{
  "name": "go_profile",
  "arguments": {
    "type": "cpu",
    "output": "slow-cpu.prof",
    "duration": "30s",
    "package": "./internal/slow"
  }
}
{
  "name": "go_trace",
  "arguments": {
    "output": "slow-trace.out",
    "package": "./internal/slow"
  }
}
{
  "name": "go_memory_profile",
  "arguments": {
    "output": "slow-mem.prof",
    "package": "./internal/slow"
  }
}
{
  "name": "go_race_detect",
  "arguments": {
    "package": "./internal/slow"
  }
}

分析后,分析结果:

go tool pprof cpu.prof
go tool trace trace.out
go tool pprof mem.prof

资源使用

资源提供了有关Go工作区的结构化信息。通过MCP资源协议访问它们。

使用go://模块

发现项目依赖关系和模块信息:

访问模式:

Resource URI: go://modules

使用案例:

  • 在添加新包之前了解项目依赖关系
  • 检查模块版本
  • 识别未使用的依赖关系
  • 计划依赖关系更新

工作流程示例:

  1. 访问 go://modules 查看当前依赖关系
  2. 使用 go_pkg_search 寻找替代方案
  3. 使用 go_mod 随着 operation: "get" 添加新包
  4. 使用 go_mod 随着 operation: "tidy" 清理

使用go://build标签

发现构建标签和条件编译:

访问模式:

Resource URI: go://build-tags

使用案例:

  • 理解平台特定代码
  • 查找功能标志
  • 规划交叉汇编
  • 识别条件构建

工作流程示例:

  1. 访问 go://build-tags 查看可用标签
  2. 使用 go_build 随着 tags: ["production", "linux"] 对于特定版本
  3. 使用 go_cross_compile 为平台构建添加适当的标签

使用go://tests

发现测试文件和基准测试:

访问模式:

Resource URI: go://tests

使用案例:

  • 查找项目中的所有测试文件
  • 发现基准函数
  • 规划测试覆盖率改进
  • 了解测试结构

工作流程示例:

  1. 访问 go://tests 查看所有测试文件
  2. 使用 go_test 随着 cover: true 在有保障的情况下跑步
  3. 使用 go_benchmark 运行特定的基准测试
  4. 使用 go_race_detect 检查比赛情况

使用go://workspace

了解项目结构和配置:

访问模式:

Resource URI: go://workspace

使用案例:

  • 了解项目布局
  • 查找主要包
  • 发现模块结构
  • 规划重构

工作流程示例:

  1. 访问 go://workspace 理解结构
  2. 使用 go_build 具有适当的包路径
  3. 使用 go_test 具有特定的包路径
  4. 使用 go_fmt 具有目标路径

使用go://pkg-docs/{path}

直接访问软件包文档:

访问模式:

Resource URI: go://pkg-docs/net/http
Resource URI: go://pkg-docs/github.com/gin-gonic/gin

使用案例:

  • 快速访问标准库文档
  • 查看第三方软件包文档
  • 学习包API
  • 查找使用示例

工作流程示例:

  1. 访问 go://pkg-docs/net/http 对于HTTP包文档
  2. 使用 go_pkg_examples 获取代码示例
  3. 使用 go_doc 用于本地包文档
  4. 将示例集成到代码中

版本示例:

Resource URI: go://pkg-docs/github.com/gin-gonic/gin@v1.9.1

使用go://工具

了解所有可用工具及其功能:

访问模式:

Resource URI: go://tools

使用案例:

  • 从服务器开始时发现可用工具
  • 了解工具参数和模式
  • 为特定任务找到合适的工具
  • 探索工具功能

工作流程示例:

  1. 访问 go://tools 查看所有22个可用工具
  2. 查看工具描述和参数模式
  3. 为您的工作流程选择合适的工具
  4. 组合使用工具完成复杂任务

响应结构示例: 该资源返回一个JSON对象,其中包含:

  • tools:工具元数据数组,包括名称、描述和输入模式
  • count:可用工具总数

使用go://提示

发现指导工作流程的所有可用提示:

访问模式:

Resource URI: go://prompts

使用案例:

  • 查找特定开发任务的提示
  • 理解即时的论点和要求
  • 发现引导式工作流程
  • 规划开发流程

工作流程示例:

  1. 访问 go://prompts 查看所有7个可用提示
  2. 查看提示描述和论点
  3. 在开发阶段使用适当的提示
  4. 将提示与工具相结合,实现完整的工作流程

响应结构示例: 该资源返回一个JSON对象,其中包含:

  • prompts:提示元数据数组,包括名称、描述和参数
  • count:可用提示总数

使用go://资源

发现所有可用资源:

访问模式:

Resource URI: go://resources

使用案例:

  • 了解可用的资源
  • 查找资源URI和描述
  • 规划基于资源的工作流程
  • 发现工作空间发现功能

工作流程示例:

  1. 访问 go://resources 查看所有8个可用资源
  2. 查看资源URI和描述
  3. 使用资源收集工作区信息
  4. 将资源与知情决策工具相结合

响应结构示例: 该资源返回一个JSON对象,其中包含:

  • resources:资源元数据数组,包括URI、名称、描述和MIME类型
  • count:可用资源总数

资源整合示例

完整的项目分析工作流程

  1. 了解项目结构:

- 访问 go://workspace 查看项目布局 - 访问 go://modules 了解依赖关系

  1. 分析代码质量:

- 访问 go://tests 查看测试覆盖率 - 访问 go://build-tags 理解条件编译

  1. 计划改进:

- 访问 go://tools 找到合适的工具 - 访问 go://prompts 用于指导工作流程

  1. 执行改进:

- 使用基于资源洞察的工具 - 遵循结构化工作流的提示

依赖关系管理工作流

  1. 访问 go://modules 查看当前依赖关系
  2. 使用 go_pkg_search 寻找替代方案
  3. 访问 go://pkg-docs/{package} 审查文件
  4. 使用 go_mod 添加依赖项
  5. 访问 go://modules 再次验证更改

测试覆盖率分析工作流程

  1. 访问 go://tests 查看所有测试文件
  2. 使用 go_test 随着 cover: true 获取覆盖报告
  3. 识别测试覆盖率中的差距
  4. 使用 write-go-tests 引导提示
  5. 访问 go://tests 再次验证新的测试

Advanced Patterns - Complex workflows and best practices

在复杂工作流中组合工具

预提交工作流

提交代码前的自动检查:

{
  "name": "go_fmt",
  "arguments": {
    "paths": ["./..."]
  }
}
{
  "name": "go_lint",
  "arguments": {
    "linter": "golangci-lint",
    "package": "./..."
  }
}
{
  "name": "go_test",
  "arguments": {
    "cover": true,
    "race": true
  }
}

发布准备工作流程

准备一个包含多个平台版本的版本:

{
  "name": "go_mod",
  "arguments": {
    "operation": "tidy"
  }
}
{
  "name": "go_test",
  "arguments": {
    "cover": true,
    "cover_pkg": "./..."
  }
}
{
  "name": "go_build",
  "arguments": {
    "output": "myapp",
    "trimpath": true,
    "ldflags": "-X main.version=1.0.0"
  }
}

然后对所有目标平台进行交叉编译。

连续分析工作流程

随时间监控性能:

{
  "name": "go_server_start",
  "arguments": {
    "id": "monitored-server",
    "name": "Monitored Server",
    "command": "go",
    "args": ["run", "main.go"]
  }
}
{
  "name": "go_profile",
  "arguments": {
    "type": "cpu",
    "output": "profile-$(date +%s).prof",
    "duration": "5m"
  }
}

定期检查日志和配置文件,以确定趋势。

使用工具使用资源

依赖关系管理工作流

使用资源通知工具使用情况:

  1. 访问 go://modules 查看当前依赖关系
  2. 使用 go_pkg_search 寻找替代方案
  3. 与...比较 go_pkg_docs 对于每个选项
  4. 使用 go_mod 添加所选包
  5. 访问 go://modules 再次验证

测试驱动开发工作流程

利用资源指导测试:

  1. 访问 go://tests 查看现有的测试结构
  2. 使用 go_test 随着 cover: true 查看覆盖范围差距
  3. 根据覆盖率报告编写新测试
  4. 使用 go_benchmark 确保性能
  5. 访问 go://tests 验证是否包括新的测试

错误处理和故障排除

构建失败

当构建失败时,使用此诊断工作流:

{
  "name": "go_fmt",
  "arguments": {
    "paths": ["./..."]
  }
}
{
  "name": "go_lint",
  "arguments": {
    "package": "./..."
  }
}
{
  "name": "go_mod",
  "arguments": {
    "operation": "tidy"
  }
}
{
  "name": "go_build",
  "arguments": {
    "output": "myapp"
  }
}

测试失败

当测试失败时,系统地调查:

{
  "name": "go_test",
  "arguments": {
    "verbose": true,
    "package": "./internal/failing"
  }
}
{
  "name": "go_race_detect",
  "arguments": {
    "package": "./internal/failing"
  }
}
{
  "name": "go_trace",
  "arguments": {
    "output": "test-trace.out",
    "package": "./internal/failing"
  }
}

服务器问题

当服务器出现意外行为时:

{
  "name": "go_server_status",
  "arguments": {
    "id": "problematic-server"
  }
}
{
  "name": "go_server_logs",
  "arguments": {
    "id": "problematic-server",
    "count": 0
  }
}
{
  "name": "go_profile",
  "arguments": {
    "type": "mem",
    "output": "server-mem.prof",
    "duration": "60s"
  }
}

最佳实践

为了发展

  • 使用 go_fmt 每次提交之前
  • go_test 随着 race: true 用于并发代码
  • 使用 go_lint 定期及早发现问题
  • 访问 go://workspace 了解项目结构

生产环境

  • 总是使用 trimpath: true 在构建中
  • 通过以下方式包含版本信息 ldflags
  • 测试用 go_race_detect 发布前
  • 在目标平台上进行交叉编译和测试

性能方面

  • 优化前后的基准测试
  • 具有实际工作负载的配置文件
  • 使用 go_trace 对于并发问题
  • 监控内存配置文件是否泄漏

用于包管理

  • 使用 go://modules 了解依赖关系
  • 添加前搜索包(go_pkg_search)
  • 审阅文档(go_pkg_docs)整合前
  • 使用 go_mod tidy 定期清理

安全注意事项

  • 所有命令执行都需要用户权限(除非 DISABLE_NOTIFICATIONS=true)
  • 命令以与MCP服务器进程相同的权限运行
  • 命令验证可防止注入攻击
  • 权限系统可以使用系统通知或控制台提示

许可证

此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。

贡献

欢迎投稿!请随时提交拉取请求。

更新日志

更改日志.md 版本历史。

目录标签

目录标签

代码执行GoClaude性能优化Go开发本地部署AI编程助手服务器管理

支持客户端

Claude DesktopClaudeCursorWindsurfClineVS Code

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

none

运行时(runtime,运行环境)

Docker

工具数量(toolCount,工具数)

22

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdionone部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP