@ttsc/graph

TypeScript Compiler Knowledge Graph

Give your coding agent the index the compiler already drew

Declarations, signatures, calls, types, decorators, tests, diagnostics, and source spans through one typed MCP tool.

@ttsc/graph · ttsc.dev/docs/graph

Do not make the agent read the whole repository.

Most orientation starts as grep, file read, import chase, another grep, and another file read.

@ttsc/graph · ttsc.dev/docs/graph

The repository crawl loop

QuestiongrepReadimportRead
  • Each hop replays context.
  • Text matches do not resolve aliases, re-exports, or types.
  • Broad questions grow with repository size.
@ttsc/graph · ttsc.dev/docs/graph

The compiler already knows the graph

ProgramSource files, modules, compiler options, diagnostics
TypeCheckerSymbols, types, signatures, declarations
@ttsc/graphResolved nodes, edges, tests, and spans

@ttsc/graph reads the resident TypeScript-Go compiler session.

@ttsc/graph · ttsc.dev/docs/graph

Compiler-exact relationships

  • tsconfig path aliases land on the real declaration.
  • Barrel re-exports preserve symbol identity.
  • pnpm workspace packages and project references resolve normally.
  • Symlinks and module-resolution rules are already settled.
  • Diagnostics and graph facts describe the same Program.

A syntax index can infer these edges. The compiler has already proved them.

@ttsc/graph · ttsc.dev/docs/graph

It returns an index, never source bodies

CheckoutService.place
  signature  place(input: IOrderInput): Promise<IOrder>
  declared   src/checkout/CheckoutService.ts:41-88
  calls      Inventory.reserve, Payment.authorize
  testedBy   test_checkout_place
  • Names, signatures, edges, decorators, tests, and source spans
  • No implementation body in the MCP response
  • Read the smallest span only when body text is actually needed
@ttsc/graph · ttsc.dev/docs/graph

Why “index only” matters

Source bodies

  • Output grows with every selected file
  • Broad queries spill large context
  • The agent must interpret raw implementation again

Graph index

  • Output grows with the answer
  • Relationships arrive resolved
  • A span anchors any necessary follow-up
@ttsc/graph · ttsc.dev/docs/graph

One tool, with an escape hatch

Guide the decision without replacing the agent's workflow

@ttsc/graph · ttsc.dev/docs/graph

One MCP surface

inspect_typescript_graph({
  question,
  draft: { type, reason },
  review,
  request,
});

The request is a discriminated union. Choosing its type chooses the operation.

@ttsc/graph · ttsc.dev/docs/graph

The schema carries the reasoning path

QuestionDraftReviewRequest
  • draft names the smallest operation that looks sufficient.
  • review can correct an over-broad or off-graph plan.
  • request commits exactly one typed operation.

Free prose can skip a step. A required schema field cannot.

@ttsc/graph · ttsc.dev/docs/graph

Seven request types

Type Use it for
tour Broad, one-call architecture tour
entrypoints Where to start reading
lookup Find a symbol by name
trace Follow calls, data flow, or impact
details Signature, members, and neighbors
overview Repository-level structure
escape The evidence is outside the graph
@ttsc/graph · ttsc.dev/docs/graph

Escape is a first-class success

Use the graph when the answer depends on TypeScript symbols, calls, or types.

Use escape when the answer depends on:

  • exact implementation text;
  • configuration or documentation;
  • runtime state or external systems;
  • a non-TypeScript project.
@ttsc/graph · ttsc.dev/docs/graph

Fresh on every operation

  • No separate init command
  • No repository-local index to remember or commit
  • Unchanged calls reuse warm in-memory indexes
  • Safe edits reuse the incremental compiler Program
  • Config, roots, deletion, or resolution changes trigger a reload
  • Refresh failure returns an error, never a stale graph
@ttsc/graph · ttsc.dev/docs/graph

The same graph is visible in 3D

3D TypeScript code graph

Every node is a declaration. Every edge is a compiler-resolved relationship.

@ttsc/graph · ttsc.dev/docs/graph

Does the index reduce agent cost?

Empty-MCP baseline versus four graph tools

@ttsc/graph · ttsc.dev/docs/graph

Benchmark design

  • Eight TypeScript repositories, from 51k to 3.1M lines
  • Common onboarding prompt and repository-specific prompts
  • Empty-MCP baseline plus @ttsc/graph, codegraph, codebase-memory, and serena
  • Codex and Claude Code model lanes at high reasoning effort
  • One published run per cell; repository breadth is the sample

This is one person's bounded benchmark. It is not a universal performance guarantee.

@ttsc/graph · ttsc.dev/docs/graph

The headline

~10×fewer tokens
conservative median
8repositories
51k to 3.1M lines
1typed tool
index, never bodies

Answer quality was manually inspected; free-text matching was not used as an oracle.

@ttsc/graph · ttsc.dev/docs/graph

Cost stays flat as repositories grow

small TypeScript project  ─┐
medium monorepo           ├─ answer-sized graph response
3M-line VS Code           ┘
  • Baseline and comparator costs swing with repository size.
  • @ttsc/graph stays near the cost of the requested index.
  • Some comparator cells cost more than running with no MCP.
@ttsc/graph · ttsc.dev/docs/graph

Cold time matters too

On the three-million-line VS Code fixture:

<30s`@ttsc/graph` compiler index
~12mcodegraph index build
~5mserena project indexing

The published chart adds index readiness and LLM answer time in the order a developer waits.

@ttsc/graph · ttsc.dev/docs/graph

The trade

Tool shape Strength Cost
@ttsc/graph compiler-exact TS graph, one tool TypeScript only
codegraph one default tool, many languages text-inferred edges, source bodies
codebase-memory broad multi-language graph many tools and explicit indexing
serena LSP-resolved symbols, editing suite broad tool surface and setup
@ttsc/graph · ttsc.dev/docs/graph

Add it in four lines

npm install -D ttsc @ttsc/graph typescript
{
  "mcpServers": {
    "ttsc-graph": {
      "command": "npx",
      "args": ["-y", "@ttsc/graph"]
    }
  }
}
@ttsc/graph · ttsc.dev/docs/graph

Explore your graph in the browser

npx @ttsc/graph view
  • Opens the project graph in a 3D viewer.
  • Color and filter by declaration or edge kind.
  • Inspect incoming and outgoing relationships.
  • Export a snapshot for sharing.
@ttsc/graph · ttsc.dev/docs/graph

Boundaries are deliberate

  • TypeScript only: compiler depth is tied to one language.
  • An index is not the implementation body.
  • Graph evidence cannot answer config, prose, runtime, or external-state questions.
  • The benchmark result can be lower or negative on a different workload.

The tool steps aside when its evidence is not the right evidence.

@ttsc/graph · ttsc.dev/docs/graph

TypeScript Compiler Knowledge Graph

  • Trust compiler-resolved relationships.
  • Return the index, never the source bodies.
  • Shape one tool so the agent can choose well.

Exact → trusted → done.

@ttsc/graph · ttsc.dev/docs/graph

Q & A

@ttsc/graph · ttsc.dev/docs/graph