Skip to content

About

DocForgeMCP is a Model Context Protocol server designed to bridge the gap between large language models and your codebase documentation.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

DocForgeMCP

A generic C++ documentation toolchain. Doxygen is the extractor; everything else is a renderer over its XML. One extraction feeds two audiences: humans (a generated HTML reference) and LLMs (a contract export plus an MCP doc index).

Nothing here is specialized to a particular consumer project. A project is adopted by writing a docforgemcp.toml (or docforgemcp.json) — never by changing this repo.

Why a contract export

A signature expresses types, not validity. Lifetime, invalidation, and thread safety have no syntactic form in C++, and reading an implementation shows what the code currently does, not what it promises. DocForgeMCP publishes the promise, and answers every guarantee a caller has to know — stating none where the header imposes none, rather than leaving a line out for a reader to interpret.

Install

Two prerequisites, and neither of them is this project:

  • Python 3.12 or newer. A floor rather than a range: the toolchain is stdlib-only Python, and its two third-party dependencies are resolved against whatever interpreter you actually have, so a newer one is a supported configuration.
  • Doxygen >= 1.9.6, < 1.19, taken from PATH or from DOCFORGE_DOXYGEN when that names an executable. Bounded on both sides, because every layer parses its XML and the schema drifts silently between releases — a drifted schema does not raise, it leaves a contract section quietly absent, which reads downstream as a promise the header never made. Doxygen is not bundled: it is GPL-2.0, per-platform, and most C++ developers already have it.

DocForgeMCP is on no package index and no extension marketplace. Every artifact comes from a GitHub release, which attaches all three.

In the editor — install docforgemcp-<version>.vsix. The archive carries the CLI and installs it into its own environment the first time it needs one, so the extension and the server it launches can never be out of step:

code --install-extension docforgemcp-<version>.vsix

As a CLI — the wheel is pure Python (py3-none-any), and the extras name the layers you want:

pip install 'docforgemcp-<version>-py3-none-any.whl[mcp]'    # layers 2 and 3
pip install 'docforgemcp-<version>-py3-none-any.whl[html]'   # layer 1

That first install is the only moment anything here touches the network. No layer needs one while serving, and none may acquire one.

Quickstart

docforge xml      # Doxygen XML -> <output>/doxygen/xml
docforge html     # browsable HTML docs -> <output>/html
docforge llm      # contract export    -> <output>/llm/<header>.md
docforge index    # contract index     -> .docforgemcp/index.sqlite
docforge status   # index state, staleness, toolchain versions
docforge serve    # the MCP doc-index server, over stdio

With no docforgemcp.toml, output lands in .docforgemcp/out under the git top-level. That directory carries its own .gitignore, so nothing needs adding to yours.

From a clone, uv is the environment — uv sync, then uv run docforge … and uv run pytest. The interpreter is pinned in .python-version.

Configuration

Every key is optional except where a decision cannot be inferred: docforge html needs [project].name and [input].dirs, because which headers constitute a published API is a choice no directory scan can make. Unknown keys are a hard error.

The file may be written as docforgemcp.toml or docforgemcp.json — same schema, same key names in diagnostics, chosen by suffix and never guessed from content. TOML is the one that can carry a comment saying why a path is excluded; JSON is the one every toolchain already parses. Having both in one directory is an error rather than a silent precedence.

[project]
name    = "myproject"
version = "0.1.0"

[input]                                  # the curated, published API (HTML)
dirs         = ["include/myproject"]
patterns     = ["*.h", "*.hh", "*.hpp", "*.hxx", "*.ipp", "*.inl"]
exclude      = ["**/detail/**"]
strip_prefix = "include/"

[output]
dir = "build/docs"                       # default: .docforgemcp/out

[html]
narrative = "docs/narrative"             # hand-written .md, extracted with the headers
logo      = "docs/logo.svg"

[index]                                  # the lookup surface (contract export, MCP index)
roots             = ["."]                # default: the workspace root
deps              = []                   # roots extracted once and cached, never watched
patterns          = ["*.h", "*.hh", "*.hpp", "*.hxx", "*.ipp", "*.inl"]
include           = ["deps/boost/**"]    # re-admit past .gitignore
exclude           = ["**/build/**"]      # always drops, beats include
respect_gitignore = true

