# add_plan_steps

URL: https://codepanel.ai/docs/mcp-server/add_plan_steps

The CodePanel MCP tool that adds steps to a saved plan after a named step or at the end, keeping every existing step ref (S1, S2) unchanged.

`add_plan_steps` adds steps to a saved plan, either after a step you name or at the end. New steps get new numbers and no existing ref ever changes, so `S2` still means the same step after you insert something before it. It needs the `reviews:write` scope, and it works only where the deployment has plan tracking turned on.

## When to call it

- **When you learn the plan was incomplete,** such as a review finding that needs a test. Pass a `reason`; it is kept in the history, so the next session can see why the plan grew.
- **When a plan was created without steps,** and `nextAction` says `add_steps`.
- **When a finished plan needs more work.** Adding a step to a `completed` plan reopens it as `active`.

It can't add steps to an `abandoned` plan. Reactivate the plan with [`update_plan`](/docs/mcp-server/update_plan) first.

## Inputs

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `planId` | string | yes | Plan id, from list_plans or create_plan |
| `steps` | array of objects, at most 200 | yes |  |
| `steps[].title` | string, at most 200 characters | yes |  |
| `steps[].detail` | string | no | How to do it, files, constraints |
| `steps[].acceptance` | string | no | What must be true for it to count as done; marking it done then needs evidence |
| `after` | string | no | Insert after this step; default the end |
| `reason` | string | no | Why the plan changed |
| `agent` | string | no | Your agent name, kept in the plan's history |

It writes: the server marks it `readOnlyHint: false`, so a client that asks before writes asks here.

### Step refs

A ref is `S` and a number, and each plan counts its own from `S1`. The number is given once, when the step is created, and never reused or renumbered. `S3` can sit between `S1` and `S2`. The `after` input takes a ref, and `S3`, `s3` and `3` all mean the same step. An unknown ref fails with `Tracked plan step S9 not found`.

The order of the steps in a plan decides what `nextAction` points to, not the number. That is why `after` exists: put the new step where it should happen, and the ref follows the order of creation.

Limits: a plan holds at most 200 steps in all (`A plan holds at most 200 steps; split it into sub-plans`), and one call adds at least 1 and at most 200. `reason` is at most 2,000 characters. Each step is `{ title, detail?, acceptance? }` as in [`create_plan`](/docs/mcp-server/create_plan).

With plan tracking off on the deployment, the call fails with `CodePanel: Plan tracking is off on this deployment (PLAN_TRACKING)`.

## What it returns

The whole plan, as [`get_plan`](/docs/mcp-server/get_plan) returns it. The history gets one `steps_added` entry whose `to` lists the new refs (`S3`, or `S3, S4`) and whose `reason` is the one you passed. `progress.pending` goes up by the number of steps added.

## Examples

These responses come from a test account on a local backend, trimmed to the first history entry.

### Insert a step after `S1`

```json title="Call"
{
  "planId": "xd7ffsskhwq6bg3ff59ptazsh98j7xjs",
  "steps": [
    {
      "title": "Add a regression test for spoofed headers",
      "acceptance": "bun test passes with the new case"
    }
  ],
  "after": "S1",
  "reason": "F1 needs a test that would have caught it",
  "agent": "claude-code"
}
```

```json title="Result (trimmed)"
{
  "createdAt": 1794614635238,
  "goal": "Make the login limit apply per client, not per X-Forwarded-For value",
  "history": [
    {
      "agent": "claude-code",
      "at": 1794614643652,
      "detail": null,
      "from": null,
      "id": "x57e3pyr8wn82n35a61brrvje98j7g48",
      "kind": "steps_added",
      "reason": "F1 needs a test that would have caught it",
      "step": null,
      "to": "S3"
    }
  ],
  "nextAction": {
    "action": "start",
    "planId": "xd7ffsskhwq6bg3ff59ptazsh98j7xjs",
    "reason": "it is the next pending step",
    "step": "S1",
    "steps": []
  },
  "parentPlanId": null,
  "parentStep": null,
  "planId": "xd7ffsskhwq6bg3ff59ptazsh98j7xjs",
  "progress": {
    "blocked": 0,
    "done": 0,
    "inProgress": 0,
    "pending": 3,
    "skipped": 0,
    "total": 3
  },
  "repo": "codepanel-dev/web-app",
  "status": "active",
  "steps": [
    {
      "acceptance": "A test sends ten requests with different X-Forwarded-For values and the eleventh is refused",
      "completedAt": null,
      "detail": "src/server/auth/rateLimit.ts:48",
      "evidence": null,
      "reason": null,
      "ref": "S1",
      "status": "pending",
      "subplans": [],
      "title": "Key the limiter on the trusted hop",
      "updatedAt": 1794614635238
    },
    {
      "acceptance": "bun test passes with the new case",
      "completedAt": null,
      "detail": null,
      "evidence": null,
      "reason": null,
      "ref": "S3",
      "status": "pending",
      "subplans": [],
      "title": "Add a regression test for spoofed headers",
      "updatedAt": 1794614643652
    },
    {
      "acceptance": null,
      "completedAt": null,
      "detail": null,
      "evidence": null,
      "reason": null,
      "ref": "S2",
      "status": "pending",
      "subplans": [],
      "title": "Run INCR and EXPIRE atomically",
      "updatedAt": 1794614635238
    }
  ],
  "title": "Fix rate limiter bucket key",
  "updatedAt": 1794614643652
}
```

The new step is `S3`, listed between `S1` and `S2`, because it was inserted after `S1`. `S1` and `S2` kept their refs. `nextAction` still says to start `S1`.

## The same step without MCP

| Surface | Form |
| --- | --- |
| HTTP API | [`POST /plans/steps`](/docs/api#post-planssteps) with the same fields |

The CLI has no command for it: `codepanel plan create` takes the steps when the plan is made.

## What the server tells your agent

The description your agent reads when it lists the tools:

> Add steps to a plan: after a named step, or at the end. New steps get new numbers; existing refs never change. Give a reason when the plan is being revised; it is kept in the history. A completed plan reopens. Returns the plan: planId, status (active, completed, abandoned), progress, steps (ref like S3, status pending|in_progress|done|blocked|skipped, acceptance, evidence, reason, subplans), history (newest first, with deviations and reasons) and nextAction. Act on nextAction: start or continue its step (in its planId, which may be a sub-plan), unblock its steps, add_steps, or done.

## Related

- [`create_plan`](/docs/mcp-server/create_plan): start a plan with its first steps.
- [`update_plan_step`](/docs/mcp-server/update_plan_step): edit a step's text or status.
- [`update_plan`](/docs/mcp-server/update_plan): reactivate an abandoned plan.
- [Tracked plans](/docs/api#tracked-plans): the rules, in the HTTP API reference.
