@yashwant.dharmdas/elementor-mcp 3.2.3 → 3.2.5
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.
- package/dist/index.js +71 -23
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1127,13 +1127,58 @@ function createMcpServer(sites) {
|
|
|
1127
1127
|
// Extra settle time for fonts, animations, videos
|
|
1128
1128
|
await new Promise(resolve => setTimeout(resolve, wait ?? 2000));
|
|
1129
1129
|
const fmt = format ?? "jpeg";
|
|
1130
|
-
const
|
|
1131
|
-
if (fmt === "jpeg")
|
|
1132
|
-
screenshotOptions.quality = quality ?? 82;
|
|
1130
|
+
const baseOptions = { type: fmt, fullPage: !max_height && (full_page ?? true) };
|
|
1133
1131
|
if (max_height)
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1132
|
+
baseOptions.clip = { x: 0, y: 0, width: vpWidth, height: vpHeight };
|
|
1133
|
+
// ── Adaptive capture: always fit under the MCP 1MB tool-result limit ──
|
|
1134
|
+
// (base64 overhead ~33%, so raw buffer must be ≤ ~780KB)
|
|
1135
|
+
const PREVIEW_LIMIT = 750 * 1024;
|
|
1136
|
+
let buf = Buffer.alloc(0);
|
|
1137
|
+
let usedQuality = undefined;
|
|
1138
|
+
let usedScale = 1;
|
|
1139
|
+
const takeOne = async (q, scale) => {
|
|
1140
|
+
if (scale !== 1) {
|
|
1141
|
+
// Re-apply viewport with scale factor to shrink pixel dimensions
|
|
1142
|
+
await page.setViewport({ width: Math.round(vpWidth * scale), height: Math.round(vpHeight * scale), deviceScaleFactor: 1 });
|
|
1143
|
+
// Allow layout to reflow
|
|
1144
|
+
await new Promise(r => setTimeout(r, 500));
|
|
1145
|
+
}
|
|
1146
|
+
const opts = { ...baseOptions };
|
|
1147
|
+
if (q !== undefined)
|
|
1148
|
+
opts.quality = q;
|
|
1149
|
+
const raw = await page.screenshot(opts);
|
|
1150
|
+
return Buffer.isBuffer(raw) ? raw : Buffer.from(raw);
|
|
1151
|
+
};
|
|
1152
|
+
if (fmt === "jpeg") {
|
|
1153
|
+
// Stage 1: try full resolution, progressive quality
|
|
1154
|
+
const q0 = quality ?? 82;
|
|
1155
|
+
const qualitySteps = Array.from(new Set([q0, 70, 55, 40, 25, 15])).filter(q => q <= q0);
|
|
1156
|
+
for (const q of qualitySteps) {
|
|
1157
|
+
buf = await takeOne(q, 1);
|
|
1158
|
+
usedQuality = q;
|
|
1159
|
+
if (buf.length <= PREVIEW_LIMIT)
|
|
1160
|
+
break;
|
|
1161
|
+
}
|
|
1162
|
+
// Stage 2: if still too big, shrink viewport width progressively
|
|
1163
|
+
const scaleSteps = [0.7, 0.5, 0.35, 0.25];
|
|
1164
|
+
for (const s of scaleSteps) {
|
|
1165
|
+
if (buf.length <= PREVIEW_LIMIT)
|
|
1166
|
+
break;
|
|
1167
|
+
buf = await takeOne(40, s);
|
|
1168
|
+
usedQuality = 40;
|
|
1169
|
+
usedScale = s;
|
|
1170
|
+
if (buf.length <= PREVIEW_LIMIT)
|
|
1171
|
+
break;
|
|
1172
|
+
// Inner quality drop at this scale
|
|
1173
|
+
buf = await takeOne(20, s);
|
|
1174
|
+
usedQuality = 20;
|
|
1175
|
+
if (buf.length <= PREVIEW_LIMIT)
|
|
1176
|
+
break;
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
else {
|
|
1180
|
+
buf = await takeOne(undefined, 1);
|
|
1181
|
+
}
|
|
1137
1182
|
// ── 5. Save to disk ─────────────────────────────────────────────
|
|
1138
1183
|
const ext = fmt === "jpeg" ? "jpg" : "png";
|
|
1139
1184
|
const idPart = page_id ?? (pageUrl.replace(/https?:\/\//, "").replace(/[^a-z0-9]/gi, "_").slice(0, 40));
|
|
@@ -1142,29 +1187,32 @@ function createMcpServer(sites) {
|
|
|
1142
1187
|
fs.writeFileSync(filePath, buf);
|
|
1143
1188
|
const sizeKB = Math.round(buf.length / 1024);
|
|
1144
1189
|
const mimeType = `image/${fmt}`;
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
text: [
|
|
1151
|
-
`✅ Screenshot saved successfully.`,
|
|
1152
|
-
`📁 file_path: ${filePath}`,
|
|
1153
|
-
`📐 Size: ${sizeKB} KB | Format: ${ext.toUpperCase()} | URL: ${pageUrl}`,
|
|
1154
|
-
``,
|
|
1155
|
-
`👉 To upload to Basecamp, call upload_attachment with:`,
|
|
1156
|
-
` file_path = "${filePath}"`,
|
|
1157
|
-
` project_id = <your Basecamp project ID>`,
|
|
1158
|
-
].join("\n"),
|
|
1159
|
-
},
|
|
1160
|
-
];
|
|
1190
|
+
const qualityNote = usedQuality !== undefined && usedQuality !== (quality ?? 82)
|
|
1191
|
+
? ` | Auto-downscaled to quality ${usedQuality}${usedScale !== 1 ? ` @ ${Math.round(usedScale * 100)}% width` : ""} to fit MCP limit`
|
|
1192
|
+
: "";
|
|
1193
|
+
// ── 6. Always return the image so Claude can analyse it ──────
|
|
1194
|
+
const content = [];
|
|
1161
1195
|
if (buf.length <= PREVIEW_LIMIT) {
|
|
1162
|
-
content.
|
|
1196
|
+
content.push({
|
|
1163
1197
|
type: "image",
|
|
1164
1198
|
data: buf.toString("base64"),
|
|
1165
1199
|
mimeType,
|
|
1166
1200
|
});
|
|
1167
1201
|
}
|
|
1202
|
+
content.push({
|
|
1203
|
+
type: "text",
|
|
1204
|
+
text: [
|
|
1205
|
+
`✅ Screenshot captured and saved.`,
|
|
1206
|
+
`📁 file_path: ${filePath}`,
|
|
1207
|
+
`📐 Size: ${sizeKB} KB | Format: ${ext.toUpperCase()}${qualityNote}`,
|
|
1208
|
+
`🌐 URL: ${pageUrl}`,
|
|
1209
|
+
buf.length > PREVIEW_LIMIT
|
|
1210
|
+
? `\n⚠️ Image still exceeds the 1MB MCP return limit even at lowest quality. The file is saved to disk and can be used via upload_attachment(file_path).`
|
|
1211
|
+
: ``,
|
|
1212
|
+
``,
|
|
1213
|
+
`👉 To upload to Basecamp: upload_attachment with file_path = "${filePath}"`,
|
|
1214
|
+
].filter(Boolean).join("\n"),
|
|
1215
|
+
});
|
|
1168
1216
|
return { content };
|
|
1169
1217
|
}
|
|
1170
1218
|
finally {
|
package/package.json
CHANGED