# Connect Récit to an agent over MCP

**Goal:** install the Récit MCP server, register it in your agent over stdio, let the agent inspect
the deck format, validate and fix a three-slide Markdown story line by line, and preview or build
the saved file.

Récit never calls a model itself: your MCP host writes the Markdown while `@recit/mcp` answers with
deterministic format guides, JSON Schemas, and line-numbered diagnostics. For the complete list of
tools and resources, see [MCP server](/documentation/ai/mcp).

## 1. Install the server

In a project where `@recit/cli` (`recit`) is installed — for instance a folder created with
`create-recit`, see [Quickstart](/documentation/getting-started/quickstart) — add `@recit/mcp`, the
optional package that backs `recit mcp serve`:

```bash
npm install --save-dev @recit/mcp@next
```

If `@recit/mcp` is missing when an agent starts `recit mcp serve`, the CLI stops with
`recit mcp serve needs @recit/mcp, an optional package of the Récit CLI` and prints the install
command.

`recit mcp serve` speaks the Model Context Protocol over stdio (`stdout` is reserved for the
protocol) and loads the project's `recit.config.*` and Récit plugins from its root directory. Pass
`--root <dir>` to bound every path the tools may read or write (default: the current working
directory):

```bash
npx recit mcp serve --root .
```

Any tool path that resolves outside `--root`, traverses a hidden directory, or follows a symbolic
link out of `--root` is refused.

## 2. Register it in your agent

Wire `npx recit mcp serve` into your MCP host from the root of the project.

In **Claude Code**, register the local stdio server with `claude mcp add`:

```bash
claude mcp add recit -- npx recit mcp serve
```

In **opencode**, declare the server in `opencode.json` at the root of the project:

```json title="opencode.json"
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "recit": {
      "type": "local",
      "command": ["npx", "recit", "mcp", "serve"],
      "enabled": true
    }
  }
}
```

opencode prefixes each tool with the server name (`recit_describe_format`, `recit_validate_story`),
and `opencode mcp list` confirms the connection (`recit connected`). For hosts without MCP, see
[Agent Skills](/documentation/ai/skills) (`recit skills export`).

## 3. Let the agent read the format

Ask your agent to inspect the `deck` format before writing a slide. The agent calls
`describe_format` with `{"format": "deck"}`:

```json
{
  "format": "deck"
}
```

`describe_format` (`format` defaults to `"motion"` when omitted) returns two sections in one reply:

1. The deck Markdown authoring guide (the same text served by the `recit://guide/deck` resource):
   front matter fields, `---` scene separators with key-value attributes (`layout`, `cols`, `id`),
   layouts (`cover`, `grid`, `center`…), directives (`:::card`, `:::notes`…), and MDX rules.
2. `## JSON Schema of the typed source ({ "kind": "story", "format": "deck" })`, followed by the
   JSON Schema of the deck twin — plus `## Directives of the project's plugins (experimental)` when
   `recit mcp serve` finds Récit plugins in the project.

Each format guide is also a resource the agent can read directly (`recit://guide/deck`…). To write a
story **with** an author rather than for them, the agent reads `recit://guide/atelier` instead: the
guided writing workshop in nine steps, from the spark to the formats, where the author decides at
every gate and the agent keeps the state in `atelier.md`.

## 4. Write and validate a story

With the syntax in context, the agent drafts a three-slide story in memory and checks it with
`validate_story` before writing to disk (`validate_story` checks every format except motion films,
which use `validate_film`; pass exactly one of `markdown`, `json`, or `file`).

Suppose the agent's first draft sets an unknown `format: slides` key on line 3 of the front matter:

```yaml
---
title: Lorem Ipsum
format: slides
---
```

Calling `validate_story` with `{"markdown": "…"}` on that draft returns `isError: true` with the
1-based line number (`story.md:3`) and diagnostic code (`invalid-format`):