[llm]
include_undocumented = false             # emit contract-less symbols into the export

[mcp]
index_path             = ""              # default: .docforgemcp/index.sqlite
watch                  = true            # the live loop; false serves a static index
debounce_ms            = 300
full_rebuild_threshold = 25              # more files than this at once: one full rebuild

[input] and [index] are two scopes, not one. The published API is curated and opt-in, so it is empty until you name it; the lookup surface is broad and opt-out, so it defaults to the whole workspace minus .gitignore. An LLM calling boost::asio needs Asio's lifetime guarantees as much as it needs yours, while an API tree drowned in a dependency's pages is unusable — one shared scope would force a choice between the two.

Files are selected in precedence order, highest first: [index].exclude always drops → [index].include re-admits past .gitignore → .gitignore drops when respect_gitignore → the file must be under a root and match patterns.

The HTML is rendered by DocForgeMCP itself, from the same Doxygen XML the other layers read — a page per component, per symbol and per member overload set, wrapped in Boost's own vendored stylesheet. There is nothing to configure and nothing fetched at build time: the whole tree opens straight off disk and serves from any prefix.

Contract vocabulary

Alongside the standard Doxygen tags (@param, @return, @retval, @pre, @post, @invariant, @throws, @see, …), DocForgeMCP defines aliases for the C++ facts Doxygen has no tag for:

Tag Captures
@lifetime How long an argument or referent must remain valid
@invalidates What references, iterators or handles the call invalidates
@thread_safety none / distinct-objects / full

Each is an \xrefitem keyed by the tag name, so it survives into the XML as <xrefsect id="<key>_…">. Downstream layers match on the key, never on a display label or on rendered prose.

The two audiences read the same tags differently. In the HTML, @thread_safety and @lifetime earn their own section on each symbol — they are the guarantees a reader must not have to hunt for — while every @invalidates on a symbol gathers into one Notes block rather than fragmenting the page into a run of one-line entries. The LLM export treats all three as primary. Folding happens at render time: an alias always expands the same way, at every extraction.

An unstated guarantee reads as none. Leaving @pre off a symbol with no preconditions is the normal case and adds nothing to write — the export states pre: none for it, which is the conclusion a reader already draws from the HTML having no Precondition section. What that costs is stated plainly: nothing distinguishes a guarantee the author considered and ruled out from one they never considered, so stating what is true is the author's job, and the agent instructions below are what keeps it done. Write a tag when it says something; @thread_safety none is worth writing because there none means unsafe to share, not unconstrained.

Recommended agent instructions

DocForgeMCP deliberately ships no contract linter. Whether a guarantee is worth demanding is a reading of the declaration — a pointer parameter raises a lifetime question, a value-in/value-out free function raises none — and a check that cannot make that judgment demands a tag that gets answered with filler. @thread_safety unspecified written to satisfy a linter is indistinguishable, in the export and in the index, from a considered promise: the failure this project exists to prevent, introduced by the tool meant to prevent it.

So the expectations are stated to the model instead, while the code is being written and a human is there to answer. This is also the only thing standing behind the none rule above: because an unstated guarantee reads as none, the guarantees that matter have to actually get written, and these instructions are what makes that happen. The reading half — look a symbol up before calling it, read the answer literally, and never recover a guarantee from the implementation, a call site, or a base class — is delivered by the MCP server itself, so what follows is only the writing half. Paste it into whatever instruction file your agent reads — .github/copilot-instructions.md, AGENTS.md, CLAUDE.md — and edit the list to the guarantees your project actually makes.

## C++ contracts

When writing or reviewing a header in this project, state every guarantee a caller
cannot see from the signature. Nothing checks this and nothing infers it, so a guarantee
you leave out is one the next reader is told does not exist. Expect a declaration to
state:

- a lifetime for every pointer, reference, view or span parameter — how long the caller
  must keep it valid, and whether the callee retains it past the call;
