A Model Context Protocol (MCP) server that allows AI assistants like Claude to interact with Go's Language Server Protocol (LSP) and benefit from advanced Go code analysis features.
A Model Context Protocol (MCP) server that allows AI assistants like Claude to interact with Go's Language Server Protocol (LSP) and benefit from advanced Go code analysis features.
This MCP server helps AI assistants to:
This project uses the mark3labs/mcp-go library to implement the Model Context Protocol. The MCP integration enables seamless communication between AI assistants and Go tools.
The server communicates with gopls, the official language server for Go, via the Language Server Protocol (LSP).
.
├── 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"
}
}
}
The MCP server provides the following tools:
Tool | Description |
---|---|
go_to_definition | Navigate to the definition of a symbol |
find_references | Find all references to a symbol |
check_diagnostics | Get diagnostics for a file |
get_hover_info | Get detailed information about a symbol |
get_completion | Get completion suggestions at a position |
analyze_coverage | Analyze test coverage for Go code |
Using the server with AI assistants that support MCP:
# 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 install golang.org/x/tools/gopls@latest
)This MCP server can be used with any tool that supports the MCP protocol. For Ollama integration:
Apache License 2.0