# Page Management

> Compile, create, inspect, and safely edit storefront pages with the MCP v3 action routers

Canonical URL: https://0.0.0.0:3005/tools/page-management

Storefront pages are authored as source-format HTML and managed through four
MCP v3 tools:

| Tool | Responsibility |
|---|---|
| `lexsis_pages` | Read pages, inspect source, compile, diff, and run integrity checks |
| `lexsis_drafts` | Apply reversible source, section, island, head, and version changes |
| `lexsis_page_create` | Create a new draft page and return its preview |

To create or edit a page as files, sending only what changed, use
[`lexsis_build` or the Lexsis CLI](/tools/build) first. The actions below
remain as a fallback.
| `lexsis_live_ops` | Publish, unpublish, delete, or roll back after explicit approval |

Call `lexsis_discover` when an action or its current arguments are unfamiliar.
Former operation names such as `compile_page_source` remain searchable through
`lexsis_discover`, but they are not top-level tools on the consolidated
endpoint.

## Standard call shape

```json
{
  "name": "lexsis_pages",
  "arguments": {
    "action": "get",
    "args": {
      "page_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
    }
  }
}
```

Successful calls expose the selected router and action:

```typescript
{
  ok: true;
  tool: string;
  action: string;
  data: unknown;
  meta: {
    operation: string;
    surface_version: "3.0";
  };
}
```

Router-level validation and dispatch failures use:

```typescript
{
  ok: false;
  tool: string;
  action: string;
  error: {
    code: string;
    message: string;
    details?: unknown;
  };
}
```

Some underlying operation handlers can still return a domain error object
inside `data`. Treat either `ok:false` or `data.error` as failure.

## Create a page

