Gopls-mcp is a Model Context Protocol (MCP) server that integrates gopls (Go language server) with MCP-compatible hosts like Claude Code, Claude Desktop, and VS Code. It provides comprehensive Go development tools through the MCP protocol, enabling powerful Go development assistance in AI-powered coding environments.
The easiest way to use gopls-mcp is with Claude Code using Streamable HTTP transport:
Start the server with your Go workspace(s):
# Single workspace using Docker (recommended)
docker run -d -v /path/to/your/go/project:/workspace -p 8080:8080 megagrindstone/gopls-mcp:latest
# Multiple workspaces using Docker
docker run -d \
-v /path/to/project1:/workspace1 \
-v /path/to/project2:/workspace2 \
-v /path/to/project3:/workspace3 \
-p 8080:8080 \
megagrindstone/gopls-mcp:latest -workspace /workspace1,/workspace2,/workspace3
# Or build from source (single workspace)
go build -o gopls-mcp
./gopls-mcp -workspace /path/to/your/go/project
# Multiple workspaces from source
./gopls-mcp -workspace /path/to/project1,/path/to/project2,/path/to/project3
Add to Claude Code:
claude mcp add --transport http gopls-mcp http://localhost:8080
Start using - The Go tools will be available in your Claude Code conversations!
For Claude Desktop, add this to your MCP settings:
{
"mcpServers": {
"gopls-mcp": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"-v", "/path/to/your/go/project:/workspace",
"-p", "8080:8080",
"megagrindstone/gopls-mcp:latest"
]
}
}
}
{
"mcpServers": {
"gopls-mcp": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"-v", "/path/to/project1:/workspace1",
"-v", "/path/to/project2:/workspace2",
"-v", "/path/to/project3:/workspace3",
"-p", "8080:8080",
"megagrindstone/gopls-mcp:latest",
"-workspace", "/workspace1,/workspace2,/workspace3"
]
}
}
}
For VS Code and other MCP hosts, use the Streamable HTTP transport:
{
"servers": {
"gopls-mcp": {
"type": "http",
"url": "http://localhost:8080"
}
}
}
go.mod
fileClone or download a Go project to work with
Start gopls-mcp server:
docker run -d -v $(pwd):/workspace -p 8080:8080 megagrindstone/gopls-mcp:latest
Integrate with Claude Code:
claude mcp add --transport http gopls-mcp http://localhost:8080
Test the integration - Ask Claude Code to help with your Go code!
Once integrated, you can use these tools naturally in your conversations. With multi-workspace support, you can work across multiple Go projects simultaneously:
"What workspaces are available?"
"List all configured Go projects"
"Where is the `ProcessRequest` function defined in project1?"
"Show me all places where `UserService` is used across all workspaces"
"What does the `http.Client` struct contain?"
"Are there any compilation errors in main.go?"
"Show me all functions and types defined in client.go"
"Find all symbols named 'Handler' across the workspace"
"What parameters does the `log.Printf` function take?"
"Show me code completion suggestions for this position"
"What's the type definition of this variable?"
"Find all implementations of the Writer interface"
"Format this Go file according to gofmt standards"
"Clean up and organize the imports in this file"
"Show me type hints for this code range"
-workspace
(required): Path(s) to your Go workspace directory(ies)
-workspace /path/to/project
-workspace /project1,/project2,/project3
-workspace "/path with spaces/project1,/project2"
⚠️ Memory Usage Notice: Each workspace uses approximately 300MB of RAM as it runs a dedicated gopls process. When using multiple workspaces, plan accordingly:
-transport
(optional): Transport type, accepts 'http' or 'stdio' (defaults to 'http')
Port: Fixed at 8080 (Streamable HTTP transport only)
# Single workspace with Streamable HTTP transport (default)
./gopls-mcp -workspace /path/to/go/project
./gopls-mcp -workspace /path/to/go/project -transport http
# Multiple workspaces with Streamable HTTP transport
./gopls-mcp -workspace /project1,/project2,/project3
./gopls-mcp -workspace /project1,/project2 -transport http
# Docker with single workspace (Streamable HTTP transport)
docker run -v /path/to/go/project:/workspace -p 8080:8080 megagrindstone/gopls-mcp:latest
# Docker with multiple workspaces (Streamable HTTP transport)
docker run \
-v /project1:/workspace1 \
-v /project2:/workspace2 \
-v /project3:/workspace3 \
-p 8080:8080 \
megagrindstone/gopls-mcp:latest -workspace /workspace1,/workspace2,/workspace3
# Single workspace with stdio transport
./gopls-mcp -workspace /path/to/go/project -transport stdio
# Multiple workspaces with stdio transport
./gopls-mcp -workspace /project1,/project2,/project3 -transport stdio
# Docker with single workspace (stdio transport)
docker run -i -v /path/to/go/project:/workspace megagrindstone/gopls-mcp:latest -transport stdio
# Docker with multiple workspaces (stdio transport)
docker run -i \
-v /project1:/workspace1 \
-v /project2:/workspace2 \
-v /project3:/workspace3 \
megagrindstone/gopls-mcp:latest -workspace /workspace1,/workspace2,/workspace3 -transport stdio
For Claude Desktop with stdio transport:
{
"mcpServers": {
"gopls-mcp": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"-v", "/path/to/your/go/project:/workspace",
"megagrindstone/gopls-mcp:latest",
"-transport", "stdio"
]
}
}
}
The server supports structured logging with configurable levels and formats via environment variables:
LOG_LEVEL
: Set logging level (DEBUG, INFO, WARN, ERROR) - defaults to INFOLOG_FORMAT
: Set log output format (text, json) - defaults to text# Native with custom logging
LOG_LEVEL=DEBUG ./gopls-mcp -workspace /path/to/go/project
LOG_FORMAT=json LOG_LEVEL=WARN ./gopls-mcp -workspace /path/to/go/project
# Docker with logging configuration
docker run -e LOG_LEVEL=DEBUG -v /path/to/go/project:/workspace -p 8080:8080 megagrindstone/gopls-mcp:latest
docker run -e LOG_FORMAT=json -e LOG_LEVEL=INFO -v /path/to/go/project:/workspace -p 8080:8080 megagrindstone/gopls-mcp:latest
Your Go workspace must contain:
go.mod
fileThe server will automatically initialize gopls with your workspace and maintain the language server connection throughout the session.
Pre-built Docker images are available on Docker Hub with multi-platform support:
# Latest stable release
docker pull megagrindstone/gopls-mcp:latest
# Specific version
docker pull megagrindstone/gopls-mcp:v0.3.0
# Run with single Go project
docker run -v /path/to/go/project:/workspace -p 8080:8080 megagrindstone/gopls-mcp:latest
# Run with multiple Go projects
docker run \
-v /path/to/project1:/workspace1 \
-v /path/to/project2:/workspace2 \
-v /path/to/project3:/workspace3 \
-p 8080:8080 \
megagrindstone/gopls-mcp:latest -workspace /workspace1,/workspace2,/workspace3
latest
- Latest stable releasev*
- Semantic version tags (e.g., v0.3.0
)main
- Latest development buildDocker images support:
linux/amd64
- Intel/AMD 64-bitlinux/arm64
- ARM 64-bit (Apple Silicon, ARM servers)"workspace flag is required"
-workspace
flag when running the server"Failed to start gopls"
go.mod
file"Connection refused"
http://localhost:8080
To debug issues, run the server with verbose logging:
# Native with debug logging
LOG_LEVEL=DEBUG ./gopls-mcp -workspace /path/to/project
# Docker with debug logging (Streamable HTTP)
docker run -e LOG_LEVEL=DEBUG -v /path/to/project:/workspace -p 8080:8080 megagrindstone/gopls-mcp:latest
# View Docker container logs
docker logs <container-id>
# JSON format logging for easier parsing
docker run -e LOG_FORMAT=json -e LOG_LEVEL=DEBUG -v /path/to/project:/workspace -p 8080:8080 megagrindstone/gopls-mcp:latest
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "gopls-mcp" '{"command":"docker","args":["run","-i","--rm","-v","/path/to/your/go/project:/workspace","-p","8080:8080","megagrindstone/gopls-mcp:latest"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"gopls-mcp": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-v",
"/path/to/your/go/project:/workspace",
"-p",
"8080:8080",
"megagrindstone/gopls-mcp:latest"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"gopls-mcp": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-v",
"/path/to/your/go/project:/workspace",
"-p",
"8080:8080",
"megagrindstone/gopls-mcp:latest"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect