Skip to content
RingKoAIPublic

About

Semantic code-outline MCP server: what each implementation does, rendered as a tree.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

English|中文

codetree

tree shows the shape of a directory. codetree shows the shape of the code inside it: directories → files → classes, functions and methods, one row each with its line range, visibility and the one-sentence purpose from the doc comment — and, for a file, the classes it references, rendered as a tree with the file each one resolves to.

It is read-only, uses tree-sitter instead of a compiler or language server, and supports TypeScript, TSX, JavaScript/JSX, Python, Java, Kotlin, Go, Rust, C, C++, Dart and Swift. A grep mode covers the other half of code reading: text lines, with grep flags.

src/main/java/com/acme/order/
└─ OrderService.java  (5 syms · 23 L · 9 refs)
   └─ cls public class OrderService extends BaseService implements OrderApi  :9-23  pub  "Places orders."
      ├─ field private final OrderRepo repo  :10  priv
      ├─ field private final Clock clock  :11  priv
      ├─ ctor public OrderService(OrderRepo repo, Clock clock)  :13-16  pub
      └─ meth public Order place(Cart cart, List<Item> items)  :19-22  pub  "Validates the cart, then writes the order."

references (9 total, 8 resolved, 1 external):
  ├─ imp   BaseService com.acme.base.BaseService  -> src/main/java/com/acme/base/BaseService.java
  ├─ imp   Clock com.acme.clock.Clock  -> src/main/java/com/acme/clock/Clock.java
  ├─ imp   List java.util.List  (external)
  ├─ imp   OrderRepo com.acme.repo.OrderRepo  -> src/main/java/com/acme/repo/OrderRepo.java
  ├─ impl  OrderApi  -> src/main/java/com/acme/order/OrderApi.java
  ├─ new   CartValidator  -> src/main/java/com/acme/order/CartValidator.java
  ├─ param Cart  -> src/main/java/com/acme/order/Cart.java
  ├─ param Item  -> src/main/java/com/acme/order/Item.java
  └─ ret   Order  -> src/main/java/com/acme/order/Order.java
[1 file · 5 symbols · java · 53 ms]

Why

An agent has a context budget. ls says nothing about purpose, a raw symbol dump wastes tokens, and grep finds one name at a time. codetree answers three questions in one compact hierarchy: what exists, what each implementation does, and what it depends on.

Quick start

Give this to your agent:

Set up codetree for this project: follow AGENTS.md, verify the MCP server, add it to my client with CODETREE_ROOTS set to the project root, reload, and confirm the outline, read_file, search, grep, exports, imports and usages tools.

Or run it yourself:

npx -y @ringko-ai/codetree --print src

From a local checkout:

pnpm install
pnpm build
node dist/main.js --print src

Depth

--depth (CLI) and depth (MCP) control how many directory levels are expanded:

codetree --depth 1 --print src      # the immediate children, plus their files
codetree --depth 3 --print src      # three levels down

Each opened file carries its reference count, so going deeper exposes more files and therefore more references. Pass a file instead of a directory to expand those references into a tree with the resolved target path:

npx -y @ringko-ai/codetree --print src/main.ts

depth is clamped to 1–12 (default 3), and every result is bounded by an entry budget and a character budget; truncation is reported in the footer.

Grep

The tree answers "what is here"; grep answers "where is this text". It is line-oriented and repo-wide, with the flags you expect from grep:

codetree grep "place" src            # regex, case-sensitive by default
codetree grep -i -w "place" src      # case-insensitive, whole word
codetree grep -C 2 "TODO" .          # two lines of context around each match
codetree grep -l "Cart" .            # files with matches
codetree grep -c "Order" src         # matching-line counts per file
codetree grep -F "operator(" src     # literal string (regex still works)
codetree grep --include '*.java' "place" src

Output is path:line: text; context lines use path-line- text, like grep. -m <n> stops after n matching lines, --exclude <glob> skips files and --hidden includes dotfiles. Invalid regexes return an actionable error, and every result is bounded by the same character budget as the tree.

Exports and imports

Two module-level views answer the questions an outline does not:

exports  (1 file · 5 symbols · 1 re-export)
src/domain.ts
  :6  enum      State  State  "Order states."
  :12  type      OrderId  OrderId = string  "Identifier alias."
  :23  class     Repo  class Repo
  :3  via       CartValidator from "./order.js"  -> src/order.ts
