gopls MCP server

Integrates with gopls to provide Go language server capabilities including go-to-definition, find references, hover information, document symbols, workspace symbols, type definitions, and workspace status monitoring across multiple Go workspaces simultaneously.
Back to servers
Setup instructions
Provider
Gerard Adam
Release date
Jul 06, 2025
Language
Go
Stats
1 star

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.

Installation

Claude Code Integration (Recommended)

The easiest way to use gopls-mcp is with Claude Code using Streamable HTTP transport:

  1. 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
    
  2. Add to Claude Code:

    claude mcp add --transport http gopls-mcp http://localhost:8080
    
  3. Start using - The Go tools will be available in your Claude Code conversations!

Claude Desktop Integration

For Claude Desktop, add this to your MCP settings:

Single Workspace

{
  "mcpServers": {
    "gopls-mcp": {
      "command": "docker",
      "args": [
        "run", "-i", "--rm",
        "-v", "/path/to/your/go/project:/workspace",
        "-p", "8080:8080",
        "megagrindstone/gopls-mcp:latest"
      ]
    }
  }
}

Multiple Workspaces

{
  "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"
      ]
    }
  }
}

Other MCP Hosts

For VS Code and other MCP hosts, use the Streamable HTTP transport:

{
  "servers": {
    "gopls-mcp": {
      "type": "http",
      "url": "http://localhost:8080"
    }
  }
}

Quick Start

Prerequisites

  • Go workspace with valid go.mod file
  • Docker (recommended) or Go 1.24+ installed

Step-by-Step Setup

  1. Clone or download a Go project to work with

  2. Start gopls-mcp server:

    docker run -d -v $(pwd):/workspace -p 8080:8080 megagrindstone/gopls-mcp:latest
    
  3. Integrate with Claude Code:

    claude mcp add --transport http gopls-mcp http://localhost:8080
    
  4. Test the integration - Ask Claude Code to help with your Go code!

Usage Examples

Once integrated, you can use these tools naturally in your conversations. With multi-workspace support, you can work across multiple Go projects simultaneously:

Workspace Management

"What workspaces are available?"
"List all configured Go projects"

Core Navigation Tools

"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?"

Diagnostic and Analysis Tools

"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"

Code Assistance Tools

"What parameters does the `log.Printf` function take?"
"Show me code completion suggestions for this position"

Advanced Navigation Tools

"What's the type definition of this variable?"
"Find all implementations of the Writer interface"

Code Maintenance Tools

"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"

Configuration

Server Options

  • -workspace (required): Path(s) to your Go workspace directory(ies)

    • Single workspace: -workspace /path/to/project
    • Multiple workspaces: -workspace /project1,/project2,/project3
    • Supports spaces in paths: -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:

    • 1 workspace: ~300MB RAM
    • 5 workspaces: ~1.5GB RAM
    • 10 workspaces: ~3GB RAM
  • -transport (optional): Transport type, accepts 'http' or 'stdio' (defaults to 'http')

  • Port: Fixed at 8080 (Streamable HTTP transport only)

Transport Options

Streamable HTTP Transport (Default)

# 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

Stdio Transport

# 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"
      ]
    }
  }
}

Logging Configuration

The server supports structured logging with configurable levels and formats via environment variables:

Environment Variables

  • LOG_LEVEL: Set logging level (DEBUG, INFO, WARN, ERROR) - defaults to INFO
  • LOG_FORMAT: Set log output format (text, json) - defaults to text

Usage Examples

# 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

Workspace Requirements

Your Go workspace must contain:

  • Valid go.mod file
  • Proper Go module structure
  • Accessible Go source files

The server will automatically initialize gopls with your workspace and maintain the language server connection throughout the session.

Docker Deployment

Using Docker Hub Images

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

Available Tags

  • latest - Latest stable release
  • v* - Semantic version tags (e.g., v0.3.0)
  • main - Latest development build

Multi-Platform Support

Docker images support:

  • linux/amd64 - Intel/AMD 64-bit
  • linux/arm64 - ARM 64-bit (Apple Silicon, ARM servers)

Troubleshooting

Common Issues

"workspace flag is required"

  • Ensure you provide the -workspace flag when running the server
  • The workspace path must contain a valid Go module

"Failed to start gopls"

  • Check that gopls is available in your PATH (automatically handled in Docker)
  • Ensure your Go workspace has a valid go.mod file
  • Verify the workspace path is accessible

"Connection refused"

  • Ensure the server is running on port 8080
  • Check that no other service is using the port
  • Verify the MCP server is accessible at http://localhost:8080

Debug Mode

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

How to install this MCP server

For Claude Code

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.

For Cursor

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.

Adding an MCP server to Cursor globally

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"
            ]
        }
    }
}

Adding an MCP server to a project

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.

How to use the MCP server

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.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.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

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later