@workover/mcp 0.10.0 → 0.10.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/index.mjs +2 -2
- package/lib.mjs +56 -4
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -188,7 +188,7 @@ const TOOLS = [
|
|
|
188
188
|
type: 'object',
|
|
189
189
|
properties: {
|
|
190
190
|
docId: DOC_ARG,
|
|
191
|
-
path: { type: 'string', description: 'Local file path to the image (png/jpg/webp).' },
|
|
191
|
+
path: { type: 'string', description: 'Local file path to the image (png/jpg/gif/webp, up to 5 MB).' },
|
|
192
192
|
alt: { type: 'string', description: 'Alt text describing the image.' },
|
|
193
193
|
},
|
|
194
194
|
required: ['docId', 'path'],
|
|
@@ -298,7 +298,7 @@ const telemetry = telemetryEnabled(process.env, { auth });
|
|
|
298
298
|
// Keep in step with package.json. It is what every telemetry event is stamped with, so a stale
|
|
299
299
|
// value here does not break anything — it quietly attributes this release's behaviour to an older
|
|
300
300
|
// one, which is worse, because the numbers still look fine.
|
|
301
|
-
const VERSION = '0.10.
|
|
301
|
+
const VERSION = '0.10.1';
|
|
302
302
|
|
|
303
303
|
/**
|
|
304
304
|
* What the client is told about this server before it calls anything.
|
package/lib.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Pure/injectable helpers for the Workover MCP server, split out so they can be unit-tested without
|
|
2
2
|
// importing index.mjs (which starts the stdio server on load). index.mjs wires the real fetch/auth/fs
|
|
3
3
|
// into makeApi + makeDispatch; tests inject stubs.
|
|
4
|
+
import { realpathSync, statSync } from 'fs';
|
|
5
|
+
import { basename } from 'path';
|
|
4
6
|
|
|
5
7
|
/** Flatten HTML to readable plain text: drop tags + named entities, collapse whitespace. */
|
|
6
8
|
export const stripHtml = (h) =>
|
|
@@ -332,9 +334,55 @@ export const mimeForExt = (ext) => {
|
|
|
332
334
|
const e = String(ext || '').toLowerCase();
|
|
333
335
|
if (e === 'jpg' || e === 'jpeg') return 'image/jpeg';
|
|
334
336
|
if (e === 'webp') return 'image/webp';
|
|
337
|
+
if (e === 'gif') return 'image/gif';
|
|
335
338
|
return 'image/png';
|
|
336
339
|
};
|
|
337
340
|
|
|
341
|
+
/** The extensions the API's media upload accepts (apps/api/src/utils/image-type.ts). */
|
|
342
|
+
export const UPLOAD_IMAGE_EXT = ['png', 'jpg', 'jpeg', 'gif', 'webp'];
|
|
343
|
+
/** The API's multer cap (apps/api/src/config/multer-memory.config.ts); checked before reading. */
|
|
344
|
+
export const UPLOAD_IMAGE_MAX_BYTES = 5 * 1024 * 1024;
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Decide whether `workover_upload_image` may read a local path. The tool is driven by a model, and a
|
|
348
|
+
* model can be talked (by a document it just read, say) into "uploading" ~/.ssh/id_ed25519 or
|
|
349
|
+
* ~/.workover/config.json into a document anyone on the team can open. So: resolve symlinks first
|
|
350
|
+
* (a `shot.png` that links to a key is judged by what it points at), refuse anything inside a dot
|
|
351
|
+
* file or dot directory, accept only the image extensions the API takes, and check the size before
|
|
352
|
+
* reading a byte. Returns `{ path, ext }` (the real path) or `{ error }`.
|
|
353
|
+
*/
|
|
354
|
+
export const vetImagePath = (p, { realpath = realpathSync, stat = statSync } = {}) => {
|
|
355
|
+
let real;
|
|
356
|
+
try {
|
|
357
|
+
real = realpath(p);
|
|
358
|
+
} catch {
|
|
359
|
+
return { error: `Couldn't read an image at ${p}.` };
|
|
360
|
+
}
|
|
361
|
+
if (real.split(/[\\/]/).some((part) => part.startsWith('.') && part !== '.' && part !== '..'))
|
|
362
|
+
return {
|
|
363
|
+
error: `Refusing to upload ${p}: it is a hidden file or inside a hidden directory. Save the image somewhere ordinary (e.g. the Desktop) and pass that path.`,
|
|
364
|
+
};
|
|
365
|
+
const name = basename(real);
|
|
366
|
+
const dot = name.lastIndexOf('.');
|
|
367
|
+
const ext = dot > 0 ? name.slice(dot + 1).toLowerCase() : '';
|
|
368
|
+
if (!UPLOAD_IMAGE_EXT.includes(ext))
|
|
369
|
+
return {
|
|
370
|
+
error: `Refusing to upload ${p}: only ${UPLOAD_IMAGE_EXT.join(', ')} images can be uploaded.`,
|
|
371
|
+
};
|
|
372
|
+
let info;
|
|
373
|
+
try {
|
|
374
|
+
info = stat(real);
|
|
375
|
+
} catch {
|
|
376
|
+
return { error: `Couldn't read an image at ${p}.` };
|
|
377
|
+
}
|
|
378
|
+
if (!info.isFile()) return { error: `${p} is not a file.` };
|
|
379
|
+
if (info.size > UPLOAD_IMAGE_MAX_BYTES)
|
|
380
|
+
return {
|
|
381
|
+
error: `${p} is ${Math.ceil(info.size / 1024 / 1024)} MB; Workover takes images up to ${UPLOAD_IMAGE_MAX_BYTES / 1024 / 1024} MB.`,
|
|
382
|
+
};
|
|
383
|
+
return { path: real, ext };
|
|
384
|
+
};
|
|
385
|
+
|
|
338
386
|
/**
|
|
339
387
|
* Build the authenticated JSON API caller. `fetchImpl` is injectable for tests. The status→message
|
|
340
388
|
* mapping is the contract the tools rely on (401/403 are friendly, other non-2xx is generic).
|
|
@@ -385,7 +433,7 @@ export function makeApi({ auth, fetchImpl = fetch }) {
|
|
|
385
433
|
* short-circuits before any request; unknown tools and thrown errors become `err(...)`. `readFile`
|
|
386
434
|
* and `fetchImpl` are injected so the upload path is testable without touching the disk/network.
|
|
387
435
|
*/
|
|
388
|
-
export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile }) {
|
|
436
|
+
export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile, fsOps }) {
|
|
389
437
|
return async function dispatch(name, args = {}) {
|
|
390
438
|
if (!auth)
|
|
391
439
|
return err(
|
|
@@ -628,16 +676,20 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile }
|
|
|
628
676
|
const doc = await resolveDoc(api, docArg(args), auth.api);
|
|
629
677
|
if (doc.error) return doc.error;
|
|
630
678
|
const docId = doc.id;
|
|
679
|
+
const vetted = vetImagePath(p, fsOps);
|
|
680
|
+
if (vetted.error) return err(vetted.error);
|
|
681
|
+
const { ext } = vetted;
|
|
631
682
|
let buf;
|
|
632
683
|
try {
|
|
633
|
-
buf = readFile(
|
|
684
|
+
buf = readFile(vetted.path);
|
|
634
685
|
} catch {
|
|
635
686
|
return err(`Couldn't read an image at ${p}.`);
|
|
636
687
|
}
|
|
637
|
-
|
|
688
|
+
if (buf.length > UPLOAD_IMAGE_MAX_BYTES)
|
|
689
|
+
return err(`${p} is larger than ${UPLOAD_IMAGE_MAX_BYTES / 1024 / 1024} MB.`);
|
|
638
690
|
const mime = mimeForExt(ext);
|
|
639
691
|
const form = new FormData();
|
|
640
|
-
form.append('file', new Blob([buf], { type: mime }),
|
|
692
|
+
form.append('file', new Blob([buf], { type: mime }), basename(vetted.path));
|
|
641
693
|
if (args.alt) form.append('alt', String(args.alt));
|
|
642
694
|
const res = await fetchImpl(`${auth.api}/project/doc/${docId}/media`, {
|
|
643
695
|
method: 'POST',
|
package/package.json
CHANGED