```text
✗ 1 error(s) in the deck
✖ story.md:3 — Unknown format "slides": install @recit/slides or update @recit/core and @recit/cli (known formats: deck, motion, docs, report, webtoon, book, roadmap, calendar, webstory, glossary, directory, atlas, form, mail). Falling back to deck. (invalid-format)
```

`deck` is the default story format, so a slide deck needs either `format: deck` or no `format` key
at all. Removing `format: slides` and calling `validate_story` again with `{"markdown": "…"}`
returns `✓ valid deck`.

No MCP tool writes a deck file to disk (only the motion film tools `build_film`, `apply_ops`, and
`extract` write film files under `--root`), so the agent saves `slides.md` with its own file tool:

```markdown title="slides.md"
---
title: Lorem Ipsum
---

--- layout=cover id=intro

# Lorem Ipsum

Dolor sit amet, consectetur adipiscing elit.

--- layout=grid cols=2 id=points

# Sed do eiusmod

:::card
### Tempor incididunt

Ut labore et dolore magna aliqua.
:::

:::card
### Ut enim ad minim

Quis nostrud exercitation ullamco.
:::

--- layout=center id=close

# Consectetur adipiscing

Duis aute irure dolor in reprehenderit.
```

The agent then verifies the file on disk (resolved inside `--root`) by calling `validate_story` with
`{"file": "slides.md"}`:

```json
{
  "file": "slides.md"
}
```

The server answers:

```text
✓ valid deck
```

Passing a path outside `--root` — such as `{"file": "../slides.md"}` — is refused with
`isError: true` and a message containing `outside the server root`.

## 5. Preview or build it

No MCP tool starts a dev server or bundles a static deck site (`render` in `@recit/mcp` renders
motion films to MP4). Preview `slides.md` locally with hot reload using `recit dev`:

```bash
npx recit dev slides.md
```

`recit dev slides.md` serves the three slides (`intro`, `points`, `close`) on
`http://localhost:3000` by default (`-p, --port <port>` to choose another port, `--open` to open a
browser) and updates the open slide live whenever you or the agent save `slides.md`.

When the deck is ready to publish, stop the dev server (`Ctrl+C`) and build a static bundle with
`recit build`:

```bash
npx recit build slides.md
```

By default, `recit build` writes `dist/index.html` and `dist/assets/` (`-o, --output <dir>` to pick
another output folder) and prints `✅ Built 3 slides in …/dist` (the absolute path of the folder).

## Check

1. Calling `describe_format` with `{"format": "deck"}` succeeds and returns the deck Markdown guide
   together with the JSON Schema for `{ "kind": "story", "format": "deck" }`. Reading the resource
   `recit://guide/atelier` returns the writing workshop and its nine steps.
2. Calling `validate_story` with `{"markdown": "…"}` when `format: slides` is on line 3 of the front
   matter returns an error (`isError: true`) naming `story.md:3` and `(invalid-format)`.
3. Removing `format: slides`, validating the Markdown with `validate_story`, writing `slides.md`
   inside `--root`, and calling `validate_story` with `{"file": "slides.md"}` returns
   `✓ valid deck`, while a path outside `--root` (`{"file": "../slides.md"}`) is refused with
   `outside the server root`.
4. Running `recit dev slides.md` serves the three slides (`Lorem Ipsum`, `Sed do eiusmod`,
   `Consectetur adipiscing`), and running `recit build slides.md` exits with `0` and writes
   `index.html` and `assets/` into `dist/`.

## See also

- **[MCP server](/documentation/ai/mcp)** — full reference of the tools and `recit://guide/*`
  resources in `@recit/mcp`.
- **[Agent Skills](/documentation/ai/skills)** — export the same guides as `SKILL.md` folders or
  `.opencode/agent/` roles with `recit skills export`.
- **[Write and present your first deck](/documentation/guides/first-deck)** — keyboard navigation,
  live-reload editing, and static deck builds.
- **[CLI](/documentation/reference/cli)** — options for `recit mcp serve`, `recit validate`,
  `recit dev`, and `recit build`.
