Skip to content
DocsLit

AI agents 4 min read

Letting AI agents write your docs without making things up

Claude Code, Cursor and Copilot guess component names when they write docs. Give them ground truth and a strict checker, and let them loop until the page is clean.

You ask an agent to write a docs page, and it comes back looking great. Then the build warns about a component that doesn't exist, a callout type nobody defined, and a tab group missing its wrapper. If you want AI documentation writing to be something you can trust, the agent needs two things: facts to work from and a checker that says no. This post covers how we set that up in DocsLit, so you can write docs with Claude Code, Cursor or Copilot and get valid pages back.

Why agents invent components

An agent writing docs has seen many docs frameworks in training. When your project uses custom tags, it fills the gaps from memory. It guesses that a callout takes type="tipp", or that a step component works on its own, because something similar worked somewhere else.

The guesses look plausible, which is the problem. Nothing fails loudly, so wrong markup ends up in a pull request, and a reviewer has to know your component set well enough to catch it. Telling the agent to "be careful" doesn't help. It can't be careful about facts it doesn't have.

Give the agent ground truth

The fix is to let the agent look things up instead of remembering them. DocsLit exposes the component manifest through the CLI:

docslit components --json            # every wc-* component
docslit components wc-tabs --json    # attributes, nesting, a working example
docslit schema                       # JSON Schema for docslit.json
docslit schema frontmatter           # JSON Schema for page frontmatter

The manifest is the same one the validators use, so the reference can't drift from what gets checked. Each entry lists attributes, allowed values, which parents a component needs and an example to copy.

You don't have to teach the agent these commands by hand. Run this once in your project:

npx docslit agents init

It always writes AGENTS.md, with a short brief built from your docslit.json: your sidebar groups, versions, locales and the rules that prevent most mistakes. For the tools it detects, it also writes tool-specific files. For Claude Code that's two skills under .claude/skills/, plus CLAUDE.md and .mcp.json. For Cursor it's .cursor/rules/docslit.mdc and .cursor/mcp.json. For Copilot it's .github/instructions/docslit.instructions.md and .vscode/mcp.json. Windsurf and Gemini CLI get their own rule files too, and Codex reads AGENTS.md directly. Pass --tool all to write everything.

It's safe to re-run. Your own text outside the marked block is kept, and MCP config files are merged rather than replaced. Details are in the agent setup docs.

Connect the MCP server

If your agent speaks MCP, docslit mcp gives it typed tools instead of shell commands. Print a config to paste into your client with docslit mcp --print-config claude (or cursor, vscode).

The tools that matter for correctness:

  • get_project_info: where the agent should start. Sidebar tree, features, theme, custom components.
  • get_component and get_schema: the same data as the CLI commands above.
  • check_markup: checks a snippet before it's written. It reports unknown tags and attributes, invalid values, bad nesting and unclosed tags.
  • create_page and update_page: write the file, then return the markup and validation issues for what they just wrote.
  • validate: runs the validator, and the linter when available, across a page or the project.

Here's what check_markup says about <wc-callout type="tipp">: an invalid-attribute-value issue, the allowed values, a suggestion of tip and a fix string. The agent doesn't have to interpret anything. It applies the fix. The full tool list is on the MCP server page.

Make the checker strict and machine-readable

Ground truth reduces mistakes. A checker catches the ones that remain. Both validate and lint can print a single JSON document:

docslit validate --format json
docslit lint --format json

Each issue has a level, a stable kebab-case code such as broken-link, unknown-attribute or invalid-parent, a file, a line and usually a fix. The docs tell agents to match on the code, not the message text, so wording can improve without breaking scripts. validate answers "is it broken?" and lint answers "is it good?", covering things like missing descriptions and alt text. Both exit with code 1 on errors, or on warnings with --strict. The list of codes is in the machine-readable CLI page.

An example workflow

With the setup above, a prompt like this is enough: "Write a getting-started page for backend developers, with steps and a code group. Run validate and lint when you're done." The agent then does roughly this:

  1. Calls get_project_info (or reads AGENTS.md) to learn the sidebar and groups.
  2. Checks wc-steps and wc-code-group with docslit components <tag> --json instead of guessing.
  3. Creates the page with docslit new guides/getting-started --title "Getting started" --json, then writes the Markdown.
  4. Runs docslit validate --format json and docslit lint --format json.
  5. Edits the reported file and line, and repeats until ok is true.

You can run the same two commands in CI with --strict --format github, so a pull request from an agent (or a person) gets inline annotations before anyone reviews it.

One thing worth being clear about: DocsLit doesn't call a language model itself. It gives your agent accurate reference data and strict feedback, and your agent does the writing. That keeps the checks deterministic and the tool usable with whichever agent you already have.

If you're curious about the reading side, see how AI agents read your docs. To try the authoring loop, run npx docslit init in an empty folder, then npx docslit agents init.