imports  (1 file · 3 imports)
src/domain.ts
  :1  imp   fs from "node:fs"  (external)
  :2  imp   Order as OrderModel from "./order.js"  -> src/order.ts
  :3  reexp CartValidator from "./order.js"  -> src/order.ts
  • exports lists top-level declarations carrying the language's exported flag, plus export … from rows marked via (disable with include_reexports: false; kinds filters declarations only). Supports path, depth, include, exclude, languages, kinds, max_chars.
  • imports reuses the extractor references and ProjectIndex, so it reports the specifier exactly as written plus the workspace target. Filters: resolved (true/false), external (true/false), dynamic (true/false), include_reexports (default true). Runtime edges (import(), require(), Class.forName, importlib.import_module, __import__) are labelled dyn.
  • group (default true) collapses imports that share a specifier and target into one { a, b, c } row, which matters for barrel files and node:fs. Use group: false for one row per symbol.
  • Monorepo imports resolve through pnpm-workspace.yaml / package.json workspaces and each package's exports/main, and through tsconfig.json compilerOptions.paths; a workspace package is a -> target, not (external).
  • Both are read-only and share the same character budget and 20-second deadline as the other tools.

Usages

usages is the reverse lookup: who references or calls this name?

usages "save"  (1 file · 1 reference)
src/service.ts
  :17  call  return this.repo.save(validator.check(cart) as Order);
  • Type positions (field, param, ret, new, extends, implements) are resolved through the file's import table and the workspace index; pass target to keep only references resolving to one file.
  • Call sites are collected by the extractors and matched by name. Receiver types are not inferred, so save matches every x.save(...) in scope; this is a usage finder, not a compiler-grade call graph.
  • include_calls (default true), include_imports (default false), plus the same path, depth, include, exclude, languages and max_chars controls as the other module tools.

MCP server

codetree is a stdio MCP server. Any MCP client that supports stdio can launch it:

{
  "mcpServers": {
    "codetree": {
      "command": "npx",
      "args": ["-y", "@ringko-ai/codetree"],
      "env": { "CODETREE_ROOTS": "/absolute/path/to/project" }
    }
  }
}
Tool Purpose
outline Implementation tree for a directory or a file. Directories expand to depth levels; a single file appends the resolved reference tree.
read_file Numbered source lines prefixed by the file outline. Use start_line/end_line from the outline to read one implementation.
search Find declarations by name, signature or documentation (default), or search source text lines.
grep grep-style text search: literal or regex, case sensitivity, whole words, context lines, counts, files-with-matches.
exports List only the declarations a file or directory exposes, with line, kind, name, signature and purpose; export … from rows are marked via.
imports List imports with the specifier as written and the resolved workspace target; export … from rows are reexp, runtime edges are dyn; grouped by module by default.
usages Find where a symbol name is referenced or called across the workspace; target restricts resolved references to one file.

Common outline parameters: path, depth, docs, kinds, languages, max_entries, max_chars, references (single-file reference tree).

Reference resolution

Extraction is tree-sitter based; resolution is a name index, not a compiler.

Language Import form Resolution
TypeScript / JavaScript ./repo/order.js Relative file lookup, including the .js → .ts mapping and index.*
TypeScript / JavaScript react Marked external
Java com.acme.repo.OrderRepo Package + class probed from the module's src/main/java layout, then the workspace index
Kotlin com.acme.repo.OrderRepo Same probing; supertypes come from the : list
Python from app.models import Order Module path against the root and src/
Go example.com/acme/repo go.mod module path, then a path suffix under the root; stdlib is external
Rust crate::repo::Order src/repo.rs or src/repo/mod.rs; std:: is external
C / C++ #include "order.h" File directory, include/, src/, then the root; <...> is external
Dart package:acme/models.dart lib/models.dart (then lib/src/); dart: is external
Swift import AcmeCore Sources/AcmeCore/ or AcmeCore.swift; system modules are external

Non-import references (extends, implements, field, param, ret, new, type) are matched against the file's import table first, then against sibling files and the workspace index. Ambiguous names prefer the same package; names that cannot be resolved are printed without a target instead of being guessed.

Supported languages

Language id Extensions
typescript .ts, .mts, .cts, .d.ts
tsx .tsx
javascript .js, .mjs, .cjs, .jsx
python .py, .pyw, .py3, .pyi
java .java
kotlin .kt, .kts
go .go
rust .rs
c .c, .h
cpp .cpp, .cxx, .cc, .c++, .hpp, .hxx, .hh, .h++
dart .dart
swift .swift

All grammars are WASM files shipped inside the package; no compiler or language server is installed.

Limits

  • Resolution is heuristic: overloads, generics and path aliases are not resolved through a compiler.
  • Only a doc comment directly above a declaration becomes its purpose; without one the row shows the signature alone.
  • The workspace class index is built lazily and is not invalidated when files are added or removed during a server session.
  • Symlinks and junctions are never followed, and every path must stay inside a configured root.
  • References are capped per file (400 for normal outlines, 4000 for detailed usages/exports queries). When rows are dropped, the result ends with ... (reference limit reached; results may be incomplete; narrow the path or use grep).

Development

pnpm typecheck    # src + tests, zero diagnostics expected
bun test          # extractor, resolver and tool tests against tests/fixtures

License

Apache-2.0.

About

Semantic code-outline MCP server: what each implementation does, rendered as a tree.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages