Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c312a17

Browse files
internal/mcp: add telemetry for MCP tool usage
- add new counters for MCP tool usage. Fixes golang/go#75448 Change-Id: I966efe12da4432f00b00d9eb2c68b1ea4d6e8140 Reviewed-on: https://go-review.googlesource.com/c/tools/+/703358 Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 7b45cae commit c312a17

12 files changed

+34
-0
lines changed

gopls/internal/mcp/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type ContextParams struct {
3232
}
3333

3434
func (h *handler) contextHandler(ctx context.Context, req *mcp.CallToolRequest, params ContextParams) (*mcp.CallToolResult, any, error) {
35+
countGoContextMCP.Inc()
3536
fh, snapshot, release, err := h.fileOf(ctx, params.File)
3637
if err != nil {
3738
return nil, nil, err

gopls/internal/mcp/counters.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 mcp
6+
7+
import "golang.org/x/telemetry/counter"
8+
9+
// Proposed counters for evaluating usage of Go MCP Server tools. These counters
10+
// increment when a user utilizes a specific Go MCP tool.
11+
var (
12+
countGoContextMCP = counter.New("gopls/mcp-tool:go_context")
13+
countGoDiagnosticsMCP = counter.New("gopls/mcp-tool:go_diagnostics")
14+
countGoFileContextMCP = counter.New("gopls/mcp-tool:go_file_context")
15+
countGoFileDiagnosticsMCP = counter.New("gopls/mcp-tool:go_file_diagnostics")
16+
countGoFileMetadataMCP = counter.New("gopls/mcp-tool:go_file_metadata")
17+
countGoPackageAPIMCP = counter.New("gopls/mcp-tool:go_package_api")
18+
countGoReferencesMCP = counter.New("gopls/mcp-tool:go_references")
19+
countGoSearchMCP = counter.New("gopls/mcp-tool:go_search")
20+
countGoSymbolReferencesMCP = counter.New("gopls/mcp-tool:go_symbol_references")
21+
countGoWorkspaceMCP = counter.New("gopls/mcp-tool:go_workspace")
22+
countGoVulncheckMCP = counter.New("gopls/mcp-tool:go_vulncheck")
23+
)

gopls/internal/mcp/file_context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type fileContextParams struct {
2121
}
2222

2323
func (h *handler) fileContextHandler(ctx context.Context, req *mcp.CallToolRequest, params fileContextParams) (*mcp.CallToolResult, any, error) {
24+
countGoFileContextMCP.Inc()
2425
fh, snapshot, release, err := h.fileOf(ctx, params.File)
2526
if err != nil {
2627
return nil, nil, err

gopls/internal/mcp/file_diagnostics.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type diagnosticsParams struct {
2929
}
3030

3131
func (h *handler) fileDiagnosticsHandler(ctx context.Context, req *mcp.CallToolRequest, params diagnosticsParams) (*mcp.CallToolResult, any, error) {
32+
countGoFileDiagnosticsMCP.Inc()
3233
fh, snapshot, release, err := h.fileOf(ctx, params.File)
3334
if err != nil {
3435
return nil, nil, err

gopls/internal/mcp/file_metadata.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type fileMetadataParams struct {
1717
}
1818

1919
func (h *handler) fileMetadataHandler(ctx context.Context, req *mcp.CallToolRequest, params fileMetadataParams) (*mcp.CallToolResult, any, error) {
20+
countGoFileMetadataMCP.Inc()
2021
fh, snapshot, release, err := h.fileOf(ctx, params.File)
2122
if err != nil {
2223
return nil, nil, err

gopls/internal/mcp/outline.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type outlineParams struct {
1818
}
1919

2020
func (h *handler) outlineHandler(ctx context.Context, req *mcp.CallToolRequest, params outlineParams) (*mcp.CallToolResult, any, error) {
21+
countGoPackageAPIMCP.Inc()
2122
snapshot, release, err := h.snapshot()
2223
if err != nil {
2324
return nil, nil, err

gopls/internal/mcp/references.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type findReferencesParams struct {
2121
}
2222

2323
func (h *handler) referencesHandler(ctx context.Context, req *mcp.CallToolRequest, params findReferencesParams) (*mcp.CallToolResult, any, error) {
24+
countGoReferencesMCP.Inc()
2425
fh, snapshot, release, err := h.session.FileOf(ctx, params.Location.URI)
2526
if err != nil {
2627
return nil, nil, err

gopls/internal/mcp/search.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type searchParams struct {
1818
}
1919

2020
func (h *handler) searchHandler(ctx context.Context, req *mcp.CallToolRequest, params searchParams) (*mcp.CallToolResult, any, error) {
21+
countGoSearchMCP.Inc()
2122
query := params.Query
2223
if len(query) == 0 {
2324
return nil, nil, fmt.Errorf("empty query")

gopls/internal/mcp/symbol_references.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type symbolReferencesParams struct {
2929
// It finds all references to the requested symbol and describes their
3030
// locations.
3131
func (h *handler) symbolReferencesHandler(ctx context.Context, req *mcp.CallToolRequest, params symbolReferencesParams) (*mcp.CallToolResult, any, error) {
32+
countGoSymbolReferencesMCP.Inc()
3233
fh, snapshot, release, err := h.fileOf(ctx, params.File)
3334
if err != nil {
3435
return nil, nil, err

gopls/internal/mcp/vulncheck.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type VulncheckResultOutput struct {
3333
}
3434

3535
func (h *handler) vulncheckHandler(ctx context.Context, req *mcp.CallToolRequest, params *vulncheckParams) (*mcp.CallToolResult, *VulncheckResultOutput, error) {
36+
countGoVulncheckMCP.Inc()
3637
snapshot, release, err := h.snapshot()
3738
if err != nil {
3839
return nil, nil, err

0 commit comments

Comments
 (0)