# MCP Server & AI Skill

Two packaged tools make AI-assisted ChainRender development first-class: the **MCP server** (so an AI calls the SDK
as tools) and the **app-builder skill** (so an AI knows the workflow). Both wrap the shipped `@chainrender/client` —
the AI's output stays verifiable (graded, compiled, validated), never blind.

They enforce two things a correct build needs: the **on-chain paradigm** (the component IS the app — compiled,
registered on-chain, rendered by an `eth_call`; not a React app that fetches with viem and hand-renders while
ChainRender only prints a hash — see [Building Correctly](../concepts/building-correctly.md)) and the
**[trust grade](../concepts/trust-grade.md)** (A = fully on-chain/trustless; off-chain dependencies drop the grade
and must be declared, never hidden). The skill teaches both; the MCP `grade` tool proves the second.

## The MCP server — `@chainrender/mcp`

A Model Context Protocol server that exposes the ChainRender SDK as tools, so an AI assistant in an MCP-capable
editor or chat can build apps by calling them directly.

### Tools

| Tool | What it does | Since |
|---|---|---|
| `chainrender_vocabulary` | The closed vocabulary (node types and fields, enums, capabilities, resolver kinds). **Call first.** Optional `include` returns only the named sections (`nodeTypes`, `a11y`, `behavior`, `enums`, `capabilities`, `kinds`, `resolverKinds`, `limits`; `presentation` with `mode: "enhanced"`). `mode` (`classic` default / `enhanced`) also on `check_node`, `compile` and `review`. | 0.1.0 (`include` 0.4.0, `mode` 0.13.0) |
| `chainrender_search_kinds` | Find resolver kinds by words (`"uniswap price"`, `"ens"`) and data edge; returns names, one-line summaries and arg names only. | 0.4.0 |
| `chainrender_describe_kind` | One kind's full descriptor: args (name, ABI type, note), `argsEncoding`, data edge, capability, notes. Unknown names return the closest matches. | 0.4.0 |
| `chainrender_check_node` | Check a tree against everything `compile()` reads; reports what it would silently drop, with paths. `authoring: true` accepts builder fields. | 0.4.0 |
| `chainrender_node_schema` | The strict JSON Schema of a tree, to constrain generation. | 0.4.0 |
| `chainrender_grade` | Grade a composition (A/B/C + itemized breakdown); optional `pinnedDep` for Grade B. | 0.1.0 |
| `chainrender_compile` | Compile to the content-addressed hash (deterministic). | 0.1.0 |
| `chainrender_validate` | Enforcer-equivalent checks (pass a manifest `{ name, version, root }`). | 0.1.0 |
| `chainrender_review` | check + grade + compile + honesty findings + (optional) validate in one call — the finalize loop. `pass` is the bit to gate "done" on; `chain` checks every address against that chain's contracts and its code. With `mode: "enhanced"` it adds the presentation findings and, with `chain`, reads that chain's RenderRouter (`v5-unavailable` when it has no VERSION_5 interpreter). | 0.1.0 (check 0.4.0, honesty and `pass` 0.8.0, Enhanced 0.13.0) |
| `chainrender_verify` | Confirmed / Refuted / Inconclusive, with evidence, for one fact: `kind-exists`, `export-exists`, `kind-deployed`, `contract-deployed`, `address-has-code`, `v5-available` (the chain's RenderRouter has an `interpreterFor(5)` with code and `version()` 5). Reads chains.json and the chain. | 0.8.0 (`v5-available` 0.13.0) |
| `chainrender_doctor` | Installed SDK and server vs npm; chains.json vs the Addresses page (stale?); each RPC reachable and really that chain; every listed contract has code; whether each chain renders VERSION_5 (a warning where it does not). | 0.8.0 (V5 0.13.0) |

**The server's instructions.** Since 0.8.0 the server sends **[Start Here for AI Builders](./ai-start-here.md)** as
its MCP `instructions` when a client connects, so the model reads it before any tool. It is the same text that heads
`llms.txt` and the skill, from one file (`ai/start-here.md`).

**Honesty findings** (`honesty` in the review, from the SDK's `honestyFindings()`):

| Rule | Severity | When |
|---|---|---|
| `public-input` | warn | an `input`'s value fills a button's `$name` arg, and no text on screen says it becomes public on-chain |
| `public-secret` | error | a `password` input fills an action arg |
| `live-claim` | warn | text says "live" / "real-time" / "real data", but nothing in the tree reads the chain |
| `unbacked-claim` | warn | the app's text or a string in its sketch says "certified", "audited", "load-tested", "guaranteed", "insured", "bank-grade", "military-grade", "unhackable", "risk-free" or "100% safe/secure" (client 0.15.0; the wider list 0.18.2) |
| `grade-claim` | error / warn | the app's text or a sketch string says "Grade X", "trustless" or "fully on-chain" and the computed grade does not support it (error); or the app has a ⚙ part and the claim is not said of the floor (warn) (client 0.21.1, docs/204) |
| `unchecked-claim` | warn | the app says "decentralized", "censorship-resistant", "uncensorable", "unstoppable", "tamper-proof" or "provably fair": no check can back it (client 0.21.1) |
| `stage-touch` | warn | a p5/three sketch handles pointer/touch events but never sets `touch-action` (client 0.15.0) |
| `stage-pinch` | warn | a p5/three sketch zooms on the mouse wheel only — no pinch (client 0.15.0) |
| `stage-own-toggle` | warn | a CR-Stage sketch builds its own Hide/Show Controls toggle (client 0.15.0) |
| `stage-safe-area` | warn | a CR-Stage sketch fills `#cr-controls` and draws text on the canvas but never reads `CRStage.safe` x/width, so its text runs under the docked controls (client 0.18.0) |
| `p5-v1-api` | error | a p5 sketch uses the p5 1.x API that the on-chain p5 2.3.2 removed (6-argument `bezierVertex`, `curveVertex`/`curvePoint`, `quadraticVertex`, `preload()`, …); names each line and its 2.x replacement (client 0.17.0) |
| `sign-message` | error | a `sign` message whose values do not fit their declared types, or carry a `$name` (nothing substitutes an input into signed typed data: it is signed exactly as written) (client 0.18.2) |
| `viewer-read` | error | a viewer read the viewer would refuse (a kind outside the allowlist, a wrong arg, an explicit `resolver`, the wrong node), or `"$viewer"` in an action, batch, signature or condition (client 0.19.0) |
| `transfer-history` | error | a transfer history (bind `transfers`) with fields the viewer would refuse (client 0.19.0) |
| `unknown-address` | warn or error | an address that is not a ChainRender contract on the target chain. With `chain` (client 0.18.3 / MCP 0.11.1): no code there is an **error**; a contract the app's text names is fine; a contract it does not name, or a resolver that is not ChainRender's, is a **warn** saying how many bytes of code it has. Without `chain`, a **warn** that the code was not checked |

**Presentation findings** (client 0.20.0, Enhanced mode only: `reviewTree(tree, { mode: "enhanced" })` and the
builder's Review, from `presentationFindings()`; MCP 0.13.0's `chainrender_review` with `mode: "enhanced"`, and
`npx -y @chainrender/mcp review app.json --enhanced`).

| Rule | Severity | When |
|---|---|---|
| `style-token` | warn | a raw style token no family defines (no CSS matches it), or a family token on a node type it is not for |
| `label-as-style` | warn | an aria-label equal to one of the default theme's styling hooks (`dash-row`, `alert-*`, …), which a screen reader reads aloud; or an image whose alt text contains "chart" / "logo" (the theme sizes by it) with no `media` token |
| `heading-order` | warn | heading levels that skip (2 → 4), or levels with no level 1 |
| `scroll-region` | warn | a `scroll` box without role `region` and a label (the viewer makes only a labelled region keyboard-scrollable) |
| `lang-missing` | warn | opt-in (`langRequired: true`): a root with no `lang` |
| `v5-unavailable` | error | with `v5Available: false`: the tree compiles to VERSION_5 but the chain's RenderRouter has no VERSION_5 interpreter |

**Keep the context small.** The full vocabulary is about 83 KB of JSON (client 0.19), about 90 % of it the resolver-kind list. An AI
building one component rarely needs every kind: call `chainrender_vocabulary` with every section except
`resolverKinds`, then `chainrender_search_kinds` → `chainrender_describe_kind` for the data sources it actually binds.
Both lookups read the SDK's own `vocabulary()` on every call, so they cannot drift from it.

### Install & configure

```bash
npm install -g @chainrender/mcp   # published — installs the ChainRender MCP server
```

Add to your MCP client's config:

```json
{
  "mcpServers": {
    "chainrender": { "command": "chainrender-mcp" }
  }
}
```

`chainrender_verify`, `chainrender_doctor` and the review's `chain` read `https://chainrender.org/chains.json`, the
Addresses page and each chain's RPC. Override them with `CHAINRENDER_CHAINS`, `CHAINRENDER_ADDRESSES` and
`CHAINRENDER_RPC_<chainId>` in the server's `env`.

Now the AI can call the tools directly — the same grade/compile/validate loop, without pasting the vocabulary by
hand. The tools are thin wrappers over `@chainrender/client`; no logic is duplicated, so what the tools compute is
exactly what the chain computes.

## The app-builder skill — `chainrender-app-builder`

A **skill** (a `SKILL.md` plus worked examples) that teaches an AI agent *how* to build ChainRender apps well: the
non-negotiable workflow (vocabulary → compose → check → grade → compile → validate), the Grade-A rules, how to encode
resolver args, the toolchain for any Solidity it writes, the do's and don'ts, and request→app examples. Where the MCP server gives the AI the *tools*, the skill gives it the *method*.

Load it wherever your AI tooling discovers skills. It's plain Markdown — no build step. It pairs naturally with the
MCP server: the skill tells the agent the workflow, the MCP tools execute it.

## Reviewing without MCP

An AI that cannot run MCP tools (a chat model, Google AI Studio) cannot check its own work, so it must never call an app
"compliant". The same review is available to the person using it, with nothing installed beyond Node.js:

| Where | How |
|---|---|
| The visual builder | **Review** tab (and the header's Review badge). Under *Review a tree from somewhere else*, paste any tree as JSON and review it, or load it. **Copy report for AI** gives the plain-text report to paste back to the AI. |
| A terminal | `npx -y @chainrender/mcp review app.json` — the report, exit 0 (pass) or 1 (fail). `--chain sepolia` also checks addresses on that chain (with `eth_getCode`), `--json` prints the full result, `--strict` rejects builder authoring fields, `--enhanced` reviews it as an Enhanced (VERSION_5) app (a builder export of an Enhanced project is read as one). |

All three surfaces — these two and the `chainrender_review` tool — report the SDK's `reviewTree()` verdict (client
0.16.0): pass only when the tree check is clean, there is no honesty error and it compiles. Warnings do not fail it, but
each must be fixed or explained.

## The Claude Code plugin — `chainrender`

For Claude Code, one install gives the skill, the MCP server and a hook that enforces the loop:

```text
/plugin marketplace add rfikki/chainrender
/plugin install chainrender@chainrender
```

| Part | What it does |
|---|---|
| Skill | `chainrender-app-builder`, as above (a generated copy, kept identical by a test). |
| MCP server | `@chainrender/mcp` ^0.12.0 (plugin 0.1.1), started with `npx` (Node.js 20+). Before 0.1.1 the plugin pinned ^0.8.0, which on a 0.x version means 0.8.x only. |
| Stop hook | If the session used the tree tools (`check_node`, `grade`, `compile`, `validate`, `review`), Claude cannot finish until the last of them is a `chainrender_review` that returned `"pass": true`. |

What the hook does not do: it cannot see a tree edited by hand after the last review without a tool call, and honesty
warnings do not block (Claude must fix them or say why they are fine). It never traps you: on any error, or a second
stop with nothing changed, it lets Claude stop.

## How they fit together

```
skill (the method)  →  the AI follows the workflow
   +
MCP server (the tools)  →  the AI calls vocabulary / search_kinds / check_node / grade / compile / validate
   +
@chainrender/client (the SDK)  →  the single source of truth both wrap
   =
verifiable AI-built apps: graded, compiled, validated — never blind trust
```

## Docs for agents: `llms.txt`

The docs site publishes itself in the formats coding agents read: **`https://chainrender.org/docs/llms.txt`** (one
line per page: title, Markdown URL, first sentence), **`llms-full.txt`** (every page in one file), and a Markdown copy
of every page (append `.md` to its URL, or use the "Markdown" link in the top bar). Point an agent at `llms.txt`
instead of pasting rules into its prompt.

## Status

- **`@chainrender/client`** — **live on npm** (`npm install @chainrender/client`). **0.20.0** adds the Classic/Enhanced
  switch, the VERSION_5 presentation fields and the presentation review rules (docs/202). Enhanced output renders where
  the chain's RenderRouter has the VERSION_5 interpreter (Sepolia, Robinhood and Arc, 2026-11-02), and the viewer styles
  it (docs/202 phase 3). Classic stays the default. **0.20.1** fixes heading size tokens in the structure CSS; **0.21.0**
  adds `decompile()` (the builder's Fork). 0.19.x added viewer reads and transfer histories.
- **`@chainrender/mcp`** — **published on npm** (`npx -y @chainrender/mcp`). **0.12.0** depends on client ^0.19.0
  (viewer reads and transfer histories in review and grade); **0.12.1** lets `include` name `viewerReads` and
  `authoringBinds`; **0.13.0** depends on client ^0.20.0 and takes `mode` (`classic` / `enhanced`): the Enhanced
  vocabulary, the presentation review rules, `v5-available` in verify and the V5 check in doctor; it also moves to
  `@modelcontextprotocol/sdk` ^1.32.2 and `zod` ^4.6.6 (GHSA-mrhx-c7xc-m3w5).
  **0.13.1** changes only the server's instructions: the deploy-registry and remix rule from the start-here text.
  Earlier: 0.11.1 (unknown addresses worded from their code size), 0.11.0 (`stage-safe-area`), 0.9.0 (the `review`
  command line), 0.8.0 (`chainrender_verify`, `chainrender_doctor`, honesty findings and `pass`). The full history is
  the server's CHANGELOG.
- **`chainrender-app-builder` skill** — built (Markdown; ready to distribute).
- **`create-chainrender`** — **live on npm** (`npm create chainrender@latest my-app`).
- **Claude Code plugin `chainrender`** — in the repository's `plugins/chainrender`, listed by its
  `.claude-plugin/marketplace.json`.

## Related
- **[Building with AI](../guides/building-with-ai.md)** — the step-by-step workflow.
- **[Instructing an AI](./instructing-ai.md)** — prompt patterns.
- **[Building Correctly](../concepts/building-correctly.md)** — the on-chain paradigm the skill enforces.
- **[The Vocabulary](./vocabulary.md)** · **[The Trust Grade](../concepts/trust-grade.md)** — the grading the tools compute.
