Skip to main content
MCP Tools

get_graph_json

Return a subgraph around a symbol as structured JSON for graph renderers. Unlike the other context tools, get_graph_json returns the raw node and edge structure rather than token-budget-trimmed prose, so it is meant for programmatic consumers such as the VS Code graph panel and CI tooling.

This tool is the backend for the visual graph panel in the VS Code extension. The extension calls it automatically when you open the panel, so you do not normally invoke it by hand.

Input schema

{
"type": "object",
"required": ["query"],
"properties": {
"query": {
"type": "string",
"description": "Symbol or file to center the subgraph on."
},
"direction": {
"type": "string",
"enum": ["deps", "callers", "both"],
"default": "both",
"description": "Which edges to follow: dependencies, callers, or both."
},
"depth": {
"type": "integer",
"default": 2,
"minimum": 1,
"maximum": 4,
"description": "How many hops to expand out from the center node."
},
"repo": { "type": "string" }
}
}

Output schema

{
"type": "object",
"properties": {
"nodes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": { "type": "string" },
"label": { "type": "string" },
"kind": { "type": "string" },
"path": { "type": "string" },
"package": { "type": "string" },
"score": { "type": "number" }
}
}
},
"edges": {
"type": "array",
"items": {
"type": "object",
"properties": {
"source": { "type": "string" },
"target": { "type": "string" },
"kind": { "type": "string" }
}
}
}
}
}

The id on each node is the Kythe VName, and the source and target on each edge reference those same VNames.

Example

Request:

{
"name": "get_graph_json",
"arguments": {
"query": "PaymentService",
"direction": "both",
"depth": 2
}
}

Response:

{
"nodes": [
{
"id": "<vname>",
"label": "PaymentService",
"kind": "class",
"path": "src/services/payment.ts",
"package": "@travsr/billing",
"score": 0.923
}
],
"edges": [
{
"source": "<vname>",
"target": "<vname>",
"kind": "calls"
}
]
}

When to use

Use get_graph_json when you need the graph structure itself, not a prose summary:

  • Rendering the live code graph in a UI, for example the Cytoscape.js panel in the VS Code extension.
  • Feeding the node and edge set into a custom integration or CI check.
  • Building your own visualisation or analysis on top of the graph.

For answering a natural language question within a token budget, use get_context instead. For a one-line structural answer such as "who calls this", use the targeted tools like get_callers or get_dependencies.

Token cost

The payload size is proportional to the subgraph size, which grows with depth and the fan-out of the center node. No knapsack trimming is applied, so the response is the complete subgraph rather than a budget-bounded subset. Keep depth at 1 or 2 for dense symbols to keep the payload small.