← Back to Dashboard
Verified Production Fix

[golang/go] x/tools/gopls: add a way to provide gopls settings for the built-in MCP server

GH-golang/go#77960 • Mar 07, 2026

### ROOT CAUSE The issue arises because the current implementation of the built-in MCP server in `gopls` does not provide a mechanism to apply user-defined settings. The `gopls` tool allows configuration via a JSON file or command-line flags, but the MCP server, which is part of `gopls`, does not expose these settings through standard editor interfaces like VS Code. This limits the ability to customize the MCP server's behavior as needed. ### CODE FIX To address this, we can modify `gopls` to accept a new flag `--mcp-settings` that takes a JSON string representing the MCP server settings. Additionally, we'll update the MCP server to read these settings when initializing. Here are the necessary code changes: 1. **Update `gopls` to accept `--mcp-settings` flag:**

   func main() {
       // ...
       mcpSettingsFlag := flag.String("mcp-settings", "", "JSON string of MCP server settings")
       // ...
       mcpSettings, err := ParseMCPSettings(*mcpSettingsFlag)
       if err != nil {
           fmt.Fprintf(os.Stderr, "failed to parse mcp settings: %v\n", err)
           os.Exit(1)
       }
       // ...
       server, err := NewServer(new(stdinStdout), nil, mcpSettings)
       // ...
   }

   func ParseMCPSettings(settings string) (map[string]interface{}, error) {
       if settings == "" {
           return nil, nil
       }
       return json.Decode([]byte(settings))
   }
   


2. **Modify the MCP server to use these settings:**
   

   type Server struct {
       // ...
       settings map[string]interface{}
   }

   func NewServer(rw io.ReadWriter, settings map[string]interface{}, mcpSettings map[string]interface{}) (*Server, error) {
       // ...
       return &Server{
           // ...
           settings: mcpSettings,
       }, nil
   }
   


3. **Update the VS Code extension to pass MCP settings:**
   - Modify the extension's `configuration.ts` to include a new setting for MCP.
   - Update the `activate` function to read the MCP settings and pass them via the `--mcp-settings` flag when starting `gopls`.

4. **Add documentation to inform users about the new `--mcp-settings` flag and how to configure it.

**Note:** This fix assumes that the MCP server's configuration can be extended with additional settings. If the MCP server is tightly coupled with `gopls` and cannot accept external settings, further modifications may be needed.

Deploy with DigitalOcean

Use this fix in production instantly. Claim your $200 developer credit.

Get Started →