Delphi-RAG-Lint
Delphi tooling · AI assistants

Integrating drag-lint With AI Coding Assistants

An AI assistant that greps a Delphi code base reads comments, doc lines and look-alike names; one that asks the drag-lint index gets the resolved answer. This article shows the MCP server, the instruction text and the two Claude Code hooks we use, and what the numbers say so far.

What ships, what does not

The MCP server (drag-lint serve) and the config writer (drag-lint mcp-config) are part of drag-lint. The two Claude Code hooks in section 05 are our own setup, not part of the download: we describe what they do so you can build the same thing, but there is no install command for them.

We use AI assistants every day on Micronite, the quality and production-control software we build for manufacturers, and on drag-lint itself; the setup below is what survived that use.

01 — Why not grep

Twenty-six lines, four calls

Ask “who calls Normalize” in the drag-lint source. Pascal is case-insensitive, so a fair text search has to be too, and it returns 26 lines across 10 units. Most of them are comments (“Normalize separators to '\' up front”), doc-comment lines that mention the routine, the declaration, and unrelated words in other units. An assistant has to read all of them, and usually the files around them, to find out which are calls.

drag-lint query find-callers --name Normalize --db src\cli\_D-RAG\drag-lint.sqlite

The index answers 4 caller(s) (4 exact): two calls on line 226 and one each on lines 235 and 237 of DRagLint.Index.Glob.pas, each with a few lines of context. The answer is resolved against declarations, so a call through with, an inherited member or a qualified name is found, and a comment is not.

The index also says when it is not sure. For LoadFromFile the same command answers 22 caller(s) (5 exact, 17 name-only): five calls resolved to one declaration, seventeen matched by name only. Text search gives 76 lines and no such split.

The answer covers the project's compile closure, the units its .dproj and .dpr pull in, so an assistant does not have to guess which of three copies of a unit the compiler uses.

02 — Register the server

drag-lint mcp-config

The MCP server is the engine itself: drag-lint serve --db <index> speaks the Model Context Protocol over stdin and stdout. You do not have to write the client entry by hand:

drag-lint mcp-config --claude-code --db C:\Projects\Delphi-RAG-lint\src\cli\_D-RAG\drag-lint.sqlite --dry-run
Target: ClaudeCode
Path  : C:\Users\<you>\.claude.json
Action: would-added
Backup: (none)
Before: (none)
After : {"type":"stdio","command":"C:\\Projects\\Delphi-RAG-lint\\third_party\\dll-win64\\drag-lint.exe","args":["serve","--db","C:\\Projects\\Delphi-RAG-lint\\src\\cli\\_D-RAG\\drag-lint.sqlite"],"env":{}}

Drop --dry-run to write it. --vscode writes %APPDATA%\Code\User\mcp.json, --cursor writes ~\.cursor\mcp.json, --all does all three. The write merges into the existing file, keeps a timestamped backup and changes nothing on a second run; --remove takes the entry out again. It refuses an index that does not exist, because the server would refuse it too. A project-level .mcp.json with the same entry works as well; that is what the drag-lint repository uses.

The server opens the index read-only. A battery test checks that the database file's hash, size and time stamp are unchanged after the tools run and that no journal file appears.

Help: MCP server · mcp-config · serve

03 — The tools

Twenty tools, two that are not read-only

The 1.62.0-alpha server lists 20 tools. The ones an assistant needs most carry a “USE FOR” line in their description, so the assistant picks them over a text search:

QuestionTool
Where is X declared, what is its signaturefind_symbol
Who calls Y (pass the bare member name, Bar, not TFoo.Bar)find_callers
Where is X used (reads, writes, calls, type uses)find_usages
I am about to change X: its doc, class surface, own body and callersget_context_bundle
What would a change to X breakget_impact, get_neighbors
Public interface of a class, a self-contained slice of its unitget_surface, get_slice
Who implements an interface; Spring4D and event wiringget_implementors, get_wiring
Which routine raises or handles which exceptionget_exception_facts
Is a variable or field set before it is usedcheck_init
What is the identifier at file, line, columnget_type_at_position
Doc comments: read one, find by tag, find missing onesget_symbol_doc, find_by_doc_tag, find_undocumented
Lint a file or folder; compiler-less AST checkslint, run_ast_checks
Rename a symbol everywhererename_symbol (use dry_run)
Compile checkrun_compile_check

Two tools change something. rename_symbol without dry_run edits the source, through a compile gate, and needs the project file. run_compile_check starts the compiler and says so in its description (“SLOW, NOT read-only”). We let assistants call rename_symbol only with dry_run and build with our usual build script instead of run_compile_check.

Some questions have no tool yet: which unit to add to uses, a search for message or caption text, a file outline, a re-index and lint-all. For those the assistant runs the command line (find-unit, query --text, outline, index --project, lint-all).

04 — The instruction

Tell it to ask first

A registered server is not used just because it is there. Assistants reach for text search out of habit, so the project's instruction file (CLAUDE.md, AGENTS.md or your tool's equivalent) says so plainly. Ours comes down to this:

