create_page
Create a new WordPress page with Elementor data, specifying title, status, content, and required JSON-formatted Elementor data, returning the page ID upon success.
Instructions
Creates a new page in WordPress with Elementor data, it will return the created page ID.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | No | The standard WordPress content for the page (optional). | |
| elementor_data | Yes | The Elementor page data as a JSON string (required for create). | |
| status | No | The status for the page (e.g., 'publish', 'draft'). Defaults to 'draft' on create. | |
| title | Yes | The title for the new page (required). |
Implementation Reference
- src/index.js:34-70 (registration)MCP tool registration for 'create_page', including description, input schema, and handler function that delegates to wp-api createPage.server.tool( "create_page", "Creates a new page in WordPress with Elementor data, it will return the created page ID.", { // Input Schema: Use plain object with Zod types title: z.string().describe("The title for the new page (required)."), status: z .enum(["publish", "future", "draft", "pending", "private"]) .optional() .describe( "The status for the page (e.g., 'publish', 'draft'). Defaults to 'draft' on create." ), content: z .string() .optional() .describe("The standard WordPress content for the page (optional)."), elementor_data: z .string() .describe( "The Elementor page data as a JSON string (required for create)." ), }, async (input) => { // Handler function const newPage = await createPage(input); // Return the result object directly return { content: [ { type: "text", text: `${newPage.id}`, }, ], }; // Errors thrown here will be handled by McpServer } );
- src/index.js:56-69 (handler)MCP tool handler for create_page: calls createPage from wp-api and returns the new page ID as text content.async (input) => { // Handler function const newPage = await createPage(input); // Return the result object directly return { content: [ { type: "text", text: `${newPage.id}`, }, ], }; // Errors thrown here will be handled by McpServer }
- src/index.js:38-55 (schema)Zod input schema for create_page tool defining parameters: title (required), status, content, elementor_data (JSON string).// Input Schema: Use plain object with Zod types title: z.string().describe("The title for the new page (required)."), status: z .enum(["publish", "future", "draft", "pending", "private"]) .optional() .describe( "The status for the page (e.g., 'publish', 'draft'). Defaults to 'draft' on create." ), content: z .string() .optional() .describe("The standard WordPress content for the page (optional)."), elementor_data: z .string() .describe( "The Elementor page data as a JSON string (required for create)." ), },
- src/wp-api.js:4-30 (helper)Core helper function createPage that performs the WordPress REST API POST to /wp/v2/pages with Elementor meta data, including validation.async function createPage(pageData) { const client = getApiClient(); // Ensure Elementor data is properly nested under meta const payload = { title: pageData.title, status: pageData.status || 'draft', // Default to draft content: pageData.content || '', // Optional standard content meta: { _elementor_data: pageData.elementor_data // MUST be a JSON string } // Add other WP fields as needed (e.g., template, author, etc.) }; // Validate elementor_data is a string if (typeof payload.meta._elementor_data !== 'string') { throw new Error('elementor_data must be provided as a JSON string.'); } try { JSON.parse(payload.meta._elementor_data); // Basic validation it's parsable JSON } catch (e) { throw new Error('elementor_data is not valid JSON string.'); } const response = await client.post('/wp-json/wp/v2/pages', payload); return response.data; // Return the created page object }