Skip to content

Commit 406c179

Browse files
madelinekalilgopherbot
authored andcommitted
gopls/internal/cmd: implement counters for mcp server
Adds three new counters for tracking usage of the Go MCP Server that increment when a user starts up the server in attached or headless mode. For golang/go#74291 Change-Id: Ifa324f1151371aac68f1cde63f0d7966a95e97dd Reviewed-on: https://go-review.googlesource.com/c/tools/+/683315 Auto-Submit: Madeline Kalil <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 55b751a commit 406c179

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

gopls/internal/cmd/counters.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2025 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package cmd
6+
7+
import "golang.org/x/telemetry/counter"
8+
9+
// Proposed counters for evaluating usage of the Go MCP Server. These counters
10+
// increment when the user starts up the server in attached or headless mode.
11+
var (
12+
countHeadlessMCPStdIO = counter.New("gopls/mcp-headless:stdio")
13+
countHeadlessMCPSSE = counter.New("gopls/mcp-headless:sse")
14+
countAttachedMCP = counter.New("gopls/mcp")
15+
)

gopls/internal/cmd/mcp.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func (m *headlessMCP) Run(ctx context.Context, args ...string) error {
4747

4848
// Send a SessionStart event to trigger creation of an http handler.
4949
if m.Address != "" {
50+
countHeadlessMCPSSE.Inc()
5051
// Specify a channel size of two so that the send operations are
5152
// non-blocking.
5253
eventChan := make(chan lsprpc.SessionEvent, 2)
@@ -65,6 +66,7 @@ func (m *headlessMCP) Run(ctx context.Context, args ...string) error {
6566

6667
return mcp.Serve(ctx, m.Address, eventChan, false)
6768
} else {
69+
countHeadlessMCPStdIO.Inc()
6870
return mcp.StartStdIO(ctx, sess)
6971
}
7072
}

gopls/internal/cmd/serve.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func (s *Serve) Run(ctx context.Context, args ...string) error {
126126

127127
// Start MCP server.
128128
if eventChan != nil {
129+
countAttachedMCP.Inc()
129130
group.Go(func() (err error) {
130131
defer func() {
131132
if err == nil {

0 commit comments

Comments
 (0)