@yashwant.dharmdas/elementor-mcp 3.2.3 → 3.2.4
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 +44 -23
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1127,13 +1127,31 @@ 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 quality: 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;
|
|
1137
|
+
let usedQuality = undefined;
|
|
1138
|
+
if (fmt === "jpeg") {
|
|
1139
|
+
// Try user-requested quality first; fall back progressively lower until it fits.
|
|
1140
|
+
const q0 = quality ?? 82;
|
|
1141
|
+
const qualitySteps = Array.from(new Set([q0, 70, 55, 40, 25, 15])).filter(q => q <= q0);
|
|
1142
|
+
for (const q of qualitySteps) {
|
|
1143
|
+
const raw = await page.screenshot({ ...baseOptions, quality: q });
|
|
1144
|
+
buf = Buffer.isBuffer(raw) ? raw : Buffer.from(raw);
|
|
1145
|
+
usedQuality = q;
|
|
1146
|
+
if (buf.length <= PREVIEW_LIMIT)
|
|
1147
|
+
break;
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
else {
|
|
1151
|
+
const raw = await page.screenshot(baseOptions);
|
|
1152
|
+
buf = Buffer.isBuffer(raw) ? raw : Buffer.from(raw);
|
|
1153
|
+
}
|
|
1154
|
+
buf = buf;
|
|
1137
1155
|
// ── 5. Save to disk ─────────────────────────────────────────────
|
|
1138
1156
|
const ext = fmt === "jpeg" ? "jpg" : "png";
|
|
1139
1157
|
const idPart = page_id ?? (pageUrl.replace(/https?:\/\//, "").replace(/[^a-z0-9]/gi, "_").slice(0, 40));
|
|
@@ -1142,29 +1160,32 @@ function createMcpServer(sites) {
|
|
|
1142
1160
|
fs.writeFileSync(filePath, buf);
|
|
1143
1161
|
const sizeKB = Math.round(buf.length / 1024);
|
|
1144
1162
|
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
|
-
];
|
|
1163
|
+
const qualityNote = usedQuality !== undefined && usedQuality !== (quality ?? 82)
|
|
1164
|
+
? ` | Auto-downscaled to quality ${usedQuality} to fit MCP limit`
|
|
1165
|
+
: "";
|
|
1166
|
+
// ── 6. Always return the image so Claude can analyse it ──────
|
|
1167
|
+
const content = [];
|
|
1161
1168
|
if (buf.length <= PREVIEW_LIMIT) {
|
|
1162
|
-
content.
|
|
1169
|
+
content.push({
|
|
1163
1170
|
type: "image",
|
|
1164
1171
|
data: buf.toString("base64"),
|
|
1165
1172
|
mimeType,
|
|
1166
1173
|
});
|
|
1167
1174
|
}
|
|
1175
|
+
content.push({
|
|
1176
|
+
type: "text",
|
|
1177
|
+
text: [
|
|
1178
|
+
`✅ Screenshot captured and saved.`,
|
|
1179
|
+
`📁 file_path: ${filePath}`,
|
|
1180
|
+
`📐 Size: ${sizeKB} KB | Format: ${ext.toUpperCase()}${qualityNote}`,
|
|
1181
|
+
`🌐 URL: ${pageUrl}`,
|
|
1182
|
+
buf.length > PREVIEW_LIMIT
|
|
1183
|
+
? `\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).`
|
|
1184
|
+
: ``,
|
|
1185
|
+
``,
|
|
1186
|
+
`👉 To upload to Basecamp: upload_attachment with file_path = "${filePath}"`,
|
|
1187
|
+
].filter(Boolean).join("\n"),
|
|
1188
|
+
});
|
|
1168
1189
|
return { content };
|
|
1169
1190
|
}
|
|
1170
1191
|
finally {
|
package/package.json
CHANGED