@yashwant.dharmdas/elementor-mcp 3.10.0 → 3.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +102 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1091,13 +1091,14 @@ function createMcpServer(sites) {
1091
1091
  }
1092
1092
  });
1093
1093
  // ── Group 8: Page Creation & Publishing ──────────────────────────────────
1094
- server.tool("create-page", "Create a new WordPress page, optionally publish it immediately, and enable the Elementor editor. Returns the page ID and direct Elementor edit URL.", {
1094
+ server.tool("create-page", "Create a new WordPress page, optionally publish it immediately, and enable the Elementor editor. Returns the page ID and direct Elementor edit URL. Supports any WordPress post type — use post_type='astra-portfolio' for Astra portfolio items, 'post' for blog posts, etc.", {
1095
1095
  title: z.string().describe("Page title"),
1096
1096
  status: z.enum(["draft", "publish", "private", "pending"]).optional().describe("Page status — default: draft"),
1097
1097
  page_template: z.string().optional().describe("WordPress page template filename (e.g. 'elementor_canvas'). Leave blank for default."),
1098
1098
  enable_elementor: z.boolean().optional().describe("Initialize the Elementor editor on this page (default: true)"),
1099
+ post_type: z.string().optional().describe("WordPress post type. Default: 'page'. Use 'astra-portfolio' for Astra portfolio, 'post' for blog posts, or any registered custom post type."),
1099
1100
  site: siteParam,
1100
- }, async ({ title, status, page_template, enable_elementor, site }) => {
1101
+ }, async ({ title, status, page_template, enable_elementor, post_type, site }) => {
1101
1102
  try {
1102
1103
  const { wpUrl, authHeader } = resolveSite(sites, site);
1103
1104
  const body = {
@@ -1107,6 +1108,8 @@ function createMcpServer(sites) {
1107
1108
  };
1108
1109
  if (page_template)
1109
1110
  body.page_template = page_template;
1111
+ if (post_type)
1112
+ body.post_type = post_type;
1110
1113
  const r = await axios.post(`${wpUrl}/wp-json/erc/v1/pages`, body, {
1111
1114
  headers: { Authorization: authHeader, "Content-Type": "application/json" },
1112
1115
  });
@@ -1116,6 +1119,103 @@ function createMcpServer(sites) {
1116
1119
  return { content: [{ type: "text", text: `Error creating page: ${error.response?.data?.message || error.message}` }], isError: true };
1117
1120
  }
1118
1121
  });
1122
+ server.tool("import-template-to-page", "Push a local Elementor JSON file from disk directly to an existing page. The MCP server reads the file and sends it straight to WordPress — the JSON NEVER passes through Claude's context, so there is NO 25K-token limit. Use when you have generated a large Elementor JSON locally and need to push it to an existing page. File path must be accessible on this machine (where the MCP server is running).", {
1123
+ page_id: z.string().describe("WordPress Page ID to write the Elementor data to"),
1124
+ file_path: z.string().describe("Absolute path to the Elementor JSON file on disk (e.g. D:\\Project\\final-service-pages\\botox.json). Must contain a valid Elementor elements array."),
1125
+ site: siteParam,
1126
+ }, async ({ page_id, file_path, site }) => {
1127
+ try {
1128
+ const { wpUrl, authHeader } = resolveSite(sites, site);
1129
+ // Read file from local disk — bypasses Claude context entirely
1130
+ if (!fs.existsSync(file_path)) {
1131
+ return { content: [{ type: "text", text: `Error: File not found at path: ${file_path}` }], isError: true };
1132
+ }
1133
+ const raw = fs.readFileSync(file_path, "utf8");
1134
+ let elementorData;
1135
+ try {
1136
+ elementorData = JSON.parse(raw);
1137
+ }
1138
+ catch {
1139
+ return { content: [{ type: "text", text: `Error: File at ${file_path} is not valid JSON.` }], isError: true };
1140
+ }
1141
+ // Auto-unwrap Elementor export format: {"content":[...],"version":"0.4",...}
1142
+ // The API endpoint expects a raw elements array, not the export wrapper object.
1143
+ if (!Array.isArray(elementorData) && Array.isArray(elementorData?.content)) {
1144
+ elementorData = elementorData.content;
1145
+ }
1146
+ // Push to WordPress
1147
+ const r = await axios.put(`${wpUrl}/wp-json/erc/v1/pages/${page_id}/data`, elementorData, { headers: { Authorization: authHeader, "Content-Type": "application/json" } });
1148
+ // Clear cache
1149
+ await axios.post(`${wpUrl}/wp-json/erc/v1/site/clear-cache`, {}, { headers: { Authorization: authHeader }, params: { post_id: page_id } }).catch(() => { });
1150
+ return { content: [{ type: "text", text: JSON.stringify({ success: true, page_id, file: file_path, result: r.data }, null, 2) }] };
1151
+ }
1152
+ catch (error) {
1153
+ return { content: [{ type: "text", text: `Error importing template: ${error.response?.data?.message || error.message}` }], isError: true };
1154
+ }
1155
+ });
1156
+ server.tool("create-page-from-file", "Create a new WordPress page AND populate it with Elementor data from a local JSON file — all in one step. The MCP server reads the file from disk and sends it straight to WordPress. The JSON NEVER passes through Claude's context, so there is NO 25K-token limit. This is the correct tool for the service-pages workflow: write a script that generates Elementor JSONs locally, then call this tool for each file. Supports any post_type (astra-portfolio, page, post, etc.). Steps internally: 1) create page → get ID, 2) push Elementor data from file, 3) clear cache.", {
1157
+ title: z.string().describe("Page title"),
1158
+ file_path: z.string().describe("Absolute path to the Elementor JSON file on disk (e.g. D:\\Project\\final-service-pages\\botox.json)"),
1159
+ post_type: z.string().optional().describe("WordPress post type. Default: 'page'. Use 'astra-portfolio' for Astra portfolio items, 'post' for blog posts, or any registered custom post type."),
1160
+ status: z.enum(["draft", "publish", "private", "pending"]).optional().describe("Page status — default: publish"),
1161
+ page_template: z.string().optional().describe("WordPress page template (e.g. 'elementor_canvas'). Leave blank for default."),
1162
+ site: siteParam,
1163
+ }, async ({ title, file_path, post_type, status, page_template, site }) => {
1164
+ try {
1165
+ const { wpUrl, authHeader } = resolveSite(sites, site);
1166
+ // Step 1: Read the Elementor JSON from disk
1167
+ if (!fs.existsSync(file_path)) {
1168
+ return { content: [{ type: "text", text: `Error: File not found at path: ${file_path}` }], isError: true };
1169
+ }
1170
+ const raw = fs.readFileSync(file_path, "utf8");
1171
+ let elementorData;
1172
+ try {
1173
+ elementorData = JSON.parse(raw);
1174
+ }
1175
+ catch {
1176
+ return { content: [{ type: "text", text: `Error: File at ${file_path} is not valid JSON.` }], isError: true };
1177
+ }
1178
+ // Auto-unwrap Elementor export format: {"content":[...],"version":"0.4",...}
1179
+ // The API endpoint expects a raw elements array, not the export wrapper object.
1180
+ if (!Array.isArray(elementorData) && Array.isArray(elementorData?.content)) {
1181
+ elementorData = elementorData.content;
1182
+ }
1183
+ // Step 2: Create the page
1184
+ const createBody = {
1185
+ title,
1186
+ status: status ?? "publish",
1187
+ enable_elementor: true,
1188
+ };
1189
+ if (post_type)
1190
+ createBody.post_type = post_type;
1191
+ if (page_template)
1192
+ createBody.page_template = page_template;
1193
+ const createRes = await axios.post(`${wpUrl}/wp-json/erc/v1/pages`, createBody, { headers: { Authorization: authHeader, "Content-Type": "application/json" } });
1194
+ const page_id = createRes.data.id;
1195
+ // Step 3: Push Elementor data from file (never entered Claude context)
1196
+ await axios.put(`${wpUrl}/wp-json/erc/v1/pages/${page_id}/data`, elementorData, { headers: { Authorization: authHeader, "Content-Type": "application/json" } });
1197
+ // Step 4: Clear cache
1198
+ await axios.post(`${wpUrl}/wp-json/erc/v1/site/clear-cache`, {}, { headers: { Authorization: authHeader }, params: { post_id: page_id } }).catch(() => { });
1199
+ return {
1200
+ content: [{
1201
+ type: "text",
1202
+ text: JSON.stringify({
1203
+ success: true,
1204
+ page_id,
1205
+ title,
1206
+ post_type: post_type ?? "page",
1207
+ status: status ?? "publish",
1208
+ url: createRes.data.url,
1209
+ edit_url: createRes.data.elementor_edit_url,
1210
+ file_used: file_path,
1211
+ }, null, 2),
1212
+ }],
1213
+ };
1214
+ }
1215
+ catch (error) {
1216
+ return { content: [{ type: "text", text: `Error creating page from file: ${error.response?.data?.message || error.message}` }], isError: true };
1217
+ }
1218
+ });
1119
1219
  server.tool("publish-page", "Change the publish status of a WordPress page (publish, draft, private, pending, trash).", {
1120
1220
  page_id: z.string().describe("WordPress Page ID"),
1121
1221
  status: z.enum(["publish", "draft", "private", "pending", "trash"]).describe("Target status"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yashwant.dharmdas/elementor-mcp",
3
- "version": "3.10.0",
3
+ "version": "3.11.1",
4
4
  "description": "MCP server for controlling Elementor via Claude — supports multiple WordPress sites",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",