image-get
Retrieve images by ID or key and optionally include base64 data. Simplify image access and management on the MCP Index Notes server for enhanced note organization and retrieval.
Instructions
Retrieve images by id or key. Optionally include base64 data.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | No | ||
| includeData | No | ||
| key | No | ||
| limit | No |
Implementation Reference
- src/mcp.ts:1398-1412 (handler)Main handler logic for the 'image-get' tool within the CallToolRequestSchema request handler. Parses input using ImageGetSchema, checks store support, calls appropriate DB methods (getImageById or getImagesByKey), and returns JSON serialized results.case 'image-get': { const parsed = ImageGetSchema.parse(args ?? {}); if (!('getImageById' in (db as any))) { throw new Error('Image storage not supported in current store implementation'); } let result: any = null; if (parsed.id) { result = (db as any).getImageById(parsed.id, parsed.includeData); } else if (parsed.key) { result = (db as any).getImagesByKey(parsed.key, parsed.limit, parsed.includeData); } else { result = []; } return { content: [{ type: 'text', text: JSON.stringify(result) }] }; }
- src/mcp.ts:77-88 (registration)Tool registration in the tools array exported for ListToolsRequestSchema. Defines name 'image-get', description, and input schema structure.name: 'image-get', description: 'Retrieve images by id or key. Optionally include base64 data.', inputSchema: { type: 'object', properties: { id: { type: 'number' }, key: { type: 'string' }, limit: { type: 'number' }, includeData: { type: 'boolean' }, }, }, },
- src/types.ts:103-109 (schema)Zod schema ImageGetSchema used for input validation in the handler. Defines optional id, key, limit (default 10, max 50), includeData (default false). Type alias ImageGetInput.export const ImageGetSchema = z.object({ id: z.number().int().positive().optional(), key: z.string().optional(), limit: z.number().int().positive().max(50).optional().default(10), includeData: z.boolean().optional().default(false), }); export type ImageGetInput = z.infer<typeof ImageGetSchema>;
- src/db.ts:205-210 (helper)Core helper function getImagesByKey in NotesDB class. Queries images table by key, optionally includes data BLOB, converts rows to ImageRecord using rowToImage.getImagesByKey(key: string, limit = 10, includeData = false): ImageRecord[] { const rows = this.db .prepare(`SELECT id, key, mime, size, metadata, created_at ${includeData ? ', data' : ''} FROM images WHERE key = ? ORDER BY created_at DESC LIMIT ?`) .all(key, limit); return rows.map((r: any) => this.rowToImage(r, includeData)); }
- src/db.ts:212-217 (helper)Core helper function getImageById in NotesDB class. Retrieves single image by id, optionally includes data BLOB, converts to ImageRecord.getImageById(id: number, includeData = false): ImageRecord | null { const row = this.db .prepare(`SELECT id, key, mime, size, metadata, created_at ${includeData ? ', data' : ''} FROM images WHERE id = ?`) .get(id); return row ? this.rowToImage(row, includeData) : null; }