mcp-gopls

by hloiseaufcms
Verified
Apache 2.0

MCP LSP 转到

模型上下文协议 (MCP) 服务器允许像 Claude 这样的 AI 助手与 Go 的语言服务器协议 (LSP) 交互并受益于高级 Go 代码分析功能。

概述

该 MCP 服务器可帮助 AI 助手:

  • 使用 LSP 分析 Go 代码
  • 导航至定义并查找参考
  • 检查代码诊断
  • 获取符号的悬停信息
  • 获取完成建议

建筑学

该项目使用mark3labs/mcp-go库实现模型上下文协议 (MCP)。MCP 集成实现了 AI 助手与 Go 工具之间的无缝通信。

该服务器通过语言服务器协议(LSP)与 Go 的官方语言服务器gopls进行通信。

特征

  • LSP 集成:连接到 Go 的语言服务器协议进行代码分析
  • 代码导航:在代码中查找定义和引用
  • 代码质量:获取诊断和错误
  • 高级信息:悬停信息和完成建议

项目结构

. ├── cmd │ └── mcp-gopls # Application entry point ├── pkg │ ├── lsp # LSP client to communicate with gopls │ │ ├── client # LSP client implementation │ │ └── protocol # LSP protocol types and features │ ├── server # MCP server │ └── tools # MCP tools exposing LSP features

安装

go install github.com/hloiseaufcms/mcp-gopls/cmd/mcp-gopls@latest

添加到光标

{ "mcpServers": { "mcp-gopls": { "command": "mcp-gopls" } } }

MCP 工具

MCP 服务器提供以下工具:

工具描述
go_to_definition导航到符号的定义
find_references查找对符号的所有引用
check_diagnostics获取文件诊断信息
get_hover_info获取有关符号的详细信息
get_completion获取某个位置的完成建议
analyze_coverage分析 Go 代码的测试覆盖率

使用示例

将服务器与支持 MCP 的 AI 助手一起使用:

# Ask the AI to get information about the code Can you find the definition of the `ServeStdio` function in this project? # Ask for diagnostics Are there any errors in my main.go file? # Ask for information about a symbol What does the Context.WithTimeout function do in Go?

发展

git clone https://github.com/hloiseaufcms/mcp-gopls.git cd mcp-gopls go mod tidy go build -o mcp-gopls cmd/mcp-gopls/main.go ./mcp-gopls

先决条件

  • Go 1.24 或更高版本
  • gopls 已安装( go install golang.org/x/tools/gopls@latest

执照

Apache 许可证 2.0

-
security - not tested
-
license - not tested
-
quality - not tested

模型上下文协议 (MCP) 服务器允许像 Claude 这样的 AI 助手与 Go 的语言服务器协议 (LSP) 交互并受益于高级 Go 代码分析功能。

  1. Overview
    1. Architecture
      1. Features
        1. Project Structure
          1. Installation
            1. Add to Cursor
              1. MCP Tools
                1. Usage Example
                  1. Development
                    1. Prerequisites
                      1. License
                        ID: 0r1utyven9