@kolbo/mcp 1.19.0 → 1.19.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.
- package/package.json +1 -1
- package/src/tools/_shared.js +23 -18
package/package.json
CHANGED
package/src/tools/_shared.js
CHANGED
|
@@ -256,24 +256,29 @@ const INLINE_IMG_MAX_BYTES = 8 * 1024 * 1024; // 8 MB per image
|
|
|
256
256
|
async function inlineImageBlocks(urls, opts = {}) {
|
|
257
257
|
if (!opts || !opts.enabled) return [];
|
|
258
258
|
if (!Array.isArray(urls) || urls.length === 0) return [];
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
259
|
+
// Fetch the (≤4) images in parallel — they're independent, the cap already
|
|
260
|
+
// bounds concurrency, and this sits on the connector response path right
|
|
261
|
+
// after generation. Order is preserved by map-then-filter; any failure falls
|
|
262
|
+
// back to URL-only for that image.
|
|
263
|
+
const blocks = await Promise.all(
|
|
264
|
+
urls.slice(0, INLINE_IMG_MAX_COUNT).map(async (url) => {
|
|
265
|
+
try {
|
|
266
|
+
if (typeof url !== 'string' || !isHttpUrl(url)) return null;
|
|
267
|
+
const res = await safeFetch(url);
|
|
268
|
+
if (!res.ok) return null;
|
|
269
|
+
const contentType = (res.headers.get('content-type') || '').split(';')[0].trim().toLowerCase();
|
|
270
|
+
if (!contentType.startsWith('image/')) return null; // never embed non-images
|
|
271
|
+
const declaredLen = Number(res.headers.get('content-length') || 0);
|
|
272
|
+
if (declaredLen && declaredLen > INLINE_IMG_MAX_BYTES) return null;
|
|
273
|
+
const ab = await res.arrayBuffer();
|
|
274
|
+
if (ab.byteLength > INLINE_IMG_MAX_BYTES) return null;
|
|
275
|
+
return { type: 'image', data: Buffer.from(ab).toString('base64'), mimeType: contentType };
|
|
276
|
+
} catch (_) {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
})
|
|
280
|
+
);
|
|
281
|
+
return blocks.filter(Boolean);
|
|
277
282
|
}
|
|
278
283
|
|
|
279
284
|
module.exports = {
|