graph
Analyze code structure to assess what breaks when a symbol changes, trace call paths, detect cycles, find entry points, hotspots, coupling, and dead code before editing.
Instructions
Structural questions about the code graph: blast radius, paths, cycles.
WHEN TO USE: after investigate() has told you what a symbol is for, and you need to know what changing it costs. investigate() answers "what is this and why"; graph() answers "what else moves if I touch it". AFTER THIS: investigate(action='why', symbol=...) on anything surprising in the blast radius, then record() what you decided.
Actions:
impact blast radius of one symbol. direction='upstream' is who depends on
it (who breaks if the contract changes); 'downstream' is what it
depends on.
trace shortest directed call path from target to to. Use it to prove
two symbols are actually connected rather than assuming it.
cycles directed cycles in the file import graph. Act on component_count,
not on the number of cycles: one removed import can dissolve a
whole component, so the cycle count swings wildly and the
component count is what a fix actually reduces. A deferred import
(inside a function, or a TypeScript import type) is excluded: it
cannot force an initialisation order, and it is the usual fix for
a cycle rather than a cause of one.
entrypoints
where control enters the program - routes, MCP tool handlers, CLI
commands, tests. Pass a kind in target to filter. Start here on
an unfamiliar codebase.
areas functional areas from the call graph, not the directory layout, so
an area can span directories. Each carries test_share and the
entry points that reach it; an area nothing reaches is a library
or is dead.
triggers
which entry points can reach target - what a user can actually
do that runs this code. The complement of impact: not "what else
changes" but "what can set this off".
coupling
file pairs that keep changing together, from git history. The
rows worth reading are the ones with also_imports=false: those
are coupled by something no static analysis can see.
hotspots
where change and structural weight meet. Neither alone is
interesting; a file both heavily depended on and constantly
rewritten is where a change is most likely to break something
far away.
deadcode
symbols nothing in the graph reaches. CANDIDATES, never a
verdict - read confidence on every row and the boundaries
before acting on one.
memscore
measure this repository's own retrieval: accuracy, latency and
context cost, reported side by side and deliberately not
combined into one number. Ground truth is the store's anchored
memories, so it is free and specific to this repository - and
only comparable to another run on the SAME repository. Use it
before and after touching search weights. window sets the
sample size.
run the runtime counterpart of all of the above: execute target
(any shell command: 'python app.py', 'pytest -x tests/test_a.py',
'npm test') and record what actually happened. Python gets the
full call flow, arguments, return values, how local variables
changed line by line, time and CPU per function, exceptions and
library calls; Node.js gets a sampled CPU profile; anything else
gets time, memory, exit code and output. Calls the static graph
does not know (dynamic dispatch, callbacks) are listed. Returns
the path of report.md: READ THAT FILE, it is written for you.
run_diff
compare two recorded runs, e.g. before and after a change, or a
passing and a failing input: the first point where the call
sequence diverges, the first variables whose values differ, calls
and exceptions present in only one run, and time that moved.
target and to name the two runs (folder or name fragment);
omit both to compare the two most recent runs in root.
READ THE ENVELOPE BEFORE THE RESULT. Every answer carries:
epistemic 'exact' or 'lower-bound'. 'lower-bound' means callers exist
that this result provably does not list. An empty affected
with epistemic='lower-bound' is NOT proof that nothing calls
the symbol.
boundaries one plain sentence per reason, for humans.
causes the machine-readable why. Every field counts MISSING or
UNPROVEN things, never sentences:
ambiguous_call_sites - call sites naming this symbol that
could not be attributed to a single definition. These
are the callers you are not being shown.
inferred_edges_traversed - edges resolved by import scope or
by uniqueness of the name, not proven from the syntax.
Counts edges walked, so it can exceed counts.inferred,
which counts distinct symbols reached.
external_call_sites - calls that left the indexed program.
Not a defect: no in-graph node could have been reached.
Edges are tiered, and the tier is on every result. receiver_self (1.0) and same_file (0.9) are read off the syntax; imported (0.8) and unique_global (0.6) are judgements. Pass min_confidence=0.9 to walk only what was proven.
The three history actions carry their own envelope. It is always
'lower-bound': history only knows the commits it read, only knows committed
work, and knows nothing that a squash or a shallow clone removed. history
in the result says how much was actually read.
Args:
action: impact (default), trace, cycles, entrypoints, areas, triggers,
coupling, hotspots, deadcode, memscore.
target: symbol to analyse, the path source for trace, or - for
action='entrypoints' - a kind to filter by (route, tool, cli, test).
A bare name is fine; if it is ambiguous the candidates come back
for you to choose.
to: destination symbol, for trace.
direction: upstream or downstream, for impact.
depth: hops to walk. Clamped to 12.
file_hint: path fragment disambiguating target, e.g. 'search.py'.
to_file_hint: the same, for to.
include_tests: include test files in the blast radius. For
action='areas', rank mostly-test areas alongside the rest instead of
sorting them last. For action='deadcode', report unreferenced test
symbols too.
min_confidence: drop edges below this confidence before walking.
window: commits to read, for the history actions. Default 500, max 5000.
since: a git date ('3 months ago', '2026-01-01') bounding that window.
root: repository path. Defaults to the server's working directory.
For action='run', the directory the command runs in.
timeout_seconds: for action='run', stop the command after this long.
run_options: for action='run', any of 'libraries' (also trace the
standard library and installed packages; slower), 'memory'
(allocation sites; slower), 'no-values' (flow and timing only;
fastest).
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "graph"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| to | No | ||
| root | No | ||
| depth | No | ||
| since | No | ||
| action | No | impact | |
| target | No | ||
| window | No | ||
| direction | No | upstream | |
| file_hint | No | ||
| run_options | No | ||
| to_file_hint | No | ||
| include_tests | No | ||
| min_confidence | No | ||
| timeout_seconds | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||