This Delphi project has a drag-lint index. Ask it BEFORE grepping or
reading whole .pas files:
- where is X            -> find_symbol
- who calls Y           -> find_callers (bare member name)
- modify / understand X -> get_context_bundle, then read only the lines you need
- what breaks           -> get_impact / get_neighbors
- uses unit for X       -> drag-lint find-unit --name X --in <file> --db <db>
- message text          -> drag-lint query --text "<phrase>" --db <db>
If an answer looks short or empty, the index may be stale: re-index
(drag-lint index --project <X.dproj> --db <db>) and ask again; do not
fall back to grep silently.

The last line matters as much as the others. An index answers for the code it last saw; an assistant that quietly switches to grep when the answer looks thin hides the stale index from you. The longer command-line version of this text is in the drag-lint repository's docs\AI-USAGE.md, section 2.

05 — Claude Code hooks

A guard before the search, a lint after the edit

Instructions get skipped, so in Claude Code we back them with two hooks. They are small Node.js scripts in our own ~\.claude\hooks folder, not part of drag-lint. Hooks are configured per user, so subagents a session starts run under the same hooks.

PreToolUse

Index first

Before a Grep, a Glob or a shell grep / rg / findstr aimed at .pas, .dfm, .dpr or .dpk files in a tree that has a drag-lint index, the hook denies the call and names the tool to use instead (the MCP tools when the project registers the server, otherwise the command line). Once the assistant has asked the index in the last five minutes, the search goes through, and the fallback is logged as a possible gap in the index. A Read of a Delphi file over 2,000 lines without an offset is denied too. Any error in the hook lets the call through, and DRAGLINT_FIRST_OFF=1 switches it off.

PostToolUse

Lint what was just changed

After every Write or Edit of a .pas, .dpr or .dfm file the hook finds the project's index, runs drag-lint lint <file> --db <db> --json with a 20-second limit, keeps only the findings that start on a changed line, and hands at most ten of them back to the assistant as context. It never blocks the edit and never re-indexes; DRAGLINT_POST_EDIT_OFF=1 switches it off. The assistant sees a finding on a line it just wrote while the change is still in front of it, instead of in the next lint run.

Both hooks use only commands documented in the help, so the same pattern works in any assistant that can run a step before and after a tool call.

06 — Statistics

What it saved us, counted carefully

Every time we use the index in our own work we log two figures: tokens the answer cost, and tokens the alternative would have cost. The second is a guess, so we count it conservatively: rows logged with the conservative method as logged (at most 6,000 tokens per query), every other row capped at 3,000 tokens for a file read and 1,500 for a grep-style question. The plain sum of what was logged is several times larger; we do not use it.

60.3k / 38.9kMCP: avoided / used, 27 queries
3.5k → 2.5ktokens per indexed query, Oct → Nov
+87.2knet, November
  • Through MCP, 27 logged queries avoided an estimated 60.3k tokens and cost 38.9k.
  • Per query, an indexed answer cost about 3.5k tokens in October (473 queries) and 2.5k in November (339).
  • Per month, the net was negative in September (-253k) and October (-645k) and turned positive in November (+87k). The first days of December are positive as well (+39.6k on 22 queries).

The honest part: over all paired rows the net is still negative (-771.5k). The loss is in whole-file reads (-830.4k): when an assistant reads a file after the index answered, our capped estimate of what it saved is smaller than what the answer cost. Grep-style questions roughly break even (+40.4k). The savings sit in questions that cross units, such as callers, impact and context bundles, which is where the index is meant to be used. The sample is small, and our figures come from our own work only.

Last measured 2026-12-02 with tools\draglint-usage-report.cjs; updated figures due around 2026-12-14.

07 — Why it is repeatable

The index answers, the assistant decides

Every answer the server gives comes from the index drag-lint builds by parsing your source. No model is involved on the drag-lint side: the same source and index give the same callers, impact and findings on every run and every machine. The assistant still decides what to do with them, and you still review its change.

08 — Limits

What to know before you rely on it

  • The hooks are not shipped. Section 05 describes ours; you write your own.
  • An index is only as fresh as its last index run, and only as complete as the project's .dproj and .dpr: a unit that is used but not listed is not indexed. The server adds a freshness note when the index is older than the source.
  • find_callers takes the bare member name; TFoo.Bar returns nothing. An ambiguous bare name in get_context_bundle also returns nothing rather than a guess: qualify it.
  • The statistics are our own, on our code bases, with a small number of MCP queries.

Output measured 2026-12-02 with drag-lint 1.62.0-alpha on the drag-lint source index; the tool list comes from the deployed 1.62.0-alpha server. The user folder in section 02 is shortened. Hook behaviour is described from the hook scripts; statistics from stats\draglint-usage.log through tools\draglint-usage-report.cjs the same day.