mcp-magento-cms
v1.4.0
Published
Cursor MCP: Magento CMS pages/blocks + custom-entity Page Builder fields (case study/product/category) + compose/validate/repair (zero npm deps)
Downloads
288
Readme
Magento CMS MCP (Cursor)
Create/update Magento CMS Pages / Blocks with Page Builder from Cursor chat — including validate/repair for stage-safe HTML and raw Page Builder HTML saves for complex layouts.
- AI: Cursor plans content and diagnostics
- This server: Magento REST via Integration Access Token
- Local: run from this repo path in
mcp.json(pointMAGENTO_BASE_URLat the target store) - Published:
npx -y mcp-magento-cms(npm)
Requires Node.js 18+ and Cursor.
CMS workflow (mandatory for agents & teams)
Use this MCP as the only way to create or update Magento CMS pages/blocks.
| Do | Do not |
|----|--------|
| pagebuilder_rules → compose_pagebuilder / create_cms_page / set_pagebuilder_html | Project PHP tools/compose-*.php / deploy-*.php |
| validate_pagebuilder / repair_pagebuilder before save | Direct DB edits to cms_page / cms_block content |
| Improve this package when something is missing or wrong | Bypass MCP with one-off scripts |
Preferred path: sections[] → compose_pagebuilder (or create_cms_page with sections) → validate → save. Use set_pagebuilder_html only for intentional raw master HTML. After save, verify on the storefront.
Reload/restart the MCP server in Cursor after changing this package so teammates pick up new rules and tools.
REST field note (Magento 2.4.8): cmsPage create/update use active (not is_active) and reject store_id / unknown fields. The client maps is_active → active so tool args stay familiar.
Store views: Magento REST cannot set cms_page_store / cms_block_store. On create, this MCP assigns All Store Views (store_id = 0) by default via Magento PHP (scripts/assign-stores.php + ddev exec when .ddev exists). Pass store_ids: [1, 2] (etc.) only when the user asks for specific store view(s). Requires MAGENTO_ROOT (or infer from MAGENTO_CMS_PROJECT_RULES → project root).
Page layout: On create, default page_layout is cms-full-width (admin label: Page — Full Width). Pass page_layout only when the user asks for a different layout (e.g. 1column).
Shared rules (all projects — read first)
Returned by pagebuilder_rules for every store. This package stays free of store-specific hex / class catalogs; those go in optional project rules.
Page Builder (stage-safe)
- Rows: use Full Width or Contained. Never Full Bleed unless the user explicitly asks.
- When edge-to-edge hero is intentional:
allow_full_bleed=trueon validate/set/repair. full-widthrows MUST include.row-full-width-inner[data-element=inner].containedrows MUST include[data-element=inner].- Converting
full-bleed→full-widthwithout adding the inner wrapper breaks admin Page Builder. - Every
[data-pb-style=ID]in<style>must match an element — orphans crash the stage. - Every column needs
width:%in the style block. - Avoid raw
<svg>inside Text — use Image (or theme CSS) for icons. - Hero CTAs: Banner Show Button=Always + Link URL.
- Links: prefer
{{store url=path}}with an unquoted path (avoid"in href). - Prefer native content types; CMS body = page content only (layout owns chrome).
CMS media + theme conventions (all projects)
- One flat media folder per CMS page under
pub/media/wysiwyg/— nocards/,icons/,products/,related/subfolders. - Folder name = CMS page URL key (identifier), e.g.
wysiwyg/markets/market-industrial/hero.jpg. - After renaming media folders, update all
{{media url=…}}incms_page/cms_block, then flush cache. - Sibling pages share one Magento_Cms LESS partial + shared classes — do not copy near-identical LESS into theme
_sources.lessper page. - Page-only LESS → theme
Magento_Cms/web/css/source/+_module.lessimport. - Brand primary/secondary once in
_theme.less(@theme__color__primary/@theme__color__secondary); use vars, not hex, in page LESS. - No module-level re-aliases of theme vars; no redundant
font-familywhen body already uses the theme base font. - Scope page CSS with layout body class and/or content markers (
:has(.…)).
Use tools pagebuilder_rules, validate_pagebuilder, and repair_pagebuilder.
Per-store project rules (optional)
Keep the published MCP general. Put store-specific values (brand hex, Vendor/theme, URL keys, class prefixes) in the Magento project, not in this package.
Recommended (project-wise Cursor config):
- Commit
.cursor/magento-cms-project-rules.jsonin the Magento repo. - Add project MCP config at
.cursor/mcp.json(Customize → MCPs → workspace) withMAGENTO_ROOTonly — rules auto-load from${MAGENTO_ROOT}/.cursor/magento-cms-project-rules.json.
{
"mcpServers": {
"magento-cms": {
"command": "npx",
"args": ["-y", "mcp-magento-cms"],
"env": {
"MAGENTO_BASE_URL": "https://your-store.example/",
"MAGENTO_ACCESS_TOKEN": "${env:MAGENTO_ACCESS_TOKEN}",
"MAGENTO_ROOT": "${workspaceFolder}"
}
}
}
}Optional override: MAGENTO_CMS_PROJECT_RULES=/path/to/file.json if the rules file is not under .cursor/.
pagebuilder_rules appends project rules after shared rules. JSON shape:
{
"rules": ["store-only convention"],
"detail": { "brand_tokens": "optional longer notes" }
}Markdown/text files are also supported (one rule per non-empty, non-# line). Projects with no rules file still get all shared conventions.
Compose with sections[]
Prefer structured trees over project-specific PHP. Theme CSS class names go in css_classes (project owns naming).
// Tool: compose_pagebuilder OR create_cms_page({ title, sections })
{
"sections": [
{
"type": "row",
"appearance": "full-bleed",
"children": [{
"type": "banner",
"background_image": "{{media url=wysiwyg/hero.jpg}}",
"content_html": "<h1>Title</h1>",
"show_button": "always",
"button_text": "Contact",
"link_url": "#contact"
}]
},
{
"type": "row",
"appearance": "contained",
"children": [
{ "type": "heading", "text": "Section", "heading_type": "h2" },
{ "type": "text", "html": "<p>Body</p>" },
{
"type": "columns",
"columns": [
{ "children": [
{ "type": "image", "src": "{{media url=wysiwyg/a.jpg}}", "alt": "A" },
{ "type": "text", "html": "<p>Card</p>" }
]}
]
},
{ "type": "buttons", "items": [{ "text": "Shop", "url": "{{store url=shop}}" }] },
{ "type": "divider" },
{ "type": "products", "skus": ["SKU1", "SKU2"] },
{ "type": "block", "identifier": "my-cms-block" }
]
}
]
}Native types: row, columns / column-group / column, text, heading, image, buttons, banner, html, divider, video, map, tabs, slider, products, block.
Call list_section_types for the full parameter catalog. For intentional edge-to-edge heroes use appearance: "full-bleed" and allow_full_bleed: true on save.
Tools
| Tool | Purpose |
|------|---------|
| magento_health | Test base URL + token |
| pagebuilder_rules | Return Full Width / inner / orphan-style rules |
| list_section_types | Native element catalog + composition patterns |
| compose_pagebuilder | Build master-format HTML from sections[] (all PB types); optional save |
| search_cms | Find pages/blocks by identifier |
| get_cms_page / get_cms_block | Load entity (include_content, validate) |
| validate_pagebuilder | Stage-safety checks (html / page_id / block_id) |
| repair_pagebuilder | Fix orphans, full-bleed, inners, widths, SVG (apply=true to save) |
| set_pagebuilder_html | Save raw PB HTML without wiping to simple_text |
| create_cms_page / update_cms_page | Simple Row→Text composer |
| create_cms_block / update_cms_block | Simple Row→Text composer |
| set_entity_pagebuilder_html | Save PB HTML into non-CMS fields (case study, product/category attributes, flat text columns). Requires MAGENTO_ROOT. |
Important: update_cms_page / update_cms_block with content rebuild as simple_text only. For complex pages use set_pagebuilder_html or repair_pagebuilder with apply=true.
Custom entity Page Builder fields (case studies, PDP, categories, …)
When Page Builder lives on a custom module column (or catalog attribute) instead of cms_page / cms_block:
// Tool: set_entity_pagebuilder_html
{
entity: "casestudy", // or "product" + sku, or "category"
entity_id: 17,
field: "challenges", // admin PB field / DB column
sections: [ /* same tree as compose_pagebuilder */ ],
// html: "<div data-content-type=...>" // alternative to sections
}Presets: casestudy → brainvire_case_studies; product / category → Magento repositories. Or pass table + entity_id + field for other flat modules. Still call pagebuilder_rules / validate first — this tool compose+repairs+validates before writing.
Local Cursor config (this machine)
{
"mcpServers": {
"magento-cms": {
"command": "node",
"args": [
"/home/[email protected]/htdocs/mcp-magento-cms/src/index.js"
],
"env": {
"MAGENTO_BASE_URL": "https://your-store.ddev.site",
"MAGENTO_ACCESS_TOKEN": "YOUR_TOKEN",
"NODE_TLS_REJECT_UNAUTHORIZED": "0"
}
}
}
}After changing this package, reload MCP in Cursor (Settings → MCP → refresh / restart).
Setup (published npx)
1. Magento Integration Access Token
- System → Extensions → Integrations → Add New Integration
- API → Custom → Content → Pages (Save/Edit Design) + Blocks
- Activate → copy Access Token
Enable Bearer tokens (2.4.4+):
bin/magento config:set oauth/consumer/enable_integration_as_bearer 1
bin/magento cache:flush config2. mcp.json with npx
{
"mcpServers": {
"magento-cms": {
"command": "npx",
"args": ["-y", "mcp-magento-cms"],
"env": {
"MAGENTO_BASE_URL": "https://www.example.com",
"MAGENTO_ACCESS_TOKEN": "YOUR_INTEGRATION_ACCESS_TOKEN"
}
}
}
}Local ddev TLS: add "NODE_TLS_REJECT_UNAUTHORIZED": "0".
Scripts
npm run test:compose
npm run test:validate
npm run healthVersion
1.2.0 — compose all native Page Builder content types via sections[] + validate/repair/raw HTML.
