Get the FREE Ultimate OpenClaw Setup Guide →

mcp-gopls

Model Context Protocol (MCP) server for Go using gopls – LSP-powered analysis, tests, coverage, and tooling.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio hloiseau-mcp-gopls mcp-gopls --workspace /absolute/path/to/your/go/project \
  --env MCP_GOPLS_LOG_LEVEL="info"

How to use

mcp-gopls exposes Go tooling through the MCP protocol by wrapping the gopls language server in an MCP server. With this server, AI assistants can perform go-to-definition, find references, show diagnostics, hover information, code completion, formatting, renaming, and code actions directly through MCP tools. It also provides Go-specific tooling like running tests, generating coverage, tidying go.mod, and performing vulnerability checks, all with structured results suitable for chat-based workflows. To use it, run the server with a workspace path pointing at your Go project and connect an MCP client (Cursor, Claude, Copilot, or another client) to issue the available MCP tools such as go_to_definition, find_references, check_diagnostics, get_hover_info, get_completion, format_document, rename_symbol, list_code_actions, run_go_test, analyze_coverage, run_go_mod_tidy, and run_govulncheck. The server will communicate with gopls via LSP and surface results in the MCP format.

How to install

Prerequisites:

  • Go installed (1.20+ recommended)
  • Access to the internet to fetch modules and binaries

Step-by-step:

  1. Install the MCP server binary (example using the published module):
    • go install github.com/hloiseau/mcp-gopls/v2/cmd/mcp-gopls@latest
  2. Verify installation:
    • mcp-gopls --help
  3. Run the MCP server pointing to your Go workspace:
    • mcp-gopls --workspace /absolute/path/to/your/go/project
  4. (Optional) Set up an MCP client configuration (e.g., Cursor) to connect to the server using the same workspace path.

If you prefer containerized usage, see the Docker guidance in the README for running mcp-gopls inside a container and mounting your workspace.

Additional notes

Tips and notes:

  • Environment variables supported by the server include MCP_GOPLS_LOG_LEVEL to control logging verbosity. Use values like info, debug, warn, error as needed.
  • The --workspace flag determines the Go workspace the server analyzes; ensure your path points to the root of your Go module or workspace.
  • For best performance, mount a local Go module workspace into the container (if using Docker) or run natively where the workspace resides.
  • If you update gopls or your Go module, restart the MCP server to reload state.
  • Use the provided MCP tools list to discover capabilities; the server supports extended LSP features via tools such as go_to_definition, get_hover_info, get_completion, and more, along with Go tooling like run_go_test and analyze_coverage.
  • When integrating with clients, ensure the client uses the same workspace path and passes any necessary environment configurations to replicate local behavior.

Related MCP Servers

Sponsor this space

Reach thousands of developers