@yashwant.dharmdas/elementor-mcp 3.2.4 → 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 +36 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1130,28 +1130,55 @@ function createMcpServer(sites) {
|
|
|
1130
1130
|
const baseOptions = { type: fmt, fullPage: !max_height && (full_page ?? true) };
|
|
1131
1131
|
if (max_height)
|
|
1132
1132
|
baseOptions.clip = { x: 0, y: 0, width: vpWidth, height: vpHeight };
|
|
1133
|
-
// ── Adaptive
|
|
1133
|
+
// ── Adaptive capture: always fit under the MCP 1MB tool-result limit ──
|
|
1134
1134
|
// (base64 overhead ~33%, so raw buffer must be ≤ ~780KB)
|
|
1135
1135
|
const PREVIEW_LIMIT = 750 * 1024;
|
|
1136
|
-
let buf;
|
|
1136
|
+
let buf = Buffer.alloc(0);
|
|
1137
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
|
+
};
|
|
1138
1152
|
if (fmt === "jpeg") {
|
|
1139
|
-
//
|
|
1153
|
+
// Stage 1: try full resolution, progressive quality
|
|
1140
1154
|
const q0 = quality ?? 82;
|
|
1141
1155
|
const qualitySteps = Array.from(new Set([q0, 70, 55, 40, 25, 15])).filter(q => q <= q0);
|
|
1142
1156
|
for (const q of qualitySteps) {
|
|
1143
|
-
|
|
1144
|
-
buf = Buffer.isBuffer(raw) ? raw : Buffer.from(raw);
|
|
1157
|
+
buf = await takeOne(q, 1);
|
|
1145
1158
|
usedQuality = q;
|
|
1146
1159
|
if (buf.length <= PREVIEW_LIMIT)
|
|
1147
1160
|
break;
|
|
1148
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
|
+
}
|
|
1149
1178
|
}
|
|
1150
1179
|
else {
|
|
1151
|
-
|
|
1152
|
-
buf = Buffer.isBuffer(raw) ? raw : Buffer.from(raw);
|
|
1180
|
+
buf = await takeOne(undefined, 1);
|
|
1153
1181
|
}
|
|
1154
|
-
buf = buf;
|
|
1155
1182
|
// ── 5. Save to disk ─────────────────────────────────────────────
|
|
1156
1183
|
const ext = fmt === "jpeg" ? "jpg" : "png";
|
|
1157
1184
|
const idPart = page_id ?? (pageUrl.replace(/https?:\/\//, "").replace(/[^a-z0-9]/gi, "_").slice(0, 40));
|
|
@@ -1161,7 +1188,7 @@ function createMcpServer(sites) {
|
|
|
1161
1188
|
const sizeKB = Math.round(buf.length / 1024);
|
|
1162
1189
|
const mimeType = `image/${fmt}`;
|
|
1163
1190
|
const qualityNote = usedQuality !== undefined && usedQuality !== (quality ?? 82)
|
|
1164
|
-
? ` | Auto-downscaled to quality ${usedQuality} to fit MCP limit`
|
|
1191
|
+
? ` | Auto-downscaled to quality ${usedQuality}${usedScale !== 1 ? ` @ ${Math.round(usedScale * 100)}% width` : ""} to fit MCP limit`
|
|
1165
1192
|
: "";
|
|
1166
1193
|
// ── 6. Always return the image so Claude can analyse it ──────
|
|
1167
1194
|
const content = [];
|
package/package.json
CHANGED