MCP: theme code
The MCP tools for a theme's files: the Liquid reference, reading, searching, writing and editing files, assets, validation and file history.
For theme developers: the Liquid this engine supports, and the tools that read, write, edit, check and restore a theme's files. Every change lands in the draft.
This page lists 17 tools. How to read each entry, the website argument, permissions, publishing, errors and limits are on MCP reference.
list_theme_files
List the files of the active theme's draft, as the code editor shows them, one page at a time. "prefix" keeps only the paths that start with it (for example "sections/" or "snippets/card"). Each item: "path", "size" (bytes), "kind", "sha256", "versionId" (pass it as base_version to write, rename or delete the file), "inDraft" (the draft changes it and it is not published yet) and "protected" (the theme needs it: it can be edited, never deleted or renamed).
- Permission: Themes · Code
- Read-only
| Argument | Type | Required | Description |
|---|---|---|---|
prefix |
string | No | Only the paths that start with this text. The top folders are: layout, sections, blocks, snippets, templates, config, locales, assets, data-lists, forms, workflows, routes, link-lists, section-icons, block-icons, site-files. |
page |
integer | No | The page to read, from 1. Default 1. (min 1) |
per_page |
integer | No | How many items a page holds, at most 100. Default 25. (min 1; max 100) |
read_theme_file
Read one file of the active theme's draft by its path, as list_theme_files names it. A text file (Liquid, JSON, CSS, JS, SVG...) answers "content"; an image or font answers "url" (where it is served; null with a "message" when it has no address yet), never its bytes. "versionId" is the version you read: pass it as base_version to write_theme_file, rename_theme_file or delete_theme_file. "inDraft" says the draft changes the file and it is not published yet. view "published" reads the live file instead: when get_draft_status marks a file changedUnderneath (publish refuses it), read it this way, review what changed, then write your version with this versionId as base_version.
- Permission: Themes · Code
- Read-only
| Argument | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | The file's path, for example "sections/header.liquid". |
view |
string | No | "draft" (default): the file as the draft holds it. "published": the live file. (one of draft, published) |
write_theme_file
Write the whole content of one text file of the active theme, in the theme's draft, not live (publishing is separate). Creates the file when it does not exist: leave base_version out only then. To change a file, pass base_version as read_theme_file or list_theme_files answered "versionId"; a conflict means the draft changed since you read it: read it again and retry. For a file get_draft_status marks changedUnderneath, read it with view "published" and pass that versionId once you have reviewed it. A file that would not render (broken Liquid, invalid JSON) is refused with what is wrong in it, and nothing is saved. Answers the path and the new "versionId". Images and fonts cannot be written here.
- Permission: Themes · Code
| Argument | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | The file's path, for example "snippets/price.liquid". |
content |
string | Yes | The whole new content of the file. |
base_version |
integer | No | The "versionId" you read; leave it out for a new file. (min 1) |
message |
string | No | A short note the file's history shows beside this version. |
edit_theme_file
Change part of one text file of the active theme, in the theme's draft, not live (publishing is separate), without sending the whole file. Each edit replaces "old" with "new"; "old" must be the exact text (whitespace and line breaks included) and appear exactly once in the file, or set replace_all to replace every place it appears. Edits apply in order, each to the file as the edits before it left it. A refused edit is named by its index and nothing is saved. Pass base_version as read_theme_file or list_theme_files answered "versionId"; a conflict means the draft changed since you read it: read it again and retry. A file get_draft_status marks changedUnderneath cannot be edited on its live version: resolve it with write_theme_file (the whole file, base_version the live versionId), then edit it here. A file that would not render (broken Liquid, invalid JSON) is refused with what is wrong in it, and nothing is saved. Answers the path, the new "versionId" and "changedLines" (the first and last line of the new file the edits changed). To create a file, use write_theme_file.
- Permission: Themes · Code
| Argument | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | The file's path, for example "sections/header.liquid". |
base_version |
integer | Yes | The "versionId" you read. (min 1) |
edits |
array of object | Yes | The changes, applied in order, at most 50. (at least 1 items; at most 50 items) |
edits[].old |
string | Yes | The exact text to replace; not empty. |
edits[].new |
string | Yes | The text to put in its place; empty removes it. |
edits[].replace_all |
boolean | No | Replace every place "old" appears. Default false: "old" must appear exactly once. |
message |
string | No | A short note the file's history shows beside this version. |
rename_theme_file
Move one file of the active theme to a new path, in the theme's draft, not live. Pass base_version as read_theme_file or list_theme_files answered "versionId"; a conflict means the draft changed since you read it: read it again and retry. Files the theme needs ("protected") cannot be renamed. Whatever names the old path (a {% render %}, a template's section type) stops finding it: run validate_theme afterwards. Answers the new path and its "versionId".
- Permission: Themes · Code
- Destructive
| Argument | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | The file's current path. |
to |
string | Yes | The new path. |
base_version |
integer | Yes | The "versionId" you read. (min 1) |
delete_theme_file
Delete one file of the active theme, in the theme's draft, not live: visitors keep it until the draft is published, and the file's history can bring it back. Pass base_version as read_theme_file or list_theme_files answered "versionId"; a conflict means the draft changed since you read it: read it again and retry. Files the theme needs ("protected") cannot be deleted. Answers the path and the deletion's "versionId".
- Permission: Themes · Code
- Destructive
| Argument | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | The file's path. |
base_version |
integer | Yes | The "versionId" you read. (min 1) |
validate_theme
Check the whole draft of the active theme, as the code editor's problems list does: broken Liquid or JSON, a {% render %} of a snippet that does not exist, placeholder text the site was made with, and the code editor's other rules. Changes nothing. Answers "diagnostics" (each with "path", "line", "column", "severity", "code" and "message") and "counts" by severity. Only errors can block a publish.
- Permission: Themes · Code
- Read-only
No arguments, other than website on a connection.
get_liquid_reference
Read the Liquid this website's theme engine supports before you write theme code with write_theme_file: "tags" (tag names), "filters" (each "name" with "minArgs", "maxArgs" and "keyword", null where the engine states none), "objects" (the global objects every template sees), "properties" (for the objects themes use most: where a theme reaches each, its properties and a note) and "rules" (the authoring guide: each "rule" and the validate_theme diagnostic "code" that reports it, null for a convention no check sees). Anything outside these lists is not supported, whatever Shopify supports. Call validate_theme after writing.
- Permission: Themes · Code
- Read-only
No arguments, other than website on a connection.
search_theme_code
Search the active theme's text files (Liquid, JSON, CSS, JS, SVG) for a literal text, ignoring case, one page of matches at a time. Each match: "path", "line", "column" and a short "preview" of the line ("previewColumn" is where the match starts in it). "truncated" true means there were more matches than are answered (at most 500, 20 per file): search for something more specific. "partial" true means the search stopped before reading every file. view "published" searches the live files instead of the draft.
- Permission: Themes · Code
- Read-only
| Argument | Type | Required | Description |
|---|---|---|---|
q |
string | Yes | The text to find, on one line, at most 200 characters. |
view |
string | No | "draft" (default): the draft's files. "published": the live files. (one of draft, published) |
page |
integer | No | The page to read, from 1. Default 1. (min 1) |
per_page |
integer | No | How many items a page holds, at most 100. Default 25. (min 1; max 100) |
get_file_references
List the files one Liquid file of the active theme uses: each {% render %}, {% include %}, {% section %}, {% sections %} and {% extends %} with a literal name, as "line", "tag", "name", "target" (the file it resolves to, for example "snippets/card.liquid") and "exists" (false: the file is missing, so the page breaks there). Any other kind of file answers no references. view "published" reads the live file instead of the draft.
- Permission: Themes · Code
- Read-only
| Argument | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | The file's path, for example "sections/header.liquid". |
view |
string | No | "draft" (default): the file as the draft holds it. "published": the live file. (one of draft, published) |
list_file_versions
List the saved versions of one file of the active theme, newest first, one page at a time: each with its "id", "deleted" (the version is a deletion), "source" (code_editor, visual_editor, mcp, restore, install, update...), "actorLabel" (who saved it), "message" and "createdAt". Every save of the draft and every publish is a version. get_file_version reads one, compare_file_versions shows what changed between two, and restore_theme_file puts one back into the draft.
- Permission: Themes · Code
- Read-only
| Argument | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | The file's path, for example "sections/header.liquid". |
page |
integer | No | The page to read, from 1. Default 1. (min 1) |
per_page |
integer | No | How many items a page holds, at most 100. Default 25. (min 1; max 100) |
get_file_version
Read one saved version of a file of the active theme by its "id" (from list_file_versions): "version" (as list_file_versions describes it), and for a text file its "content" and "sha256". An image or font answers its "sha256" only, never its bytes; a deletion answers null for both. To put it back, use restore_theme_file.
- Permission: Themes · Code
- Read-only
| Argument | Type | Required | Description |
|---|---|---|---|
version_id |
integer | Yes | The version's "id", from list_file_versions. (min 1) |
compare_file_versions
Show what changed between two versions of one text file of the active theme (ids from list_file_versions), as a unified diff ("diff": lines starting with "-" were removed, "+" added, 3 lines of context around each change). Both versions must be of the same file. A diff longer than about 100 KB is cut at a line's end and answers "truncated": true; compare closer versions, or read each with get_file_version.
- Permission: Themes · Code
- Read-only
| Argument | Type | Required | Description |
|---|---|---|---|
from_version_id |
integer | Yes | The older version's "id". (min 1) |
to_version_id |
integer | Yes | The newer version's "id". (min 1) |
restore_theme_file
Put an earlier version of one file of the active theme (its "id" from list_file_versions) back into the theme's draft, not live: visitors see it once the draft is published. The draft's current version of the file stays in its history. A deletion cannot be restored this way; a version of another file is refused. Answers the path and the new "versionId".
- Permission: Themes · Code
| Argument | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | The file's path. |
version_id |
integer | Yes | The "id" of the version to put back, from list_file_versions. (min 1) |
discard_draft_file
Drop the draft's change of one file of the active theme, so the file is the live one again (a file only the draft added is removed). The draft is shared: this drops whoever made that change, so only do it to your own change or when asked. Visitors see no difference. The dropped version stays in the file's history (list_file_versions, restore_theme_file). Answers "discarded" (false, with a "message", when the draft had no change of that file) and the draft as get_draft_status does.
- Permission: Themes · Code
- Needs May publish theme changes · Destructive
| Argument | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | The file's path, as get_draft_status lists it. |
upload_theme_asset
Upload an image, font or SVG into the active theme's draft (not live until the draft is published) from its bytes in base64, at a path in assets/, for example "assets/hero.webp". Extensions: svg, png, jpg, jpeg, webp, gif, woff, woff2, ico; at most 10240 KB. The content must be what the extension says; an SVG is cleaned of scripts. To replace a file the theme has, pass its "versionId" (from list_theme_files) as base_version. Liquid, CSS, JS and other text files are written with write_theme_file instead. A theme refers to an asset with {{ 'hero.webp' | asset_url }}. Answers the file as list_theme_files lists it.
- Permission: Themes · Code
| Argument | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | Where the file goes, in assets/, with its extension, for example "assets/hero.webp". |
data_base64 |
string | Yes | The file's bytes in base64, without a "data:" prefix, at most 10240 KB decoded. |
base_version |
integer | No | The "versionId" of the file this replaces; leave it out for a new file. (min 1) |
upload_theme_asset_from_url
Upload an image, font or SVG into the active theme's draft (not live until the draft is published) by downloading it from a public http(s) address, to a path in assets/ you name, for example "assets/hero.webp"; the same as upload_theme_asset without sending the bytes. Redirects are not followed: give the address the file is served from. Extensions: svg, png, jpg, jpeg, webp, gif, woff, woff2, ico; at most 10240 KB. The content must be what the path's extension says; an SVG is cleaned of scripts. To replace a file the theme has, pass its "versionId" (from list_theme_files) as base_version. A theme refers to an asset with {{ 'hero.webp' | asset_url }}. Answers the file as list_theme_files lists it.
- Permission: Themes · Code
- Reaches outside in1s
| Argument | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | Where the file goes, in assets/, with its extension, for example "assets/hero.webp". |
url |
string | Yes | The file's public http or https address. |
base_version |
integer | No | The "versionId" of the file this replaces; leave it out for a new file. (min 1) |