Skip to content

x/tools/gopls: Add MCP tool for depth-limited call graph source retrieval #76814

@myaaaaaaaaa

Description

@myaaaaaaaaa

I would like to propose an MCP tool that retrieves the source code of a call graph rooted at a specific function, up to a specified depth.

Currently, coding agents interacting with Go codebases struggle to gather relevant context efficiently.

  • Token Waste: Agents often read full files to inspect single functions.
  • High Latency: Tracing a function call across packages requires multiple tool round-trips (Read File $\to$ Parse $\to$ Go to Definition $\to$ Read File).
  • Context Fragmentation: Agents struggle to maintain a mental model of cross-package dependencies when files are read largely in isolation.

These problems can be addressed by a new fetch_call_graph tool. It would work like so:

If TestA calls FuncB, and FuncB calls pkgC.FuncD:

  • Request: { symbol: "TestA", depth: 2 }
  • Response: Source code for TestA, FuncB, and pkgC.FuncD.

This allows agents to instantly retrieve the "semantic neighborhood" of a failing test or a bug, regardless of file or even package boundaries. The result is a high-signal context window populated only with reachable code, significantly improving debugging performance and reducing token consumption.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions