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:
- Use LSP to analyze Go code with minimal context usage
- Navigate to definitions and find references instantly
- Check code diagnostics without running builds
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).
- LSP Integration: Connection to Go's Language Server Protocol for code analysis
- Code Navigation: Finding definitions and references in the code
- Code Quality: Getting diagnostics and errors in real-time
.
├── 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 featuresgo install github.com/solatis/mcp-gopls/cmd/mcp-gopls@latest{
"mcpServers": {
"mcp-gopls": {
"command": "mcp-gopls"
}
}
} The MCP server provides the following LSP-powered tools for efficient Go code analysis:
| Tool | Description |
|---|---|
go_to_definition |
Navigate instantly to where any symbol (function, type, variable) is defined. Much faster and more accurate than text search. |
find_references |
Find all usages of a symbol across the entire codebase. Essential for understanding code impact before making changes. |
check_diagnostics |
Get all compile errors, type errors, and linting issues without running builds. The fastest way to verify code correctness. |
document_symbol |
Get a complete hierarchical outline of all symbols in a file. 10-100x faster than reading the entire file. |
workspace_symbol |
Search for any symbol across the entire project instantly. Supports fuzzy matching and understands Go syntax. |
list_interface_implementation |
Find all types that implement an interface, or find which interface a method implements. Critical for Go's interface-based design. |
Using the server with AI assistants that support MCP:
# Navigate to definitions instantly
Where is the ServeStdio function defined?
# Find all usages efficiently
Show me everywhere the Context type is used in this project
# Check for errors without building
Are there any errors in my main.go file?
# Understand code structure
What's the structure of the server.go file?
# Search across the project
Where is the MCPServer type defined in this codebase?
# Understand interfaces
What types implement the LSPClient interface?- Reduced Token Usage: LSP tools provide precise results without reading entire files
- Better Accuracy: Understands Go's type system, imports, and syntax
- Faster Analysis: Instant results compared to multiple grep/search operations
- Lower Costs: Less context means fewer tokens and reduced API costs
git clone https://github.com/solatis/mcp-gopls.git
cd mcp-gopls
go mod tidy
go build -o mcp-gopls cmd/mcp-gopls/main.go
./mcp-gopls- Go 1.21 or higher
- gopls installed (
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:
- Make sure Ollama is running
- The MCP server runs independently and communicates through stdin/stdout
- Configure your client to use the MCP server as a tool provider
Apache License 2.0