update_page
Update WordPress pages with Elementor data by specifying page ID, title, status, content, and JSON-based Elementor data. Verifies success with a boolean response.
Instructions
Updates an existing page in WordPress with Elementor data, it will return a boolean value to indicate if the update was successful.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | No | The standard WordPress content for the page (optional). | |
| elementor_data | No | The Elementor page data as a JSON string. Optional for update. | |
| pageId | Yes | The ID of the page to update. | |
| status | No | The status for the page (e.g., 'publish', 'draft'). | |
| title | No | The title for the page. |
Implementation Reference
- src/index.js:161-179 (handler)MCP tool handler for 'update_page' that extracts input, validates, calls the updatePage helper, and returns success indicator.async (input) => { // Handler const { pageId, ...updateData } = input; // Basic validation, although schema handles optionality if (Object.keys(updateData).length === 0) { throw new Error( "No update data provided (title, status, content, or elementor_data)." ); } await updatePage(pageId, updateData); return { content: [ { type: "text", text: "true", }, ], }; }
- src/index.js:138-160 (schema)Zod input schema defining parameters for the update_page tool: pageId (required), title/status/content/elementor_data (optional).{ // Input Schema: Use plain object with Zod types pageId: z .number() .int() .positive() .describe("The ID of the page to update."), title: z.string().optional().describe("The title for the page."), status: z .enum(["publish", "future", "draft", "pending", "private"]) .optional() .describe("The status for the page (e.g., 'publish', 'draft')."), content: z .string() .optional() .describe("The standard WordPress content for the page (optional)."), elementor_data: z .string() .optional() .describe( "The Elementor page data as a JSON string. Optional for update." ), },
- src/index.js:135-180 (registration)Registration of the 'update_page' tool on the MCP server using server.tool() with name, description, schema, and handler.server.tool( "update_page", "Updates an existing page in WordPress with Elementor data, it will return a boolean value to indicate if the update was successful.", { // Input Schema: Use plain object with Zod types pageId: z .number() .int() .positive() .describe("The ID of the page to update."), title: z.string().optional().describe("The title for the page."), status: z .enum(["publish", "future", "draft", "pending", "private"]) .optional() .describe("The status for the page (e.g., 'publish', 'draft')."), content: z .string() .optional() .describe("The standard WordPress content for the page (optional)."), elementor_data: z .string() .optional() .describe( "The Elementor page data as a JSON string. Optional for update." ), }, async (input) => { // Handler const { pageId, ...updateData } = input; // Basic validation, although schema handles optionality if (Object.keys(updateData).length === 0) { throw new Error( "No update data provided (title, status, content, or elementor_data)." ); } await updatePage(pageId, updateData); return { content: [ { type: "text", text: "true", }, ], }; } );
- src/wp-api.js:41-68 (helper)Core helper function updatePage that constructs the payload from input data, validates elementor_data, and performs the PUT-like update via WordPress REST API POST to /pages/{id}.async function updatePage(pageId, pageData) { const client = getApiClient(); const payload = {}; if (pageData.title) payload.title = pageData.title; if (pageData.status) payload.status = pageData.status; if (pageData.content) payload.content = pageData.content; // Use !== undefined to allow setting empty content if (pageData.elementor_data) { if (typeof pageData.elementor_data !== 'string') { throw new Error('elementor_data must be provided as a JSON string.'); } try { JSON.parse(pageData.elementor_data); // Basic validation } catch (e) { throw new Error('elementor_data is not valid JSON string.'); } payload.meta = { _elementor_data: pageData.elementor_data }; } if (Object.keys(payload).length === 0) { throw new Error("No update data provided."); } // WP uses POST for updates via ID route const response = await client.post(`/wp-json/wp/v2/pages/${pageId}`, payload); return response.data; }