bricks_replace_section

Phase 4AdvancedComplexity: 8/10
Replace an existing section with new content

Overview

Replace an existing section on a Bricks page with entirely new content. The tool identifies the section by its root element ID and removes it along with all its child elements, then inserts the new section tree in its place. Uses the same simplified JSON format as bricks_add_section.

This is useful for redesigning a specific section without affecting the rest of the page. The old section is completely removed — there is no merge or partial update.

Key Features

Atomic Replacement
Removes the old section and all descendants, then inserts the new content in the exact same position. Other sections are not affected.
Same JSON Format
Uses the same simplified hierarchical JSON as bricks_add_section, so you can reuse section patterns.
Position Preservation
The new section is placed at the same position in the page as the old one, maintaining section order.

When to Use

You need to completely redesign a specific section of a page
The existing section has too many issues to fix individually with bricks_update_element
You want to rebuild a section with a different layout (e.g., change from 2-column to 3-column)
You are iterating on a design and want to replace the current version with an improved one
Prerequisites
The page and section must exist. Use bricks_get_page_content to find the section root element ID (6-char hex string). The section ID is the ID of the root section element (type: "section") at the page root level.

When NOT to Use

You only need to update one or two elements in a section (use bricks_update_element instead)
You want to add a new section without removing anything (use bricks_add_section instead)
You want to remove a section without adding a replacement (use bricks_delete_section instead)
You need to update multiple elements with small changes (use bricks_bulk_update_elements instead)

Parameters

3 Total Parameters3 Required
page_idnumberREQUIRED
Target page ID containing the section to replace.
section_idstringREQUIRED
The 6-char Bricks element ID of the section root element to replace. Use bricks_get_page_content to find this.
sectionobjectREQUIRED
The new section element tree in hierarchical JSON format. Same format as bricks_add_section.

Code Examples

Replace a hero section with a new design

Find the old hero section ID, then replace it with an updated version.

JSON
// Step 1: Find the section ID
bricks_get_page_content({ page_id: 42, mode: "summary" })
// Returns section with id: "a1b2c3"

// Step 2: Replace the section
bricks_replace_section({
  page_id: 42,
  section_id: "a1b2c3",
  section: {
    type: "section",
    ref: "new-hero",
    settings: { "_padding": { "top": "140", "bottom": "140" } },
    children: [{
      type: "container",
      settings: { "_width": "1200px" },
      children: [
        { type: "heading", settings: { tag: "h1", text: "New Hero Title" }, globalClasses: ["text-display"] },
        { type: "text-basic", settings: { text: "Updated subtitle." }, globalClasses: ["text-body"] }
      ]
    }]
  }
})
Response
{
  "success": true,
  "element_ids": { "new-hero": "x9y8z7" },
  "elements_count": 4
}

Common Mistakes

Using the wrong element ID (child instead of section root)
The section_id must be the root section element (parent: 0). Use bricks_get_page_content in summary mode to find root-level section IDs.
Wrong
bricks_replace_section({
  page_id: 42,
  section_id: "def456",  // This is a container, not the section!
  section: { ... }
})
Correct
// Find root sections first
bricks_get_page_content({ page_id: 42, mode: "summary" })
// Use the section-type element at root level
bricks_replace_section({
  page_id: 42,
  section_id: "abc123",  // Root section element
  section: { ... }
})

Tips & Warnings

Tips & Warnings

Complete replacement: This tool removes ALL children of the old section. Any element IDs from the old section become invalid. If other tools reference those IDs, they will fail.

Same payload limits apply: Keep the replacement section under 30-40 elements, just like bricks_add_section.

Find section IDs: Use bricks_get_page_content({ mode: « summary » }) and look for elements with type: « section » and parent: 0.

Return Values

FieldTypeDescription
successbooleanWhether the replacement was successful.
element_idsobjectMap of ref names to new element IDs for the replacement section.
elements_countnumberNumber of elements in the new section.

Related Tools

Technical Details

Tool ID
bricks_replace_section
API Endpoint
/bricks-mcp/v1/pages/{page_id}/sections/{section_id}
HTTP Method
PUT
Namespace
pages-elements
Source File
pages/sections.ts
Version
1.0
Min Bricks Version
1.9
Requires Auth
Yes

Changelog

v1.0
Initial release with atomic section replacement and position preservation.
20250101