Prefer `lexsis_build` action `commit` with `create`
([Page Files](/tools/build#create-a-page)). This flow is the fallback.

### 1. Resolve the store and theme

Use `lexsis_workspace` action `stores`, then `lexsis_brand` actions
`list_themes` and `get_theme`. Do not create a branded page if the selected
workspace has no valid theme.

### 2. Compile without saving

```json
{
  "name": "lexsis_pages",
  "arguments": {
    "action": "compile",
    "args": {
      "source": "<!-- section: hero --><section class=\"grid grid-cols-1 gap-8 lg:grid-cols-2\"><h1>Summer Collection</h1></section>",
      "head": { "title": "Summer Collection" },
      "theme_css": ":root { --lx-accent-color: #4b2e24; }"
    }
  }
}
```

Compilation returns structural validation plus the generated page styles:

```typescript
{
  ok: boolean;
  compile_issues: Array<{
    severity: "error" | "warning";
    check: string;
    section_id?: string;
    message: string;
  }>;
  validation_errors: string[];
  validation_warnings: string[];
  compile_id: string;
  bundle_hash: string;
  expires_at: string;
  local_preview_url: null;
  bundle_path: null;
  preview_status: {
    available: false;
    code: "DRAFT_REQUIRED";
    message: string;
  };
  section_count: number;
  styles: {
    compiled_page_css: string;
    style_manifest: {
      engine: "tailwindcss";
      compiler_version: string;
      input_version: number;
      input_sha256: string;
      candidate_count: number;
      css_bytes: number;
    };
    missing_candidates: string[];
  };
  page: object;
}
```

Fix every error and every missing Tailwind candidate before continuing.
Compilation is validation only: it does not save a page, upload a bundle, or
create a hosted preview. The short-lived compile artifact remains available for
30 minutes and can be passed directly to draft creation.

### 3. Create the draft

```json
{
  "name": "lexsis_page_create",
  "arguments": {
    "action": "create",
    "args": {
      "slug": "summer-collection",
      "source": "<!-- section: hero --><section class=\"grid grid-cols-1 gap-8 lg:grid-cols-2\"><h1>Summer Collection</h1></section>",
      "head": { "title": "Summer Collection" },
      "theme_css": ":root { --lx-accent-color: #4b2e24; }",
      "archetype": "landing",
      "theme_id": "theme-uuid",
      "workspace_id": "workspace-uuid",
      "store_id": "store-uuid",
      "publish": false
    }
  }
}
```

The consolidated create action is draft-only. It rejects `publish:true`.
Draft creation stores the exact validated bundle in shared object storage.
Verify the returned `/v/{slug}?preview=1` `preview_url`, then publish through
`lexsis_live_ops`. Production responses never use `/bundle/{hash}`; that route
is reserved for explicit local development and renderer parity tests.

## Edit an existing page

Prefer the [Lexsis CLI or `lexsis_build`](/tools/build#edit-a-page). The
V1 actions below remain as a fallback.

### 1. Resolve authoritative edit context

Always begin with `lexsis_pages` action `edit_context`:

```json
{
  "name": "lexsis_pages",
  "arguments": {
    "action": "edit_context",
    "args": {
      "page_id": "page-uuid"
    }
  }
}
```

The response identifies:

```typescript
{
  page_id: string;
  workspace_id: string;
  page_workspace_id: string;
  store_id: string;
  store_workspace_id: string;
  selected_workspace_id: string | null;
  workspace_consistent: boolean;
  shop_domain: string;
  theme_id: string | null;
  current_version: number;
  published_version_id: string | null;
  published_version: number | null;
  has_unpublished_changes: boolean;
  status: "draft" | "published" | "archived";
  source_available: boolean;
  product_binding: Record<string, unknown> | null;
  preview_url: string | null;
  corrective_action: string | null;
}
```

`page_id` is authoritative for existing-page edits. Normally omit `store_id`;
when supplied, it is an assertion that must match the page's resolved store.
Stop if `workspace_consistent` is false or `corrective_action` is non-null.

### 2. Read the smallest useful source

- `lexsis_pages` action `section_source` — preferred for one-section changes.
- `lexsis_pages` action `source` — use for multi-section or page-wide changes.

The `source` response also returns the immutable `page_version_id` UUID.
Use it when inspecting or preparing [Quiz capture](/tools/forms); the integer
`version`/`expected_version` used for edits is not interchangeable with that UUID.
Re-read source after an edit before preparing a policy for the new version.
- `lexsis_pages` action `content` — inspect the compiled representation.
- `lexsis_pages` action `inspect` — inspect section ordering and island usage.

### 3. Apply one atomic version

Use `lexsis_drafts` action `page_patch` for localized changes:

```json
{
  "name": "lexsis_drafts",
  "arguments": {
    "action": "page_patch",
    "args": {
      "page_id": "page-uuid",
      "expected_version": 6,
      "change_note": "Add trust icons after BuyBox",
      "changes": [
        {
          "operation": "insert_after_island",
          "section_id": "product-hero",
          "island_name": "BuyBox",
          "content": "<div class=\"grid grid-cols-4 gap-4\">...</div>"
        }
      ]
    }
  }
}
```

Supported patch operations:

| Operation | Required fields |
|---|---|
| `upsert_section` | `source`; optional `section_id` and `position` |
| `remove_section` | `section_id` |
| `move_section` | `section_id`, `position` |
| `update_island_props` | `section_id`, `island_name`, `props_patch`; optional `occurrence` |
| `insert_after_island` | `section_id`, `island_name`, `content`; optional `occurrence` |

Positions accept a zero-based index, `"first"`, `"last"`,
`{"before":"section-id"}`, or `{"after":"section-id"}`.

Other edit actions:

| `lexsis_drafts` action | Use it for |
|---|---|
| `page_replace` | Replace the complete source while preserving head, theme, and scripts |
| `page_update_section` | Compile and upsert exactly one source-format section |
| `page_remove_section` | Remove one section |
| `page_move_section` | Reorder one section |
| `page_update_head` | Update head, SEO, fonts, cart mode, or complete `theme_css`; source-backed theme changes recompile and atomically replace the page |
| `page_duplicate` | Create an independent draft copy |
| `page_variation` | Create an experiment-oriented page variation |

For source-backed pages, `page_update_head` detects `theme_css`, recompiles the
complete stored source, and writes through the atomic source-replacement path.
Direct backend head-only theme patching is not sufficient because it would
leave `compiled_page_css` stale.

### 4. Handle version conflicts

Pass the `current_version` returned by `edit_context` as `expected_version`.
If another edit wins first, the server returns a conflict with the new current
version. Re-read the source, reapply the intended change, and submit a new
patch. Never retry a stale patch blindly.

For retry-safe edits, use `lexsis_build` `commit` or `patch` with an
`idempotency_key` ([Page Files](/tools/build#conflicts-and-retries)).

### 5. Verify the result

Run:

1. `lexsis_pages` action `diff`
2. `lexsis_pages` action `integrity`
3. Browser QA with the calling agent at 390px, 768px, and 1280px

The MCP returns a preview URL but does not run a shared browser session.
The host agent is responsible for screenshots, computed-style inspection,
hover testing, console errors, and responsive verification.

## Shared sections

A shared section is one section, such as an entry pop-up, linked into many
pages. Edit it once, then sync every linked page.

1. Build the section on one page as usual, then make it shared:

```json
{
  "name": "lexsis_drafts",
  "arguments": {
    "action": "shared_section_create",
    "args": {
      "page_id": "page-uuid",
      "section_id": "entry-popup",
      "name": "Entry pop-up"
    }
  }
}
```

   The source page is linked at revision 1.

2. Add it to other pages with `shared_section_sync` and `page_ids`. Pages that
   don't have it yet get it at `position` (default: last); linked pages keep it
   where it is.

3. Edit it with `shared_section_update` (`source`, `name`, optional
   `expected_revision`). A new source bumps the revision and marks every
   linked page `stale`. Nothing on the pages changes yet.

4. Run `shared_section_sync` without `page_ids` to refresh every stale page.

Each sync writes one **draft** version per page through the same compile path
as `page_update_section`. Live pages keep serving the published version until
you publish them. Pages in a running experiment are skipped with
`reason: "running_experiment"`, whether or not they are linked yet.

Read with `lexsis_pages` actions `shared_sections` (list) and
`shared_section` (source, revision, and each linked page with `stale` and
`in_running_experiment`). `shared_section_detach` unlinks one page; the page
keeps its current copy as an ordinary section. Only source-backed pages can
share sections.

## Recover a missing bundle

Every page version normally has its compiled bundle attached. If a write saved
the source but attaching the bundle failed, use `lexsis_drafts` action
`page_attach_bundle`. It attaches an existing successful compile artifact to the
current version without creating a new version.

```json
{
  "name": "lexsis_drafts",
  "arguments": {
    "action": "page_attach_bundle",
    "args": {
      "page_id": "page-uuid",
      "compile_id": "compile-uuid",
      "expected_version": 9
    }
  }
}
```

`expected_version` must be the current version. You can also pass
`expected_source_sha256`. Use this only for recovery; normal edits attach their
bundle automatically.

## Published-page edits

Editing a published page creates a new non-live current version. Public
rendering continues to use `published_version_id` until a later successful
`lexsis_live_ops` action `publish` promotes the reviewed version.

Use `has_unpublished_changes` to detect when the current draft differs from the
live version. A failed republish preserves the previously published version.

## Publishing and deployment boundaries

`lexsis_live_ops` action `publish` marks the Lexsis page as published after
validation. It does not itself create or update a Shopify page.

The following are separate lifecycle concepts:

- **Draft preview** — renderer URL for an unpublished version.
- **Lexsis publish** — changes the Lexsis page status.
- **Standalone deployment** — publishes to Lexsis-hosted storefront delivery.

Lexsis never creates or updates Shopify `/pages`. The Lexsis storefront
renderer serves published pages.

The publish response can contain `url:null` when no public deployment URL has
been created. Continue using `preview_url` for QA in that case.

## Destructive operations

`lexsis_live_ops` requires explicit approval:

| Action | Effect |
|---|---|
| `publish` | Promote the reviewed page/version to published state |
| `unpublish` | Begin asynchronous removal from live delivery |
| `delete` | Permanently delete one or more unpublished pages |
| `rollback` | Move the page back to a selected previous version |
| `scale_winner` | Promote an experiment winner |

Unpublish a page and wait for completion before deleting it.

## Best practices

1. Resolve `edit_context` before every editing session.
2. Read and patch the smallest possible source unit.
3. Use one `page_patch` call for related changes so they produce one version.
4. Pass `expected_version`; add an idempotency key only when the selected
   action schema supports it.
5. Compile before creating and run integrity checks after editing.
6. Use Tailwind for structural and responsive styling.
7. Perform browser QA before every live operation and record it with
   [`page_record_qa`](/tools/page-qa).
8. Distinguish Lexsis publishing from Shopify deployment.

## Related

- [Page Files (lexsis_build)](/tools/build)
- [Page Source Contract](/pages/schema)
- [Page QA](/tools/page-qa)
- [Tool Reference](/tools/reference)
- [Publishing](/pages/publishing)
- [Theming](/pages/theming)
- [Styling Issues](/troubleshooting/styling-issues)
