Verified Solution

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

Sponsored Content
### ROOT CAUSE The issue arises because the built-in MCP server in `gopls` does not have a mechanism to accept configuration settings, unlike the standard LSP server. This prevents users from applying the same settings (e.g., `env`, `directoryFilters`) to the MCP server, which is necessary for consistency with the LSP server and client editors like VS Code. ### CODE FIX Modify the `gopls` binary to load and pass the configuration settings to the MCP server when it is started. Specifically, update the `gopls` main package to: 1. Load the configuration settings (using the existing `loadConfig` function) and store them in a variable. 2. Pass the configuration to the MCP server's `Serve` function. Here's the fix: ```go // In gopls/main.go, modify the main function to load the configuration and pass it to the MCP server. func main() { // ... existing code to parse flags and set up context ... // Load the configuration cfg, err := loadConfig(context.Background(), settings, nil) if err != nil { log.Fatal(err) } // ... existing code to start the LSP server ... // Start the MCP server with the loaded configuration if mcpAddr != "" { mcp.Serve(mcpAddr, cfg, log.Default()) } } ``` This change ensures the MCP server uses the same configuration as the LSP server, allowing settings like `env` and `directoryFilters` to be applied consistently.
Deploy on DigitalOcean ($200 Credit)

Related Fixes

[pytorch/pytorch] torch.compile error in unit tests, but test passes when ran individually
[pytorch/pytorch] something regressed torchbench graph breaks
[golang/go] x/build/cmd/relui: automate process of upstreaming private-track security CLs on release day (for the main branch)