@ww_nero/mini-cli 1.0.75 → 1.0.76
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/mcp.js +25 -1
package/package.json
CHANGED
package/src/tools/mcp.js
CHANGED
|
@@ -304,6 +304,26 @@ const formatMcpContent = (content) => {
|
|
|
304
304
|
return renderContentChunk(content);
|
|
305
305
|
};
|
|
306
306
|
|
|
307
|
+
const resolveImageSource = (workspaceRoot, args = {}) => {
|
|
308
|
+
if (!isPlainObject(args)) return { args };
|
|
309
|
+
if (!Object.prototype.hasOwnProperty.call(args, 'image_source')) return { args };
|
|
310
|
+
const imageSourceRaw = args.image_source;
|
|
311
|
+
if (typeof imageSourceRaw !== 'string') return { args };
|
|
312
|
+
const imageSource = imageSourceRaw.trim();
|
|
313
|
+
if (!imageSource) return { args };
|
|
314
|
+
if (path.isAbsolute(imageSource)) {
|
|
315
|
+
return { args: { ...args, image_source: path.normalize(imageSource) } };
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const root = workspaceRoot ? path.resolve(workspaceRoot) : process.cwd();
|
|
319
|
+
const resolved = path.resolve(root, imageSource);
|
|
320
|
+
const relative = path.relative(root, resolved);
|
|
321
|
+
if (relative.startsWith('..') || path.isAbsolute(relative) || !fs.existsSync(resolved)) {
|
|
322
|
+
return { error: '找不到图片' };
|
|
323
|
+
}
|
|
324
|
+
return { args: { ...args, image_source: resolved } };
|
|
325
|
+
};
|
|
326
|
+
|
|
307
327
|
class McpManager {
|
|
308
328
|
constructor(workspaceRoot, allowedMcpNames = null, options = {}) {
|
|
309
329
|
this.workspaceRoot = workspaceRoot;
|
|
@@ -401,10 +421,14 @@ class McpManager {
|
|
|
401
421
|
},
|
|
402
422
|
handler: async (args = {}) => {
|
|
403
423
|
try {
|
|
424
|
+
const { args: normalizedArgs, error } = resolveImageSource(this.workspaceRoot, args);
|
|
425
|
+
if (error) {
|
|
426
|
+
return error;
|
|
427
|
+
}
|
|
404
428
|
const result = await client.callTool(
|
|
405
429
|
{
|
|
406
430
|
name: tool.name,
|
|
407
|
-
arguments:
|
|
431
|
+
arguments: normalizedArgs
|
|
408
432
|
},
|
|
409
433
|
undefined,
|
|
410
434
|
{
|