Edit Theme File
Changes one passage inside a theme file — for example a function in functions.php or a rule in style.css — without rewriting the rest. The change goes into the theme draft, never the live theme. Refuses when the text is missing or appears more than once unless replace_all is set; PHP is checked for syntax errors, JSON for validity and templates for balanced blocks before the change is accepted.
Also known as: edit functions.php, change CSS, modify theme code, add custom code.
| Property | Value |
|---|---|
| Ability slug | mosmcp/theme-file-edit |
| Wire tool name | mosmcp__theme-file-edit |
| Category | Theme: Files (mosmcp-theme-files) |
| Plan | Free |
Required access
| Requirement | Value |
|---|---|
| Capability | edit_theme_options |
| Minimum default role | Administrator (Shop manager too when WooCommerce is active) |
| Annotations | readOnly: false · destructive: false · idempotent: false · openWorld: false |
Input schema
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| path | string | Yes | — | Path inside the theme, for example "functions.php". |
| find_text | string | Yes | — | The exact text to change. Include enough surrounding lines to make it unique. |
| replace_with | string | Yes | — | The new text. |
| replace_all | boolean | false |
Change every occurrence instead of requiring exactly one. | |
| whole_word | boolean | false |
Only match whole words. |
Output schema
| Field | Type | Required | Description |
|---|---|---|---|
| staged | boolean | Yes | |
| target | string | ||
| change | string | ||
| draft | object | Yes | |
| draft.exists | boolean | ||
| draft.change_count | integer | ||
| draft.templates | string[] | ||
| draft.template_parts | string[] | ||
| draft.global_styles | string | ||
| draft.patterns | string[] | ||
| draft.files | string[] | ||
| draft.site_identity | string[] | Pending logo and site icon changes. | |
| draft.custom_css | string[] | Pending change to the Customizer's Additional CSS. A block theme's Additional CSS is part of global styles. | |
| draft.theme_settings | string[] | Pending theme (Customizer) settings. | |
| draft.created | string | ||
| draft.updated | string | ||
| draft.preview_ready | boolean | ||
| next_step | string | ||
| notes | string[] | ||
| occurrences | integer | ||
| match_mode | string |
Example
Sample prompt
In my theme's style.css, change the header padding from 24px to 32px.
Example request (json)
{
"jsonrpc": "2.0",
"id": 302,
"method": "tools/call",
"params": {
"name": "mosmcp__theme-file-edit",
"arguments": {
"input": {
"path": "style.css",
"find_text": ".site-header { padding: 24px 0; }",
"replace_with": ".site-header { padding: 32px 0; }"
}
}
}
}Example response (json)
{
"jsonrpc": "2.0",
"id": 302,
"result": {
"isError": false,
"structuredContent": {
"staged": true,
"target": "the theme file \"style.css\"",
"change": "edited",
"draft": {
"exists": true,
"change_count": 1,
"templates": [],
"template_parts": [],
"global_styles": "",
"patterns": [],
"files": [
"style.css (write)"
],
"created": "2026-09-29 10:15:00 UTC",
"updated": "2026-09-29 10:15:00 UTC",
"preview_ready": false
},
"next_step": "Nothing has changed on the live site yet. Preview the draft with mosmcp/theme-draft-preview, then publish it with mosmcp/theme-draft-publish.",
"notes": [],
"occurrences": 1,
"match_mode": "exact"
}
}
}
Edge cases / errors
- find_text not found, or found more than once without replace_all → refused and nothing is staged.
- The edit would leave a PHP syntax error, invalid JSON, or unbalanced block comments in an .html template → refused (mosmcp_theme_php_syntax, mosmcp_theme_json_invalid, mosmcp_theme_blocks_broken).
- File doesn't exist → mosmcp_theme_file_not_found, pointing to mosmcp/theme-file-write. DISALLOW_FILE_EDIT/DISALLOW_FILE_MODS, a missing edit_themes capability, or a host that can't write files directly → refused.
- Draft-only: the live theme is untouched until mosmcp/theme-draft-publish. Editing a template that was customised in the Site Editor adds a note that the saved version wins over the file.
| << Previous | Next >> |
|---|---|
| Delete Theme File | List Theme Files |
For more information about the Secure MCP Server for WordPress plugin, explore the following resources:
Product Overview | Pricing | Try for Free | Documentation
If you have any questions regarding plugin configuration, pricing plans or licensing, please contact us or mail us at aisupport@xecurify.com.