|
1 | 1 | The Go team recently added an official [Model Context Protocol (MCP) server to `gopls`](https://tip.golang.org/gopls/features/mcp), the language server protocol (LSP) implementation for Go. This allows IDEs and other AI coding agents to directly access some features of the LSP. While most of the features provided by the MCP already exist in AI coding tools, this can improve the efficiency of token use by avoiding searching and reading whole files. |
2 | 2 |
|
3 | | -### Why MCP? |
4 | | - |
5 | | -One of the most impactful features is the ability to use the `go_diagnostics` tool. Besides the usual information about diagnostic issues, this also allows the agent to automatically review and apply fixes suggested by the LSP. This greatly improves consistency and accuracy of code fixes since it uses deterministic analysis provided directly by the Go maintainers. |
6 | | - |
7 | | -If you are regularly programming with newer versions of Go, you might be familiar with the "modernize" suggestions. I mostly-commonly see these with typical `for i := 0; i < 10; i++` loops that could use the new `for i := range 10` syntax. This feature is a big win for the language in the world of AI coding. By definition, LLMs always output "old" code since they are trained on existing codebases. This means any new language features won't be used by LLMs until enough human coders have introduced them into the training data. |
8 | | - |
9 | | -The new [analyze and modernize](https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize) tools allow coding agents to automatically update to new language features that they don't even know about yet. This improves the overall quality of a codebase even when using AI agents. This is an important feature helping to keep Go relevant as software development is rapidly changing. |
10 | | - |
11 | | - |
12 | 3 | ## Enable gopls MCP in VS Code |
13 | 4 |
|
14 | 5 | Now, let's get to the reason you're here! With a few simple steps, we can start using this new MCP feature in VS Code: |
@@ -76,7 +67,15 @@ The simplest place to start is to ask about references for a function or type in |
76 | 67 |
|
77 | 68 | This should use the `go_symbol_references` tool to find references to this function. |
78 | 69 |
|
79 | | -A more interesting example uses the `go_diagnostics` tool that I mentioned earlier. To do this, write a simple function using a for loop: |
| 70 | +### Why MCP? |
| 71 | +
|
| 72 | +One of the most impactful features is the ability to use the `go_diagnostics` tool. Besides the usual information about diagnostic issues, this also allows the agent to automatically review and apply fixes suggested by the LSP. This greatly improves consistency and accuracy of code fixes since it uses deterministic analysis provided directly by the Go maintainers. |
| 73 | +
|
| 74 | +If you are regularly programming with newer versions of Go, you might be familiar with the "modernize" suggestions. I mostly-commonly see these with typical `for i := 0; i < 10; i++` loops that could use the new `for i := range 10` syntax. This feature is a big win for the language in the world of AI coding. By definition, LLMs always output "old" code since they are trained on existing codebases. This means any new language features won't be used by LLMs until enough human coders have introduced them into the training data. |
| 75 | +
|
| 76 | +The new [analyze and modernize](https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize) tools allow coding agents to automatically update to new language features that they don't even know about yet. This improves the overall quality of a codebase even when using AI agents. This is an important feature helping to keep Go relevant as software development is rapidly changing. |
| 77 | +
|
| 78 | +To demonstrate this tool, write a simple function using a for loop: |
80 | 79 |
|
81 | 80 | ```go |
82 | 81 | func Example() { |
|
0 commit comments