Write Theme File
Writes a whole theme file, creating it if it does not exist — for example a new stylesheet or an include for functions.php. The file goes into the theme draft, never the live theme, after the same syntax, JSON and block checks as an edit. To change part of an existing file, mosmcp/theme-file-edit is safer.
| Property | Value |
|---|---|
| Ability slug | mosmcp/theme-file-write |
| Wire tool name | mosmcp__theme-file-write |
| 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: true · openWorld: false |
Input schema
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| path | string | Yes | — | Path inside the theme. |
| content | string | Yes | — | The complete file contents. |
| create_only | boolean | false |
Refuse instead of overwriting when the file already exists. |
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[] |
Example
Sample prompt
Add a new stylesheet called assets/css/custom.css to my theme with a blue button style.
Example request (json)
{
"jsonrpc": "2.0",
"id": 307,
"method": "tools/call",
"params": {
"name": "mosmcp__theme-file-write",
"arguments": {
"input": {
"path": "assets/css/custom.css",
"content": ".wp-block-button__link { background: #1e5aa8; }
",
"create_only": true
}
}
}
}Example response (json)
{
"jsonrpc": "2.0",
"id": 307,
"result": {
"isError": false,
"structuredContent": {
"staged": true,
"target": "the theme file \"assets/css/custom.css\"",
"change": "created",
"draft": {
"exists": true,
"change_count": 1,
"files": [
"assets/css/custom.css (write)"
],
"created": "2026-09-29 10:20:00 UTC",
"updated": "2026-09-29 10:20: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": [
"This is a new file. WordPress only uses it if the theme includes or references it — for example a PHP file needs require_once from functions.php, and a stylesheet needs enqueuing."
]
}
}
}
Edge cases / errors
- File already exists and create_only is true → refused with mosmcp_theme_file_exists.
- Content identical to the current file → refused with mosmcp_no_change.
- File type not writable (only php, css, scss, js, json, html, txt, md are allowed) → mosmcp_theme_file_type_unwritable; content over 1 MB → mosmcp_theme_file_too_large.
- Same PHP, JSON and block-balance checks as mosmcp/theme-file-edit; the change goes to the draft, never the live theme.
| << Previous | Next >> |
|---|---|
| Search Theme Files | Check Theme Draft |
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.