Skip to main content
Glama

image-upsert

Store image data (base64 or file path) under a unique key, returning an image ID. Integrates with MCP Index Notes for efficient note management, tagging, and semantic connections.

Instructions

Store an image (base64 data or file path) under a key. Returns image id.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataNoBase64-encoded image data (no data: prefix)
fileNoPath to image file to read if data not provided
keyYes
metadataNo
mimeNoMIME type e.g. image/png if data provided

Implementation Reference

  • Executes the image-upsert tool: validates input with ImageUpsertSchema, loads image data from base64 or file path, guesses MIME type if needed, calls db.insertImage, returns the new image ID.
    case 'image-upsert': { const parsed = ImageUpsertSchema.parse(args); if (!('insertImage' in (db as any))) { throw new Error('Image storage not supported in current store implementation'); } const fs = await import('fs'); let raw: Buffer | null = null; if (parsed.data) { raw = Buffer.from(parsed.data, 'base64'); } else if (parsed.file) { raw = fs.readFileSync(parsed.file); } else { throw new Error('Provide data (base64) or file'); } // crude mime guess if not provided let mime = parsed.mime; if (!mime && parsed.file) { const ext = parsed.file.toLowerCase(); if (ext.endsWith('.png')) mime = 'image/png'; else if (ext.endsWith('.jpg') || ext.endsWith('.jpeg')) mime = 'image/jpeg'; else if (ext.endsWith('.gif')) mime = 'image/gif'; else if (ext.endsWith('.webp')) mime = 'image/webp'; else mime = 'application/octet-stream'; } if (!mime) mime = 'application/octet-stream'; const id = (db as any).insertImage({ key: parsed.key, mime, data: raw!, metadata: parsed.metadata }); return { content: [{ type: 'text', text: JSON.stringify({ id }) }] }; }
  • Zod input schema for image-upsert tool defining key (required), optional data (base64), file path, mime type, and metadata.
    export const ImageUpsertSchema = z.object({ key: z.string().min(1, 'key is required'), // Either provide raw base64 data (without data:mime prefix) or a file path to read data: z.string().optional(), file: z.string().optional(), mime: z.string().optional(), metadata: z.record(z.any()).optional().default({}), }); export type ImageUpsertInput = z.infer<typeof ImageUpsertSchema>;
  • src/mcp.ts:62-75 (registration)
    MCP tool registration defining name 'image-upsert', description, and inputSchema (JSON schema version of the Zod schema).
    name: 'image-upsert', description: 'Store an image (base64 data or file path) under a key. Returns image id.', inputSchema: { type: 'object', properties: { key: { type: 'string' }, data: { type: 'string', description: 'Base64-encoded image data (no data: prefix)' }, file: { type: 'string', description: 'Path to image file to read if data not provided' }, mime: { type: 'string', description: 'MIME type e.g. image/png if data provided' }, metadata: { type: 'object' }, }, required: ['key'], }, },
  • Database helper method that inserts image record into SQLite 'images' table, storing key, mime, size, metadata (JSON), and binary data (BLOB), returns inserted ID.
    insertImage(img: { key: string; mime: string; data: Buffer; metadata?: any }): number { const stmt = this.db.prepare(`INSERT INTO images (key, mime, size, metadata, data) VALUES (@key, @mime, @size, @metadata, @data)`); const info = stmt.run({ key: img.key, mime: img.mime, size: img.data.length, metadata: JSON.stringify(img.metadata ?? {}), data: img.data, }); return Number(info.lastInsertRowid); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/vjsr007/mcp-index-notes'

If you have feedback or need assistance with the MCP directory API, please join our Discord server