Description:

The current implementation of the gopls MCP server (https://tip.golang.org/gopls/features/mcp) presents challenges when working with multiple workspaces in environments like VS Code. Specifically, managing the MCP port (-mcp.listen) is cumbersome, and there is no seamless way to configure it for both shared and standalone gopls instances.


Problem:

  1. Random MCP Port:
  2. When using -mcp.listen=localhost:0, the MCP server assigns a random port. This makes it difficult to pin down the port for use in the mcp.json file or other tools that rely on a static MCP endpoint.
  3. Dynamically updating the mcp.json file to reflect the random port is non-trivial.

  4. Fixed MCP Port:

  5. Using a fixed MCP port allows for per-workspace configurations, but this requires manual setup for each workspace. This is not ideal for users who want a more automated solution.

  6. Shared gopls Daemon:

  7. A shared gopls daemon with -mcp.listen and -remote flags is a viable solution. However, the -remote=auto flag does not currently support forwarding the -mcp.listen flag to the shared daemon. This makes it impossible to configure the MCP port for the shared daemon in an automated way.

Proposed Solutions:

  1. Enhance -remote=auto:
  2. Allow the -remote=auto flag to forward the -mcp.listen flag (or other arbitrary flags) to the shared gopls daemon. This would enable users to configure the MCP port for the shared daemon seamlessly.