- thread safety on the type that owns the shared state, not repeated on each member;
- what a mutating call invalidates, where it invalidates anything;
- a precondition wherever some inputs are not valid, and the error mode — throws,
  `error_code`, or undefined behaviour — wherever misuse is possible.

Expect each of these only where the declaration actually raises the question. A tag
written to fill a slot is worse than none, because it reads as a considered promise.
And never write one you cannot get from the author or from the declaration's intent.

The contract index

docforge index builds a SQLite FTS5 index of every public symbol in the [index] scope, at .docforgemcp/index.sqlite. It needs no config file: the default scope is the whole workspace minus what .gitignore excludes, so a vendored dependency is indexed alongside your own headers — an LLM calling into one needs its contract just as much.

docforge index --if-missing          # create one only when there is not one already
docforge index --rebuild             # discard and rebuild, swapped in atomically
docforge status --format json        # state, staleness, and toolchain, for an editor

Two rules are worth knowing. Every public symbol is indexed, including the ones the Markdown export omits for compactness: answering "no such symbol" for a symbol that exists is what sends a model back to the implementation for a guarantee the header never made, so such a symbol is stored with its required keys rendered as none. And a header's rows are rewritten only when its contract changed, so an edit that altered bytes but no promise costs one hash update and nothing else.

docforge status reports ready, stale, not-initialized or error, and decides staleness by content rather than timestamps — a full read of the scope, whose cost is reported rather than traded away for a cheaper, wrong answer.

The MCP server

docforge serve serves that index to an MCP client over stdio, building it first when there is none. It needs no config file, and needs the mcp extra (which the VS Code extension provisions for you):

docforge serve --no-watch            # do not follow source edits

The surface is two tools and no more — every added tool costs context on every request and creates a wrong-tool failure mode:

Tool Answers
search_docs(query, limit) symbols whose stated contract matches a name or a guarantee
get_symbol_doc(name) one symbol's full contract, by qualified or call-site name

Index maintenance is deliberately not an MCP tool. It belongs to the CLI, which no model can see.

Every answer carries the declaring header, the line, and when the contract was extracted; a header whose bytes have moved since is flagged STALE rather than served as if current. It also says whose contract it is — a workspace header is where work in progress lives, so its documentation is the most likely to be lagging the code and is worth checking against the change being made, while a dependency, pinned one moved with the code it describes. A symbol that states no contract is still answered, with its required keys as none, because the one thing a lookup must never do is report a symbol that exists as missing. Only stated text is searchable, so a search for lifetime returns the symbols that make a lifetime promise rather than every symbol that lacks one.

stdout is the MCP transport, so every diagnostic goes to stderr.

While it is running

The server watches your headers and reindexes the ones you edit, so a contract changed seconds ago is what the next answer states. A body-only edit costs nothing: a header's rows are rewritten only when its contract moved. A query is never blocked on a rebuild — it is answered from the last contract that finished extracting, and the answer says so.

The index has exactly one writer, and while the server runs that writer is the server. So docforge index asks it to do the work instead of racing it:

docforge index --rebuild     # performed by the live server; says which pid did it
docforge status              # adds the live server, and any rebuild in flight

That conversation happens over a local socket at .docforgemcp/control.sock, announced only in .docforgemcp/serve.json. It is not MCP and is never advertised in tools/list: a destructive rebuild must not be reachable by a model's inferred intent. With no server running, the same commands simply do the work themselves.

Status

Layer What State
1 Human HTML — Doxygen XML → a first-party renderer done
2 LLM contract export — <output>/llm/<header>.md done
3 MCP doc-index server — SQLite FTS5 + live watcher done
4 VS Code extension — launcher only done; released as a .vsix, not listed on the Marketplace

tests/fixtures/sample/ is the end-to-end input: a small documented C++ tree that exercises every contract alias, both the documented-none and the not-documented case, and an override that must not inherit its base's contract.

Licence

See LICENSE.

About

DocForgeMCP is a Model Context Protocol server designed to bridge the gap between large language models and your codebase documentation.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages