@imenam/mcp-documentor 1.0.52 → 1.0.53
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/src/index.js +14 -0
- package/dist/src/tools/get-image.d.ts +15 -0
- package/dist/src/tools/get-image.js +67 -0
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
package/dist/src/index.js
CHANGED
|
@@ -38,6 +38,7 @@ import { reindexEmbeddings } from "./tools/reindex-embeddings.js";
|
|
|
38
38
|
import { prepareExportBundle } from "./tools/prepare-export-bundle.js";
|
|
39
39
|
import { deleteExportBundle } from "./tools/delete-export-bundle.js";
|
|
40
40
|
import { uploadImage } from "./tools/upload-image.js";
|
|
41
|
+
import { getImage } from "./tools/get-image.js";
|
|
41
42
|
const __filename = fileURLToPath(import.meta.url);
|
|
42
43
|
const __dirname = path.dirname(__filename);
|
|
43
44
|
function findProjectRoot(startDir) {
|
|
@@ -987,6 +988,17 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
|
987
988
|
required: ["filename", "filePath"],
|
|
988
989
|
},
|
|
989
990
|
},
|
|
991
|
+
{
|
|
992
|
+
name: "get_image",
|
|
993
|
+
description: "Retrieve an image stored in a project's assets by its URI and return it as a base64-encoded image. Use this when a document references an image (e.g. ) and you need to view its content.",
|
|
994
|
+
inputSchema: {
|
|
995
|
+
type: "object",
|
|
996
|
+
properties: {
|
|
997
|
+
uri: { type: "string", description: "Image URI as it appears in the document, e.g. '/api/images/my-project/screenshot.png'" },
|
|
998
|
+
},
|
|
999
|
+
required: ["uri"],
|
|
1000
|
+
},
|
|
1001
|
+
},
|
|
990
1002
|
],
|
|
991
1003
|
};
|
|
992
1004
|
});
|
|
@@ -1058,6 +1070,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
1058
1070
|
}
|
|
1059
1071
|
case "upload_image":
|
|
1060
1072
|
return await uploadImage(storageEngine, args);
|
|
1073
|
+
case "get_image":
|
|
1074
|
+
return await getImage(storageEngine, args);
|
|
1061
1075
|
default:
|
|
1062
1076
|
throw new Error(`Tool not found: ${name}`);
|
|
1063
1077
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { StorageEngine } from "../core/storage-engine.js";
|
|
2
|
+
export declare function getImage(storageEngine: StorageEngine, args: unknown): Promise<{
|
|
3
|
+
isError: boolean;
|
|
4
|
+
content: {
|
|
5
|
+
type: string;
|
|
6
|
+
text: string;
|
|
7
|
+
}[];
|
|
8
|
+
} | {
|
|
9
|
+
content: {
|
|
10
|
+
type: string;
|
|
11
|
+
data: string;
|
|
12
|
+
mimeType: string;
|
|
13
|
+
}[];
|
|
14
|
+
isError?: undefined;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
const GetImageArgsSchema = z.object({
|
|
5
|
+
uri: z.string().min(1),
|
|
6
|
+
});
|
|
7
|
+
const MIME_TYPES = {
|
|
8
|
+
".png": "image/png",
|
|
9
|
+
".jpg": "image/jpeg",
|
|
10
|
+
".jpeg": "image/jpeg",
|
|
11
|
+
".gif": "image/gif",
|
|
12
|
+
".webp": "image/webp",
|
|
13
|
+
".svg": "image/svg+xml",
|
|
14
|
+
".bmp": "image/bmp",
|
|
15
|
+
".ico": "image/x-icon",
|
|
16
|
+
};
|
|
17
|
+
export async function getImage(storageEngine, args) {
|
|
18
|
+
try {
|
|
19
|
+
const validated = GetImageArgsSchema.parse(args);
|
|
20
|
+
// Expected URI format: /api/images/{project}/{filename}
|
|
21
|
+
const match = validated.uri.match(/^\/api\/images\/([^/]+)\/([^/]+)$/);
|
|
22
|
+
if (!match) {
|
|
23
|
+
return {
|
|
24
|
+
isError: true,
|
|
25
|
+
content: [
|
|
26
|
+
{
|
|
27
|
+
type: "text",
|
|
28
|
+
text: `Invalid image URI format. Expected: /api/images/{project}/{filename}. Got: ${validated.uri}`,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const project = decodeURIComponent(match[1]);
|
|
34
|
+
const filename = decodeURIComponent(match[2]);
|
|
35
|
+
const assetsDir = path.join(storageEngine.getDataDir(), "projects", project, "assets");
|
|
36
|
+
const filePath = path.join(assetsDir, filename);
|
|
37
|
+
// Prevent path traversal
|
|
38
|
+
if (!filePath.startsWith(assetsDir)) {
|
|
39
|
+
return {
|
|
40
|
+
isError: true,
|
|
41
|
+
content: [{ type: "text", text: "Invalid image path." }],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (!fs.existsSync(filePath)) {
|
|
45
|
+
return {
|
|
46
|
+
isError: true,
|
|
47
|
+
content: [{ type: "text", text: `Image not found: ${validated.uri}` }],
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const ext = path.extname(filename).toLowerCase();
|
|
51
|
+
const mimeType = MIME_TYPES[ext] ?? "application/octet-stream";
|
|
52
|
+
const data = fs.readFileSync(filePath).toString("base64");
|
|
53
|
+
return {
|
|
54
|
+
content: [
|
|
55
|
+
{
|
|
56
|
+
type: "image",
|
|
57
|
+
data,
|
|
58
|
+
mimeType,
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
65
|
+
return { isError: true, content: [{ type: "text", text: `Error retrieving image: ${message}` }] };
|
|
66
|
+
}
|
|
67
|
+
}
|
package/dist/src/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const APP_VERSION = "1.0.
|
|
1
|
+
export declare const APP_VERSION = "1.0.53";
|
package/dist/src/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Auto-generated version file - do not edit manually
|
|
2
|
-
export const APP_VERSION = '1.0.
|
|
2
|
+
export const APP_VERSION = '1.0.53';
|