Skip to main content
Glama
vjsr007
by vjsr007

image-export

Export images by ID or key into specified directories using this MCP Index Notes tool. Returns file paths for easy access and integration.

Instructions

Export images (by id or key) to files. Returns file paths.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dirNo
idNo
keyNo
limitNo

Implementation Reference

  • Handler for 'image-export' tool: parses input schema, fetches images from database (by id or key), creates export directory, writes base64 data to files with appropriate extensions, returns directory and file paths.
    case 'image-export': {
      const parsed = ImageExportSchema.parse(args ?? {});
      if (!('getImageById' in (db as any))) {
        throw new Error('Image storage not supported in current store implementation');
      }
      const fs = await import('fs');
      const path = await import('path');
      const exportDir = parsed.dir ? path.resolve(parsed.dir) : path.resolve(process.cwd(), 'exported-images');
      if (!fs.existsSync(exportDir)) fs.mkdirSync(exportDir, { recursive: true });
      let images: any[] = [];
      if (parsed.id) {
        const one = (db as any).getImageById(parsed.id, true);
        if (one) images = [one];
      } else if (parsed.key) {
        images = (db as any).getImagesByKey(parsed.key, parsed.limit, true);
      } else {
        return { content: [{ type: 'text', text: JSON.stringify({ error: 'Provide id or key' }) }] };
      }
      const files: string[] = [];
      for (const img of images) {
        if (!img.data) continue;
          const safeKey = img.key.replace(/[^a-zA-Z0-9._-]+/g, '_').slice(0, 60);
          const ext = (() => {
            switch (img.mime) {
              case 'image/png': return '.png';
              case 'image/jpeg': return '.jpg';
              case 'image/gif': return '.gif';
              case 'image/webp': return '.webp';
              default: return '.bin';
            }
          })();
          const filename = `${safeKey}-${img.id}${ext}`;
          const outPath = path.join(exportDir, filename);
          fs.writeFileSync(outPath, Buffer.from(img.data, 'base64'));
          files.push(outPath);
      }
      return { content: [{ type: 'text', text: JSON.stringify({ dir: exportDir, files }) }] };
    }
  • src/mcp.ts:97-109 (registration)
    Tool registration entry for 'image-export' in the tools array, defining name, description, and input schema.
    {
      name: 'image-export',
      description: 'Export images (by id or key) to files. Returns file paths.',
      inputSchema: {
        type: 'object',
        properties: {
          id: { type: 'number' },
          key: { type: 'string' },
          limit: { type: 'number' },
          dir: { type: 'string' },
        },
      },
    },
  • Zod input schema and TypeScript type for image-export tool parameters.
    export const ImageExportSchema = z.object({
      id: z.number().int().positive().optional(),
      key: z.string().optional(),
      limit: z.number().int().positive().max(100).optional().default(20),
      dir: z.string().optional(),
      includeData: z.boolean().optional().default(true), // force include data if not provided
    });
    export type ImageExportInput = z.infer<typeof ImageExportSchema>;
  • Database helper method to retrieve a single image by ID, optionally including base64 data.
    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;
    }
  • Database helper method to retrieve images by key, with limit and optional base64 data inclusion.
    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));
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It mentions the return value ('Returns file paths') but lacks details on permissions, side effects (e.g., file system changes), error handling, or performance (e.g., rate limits). For a tool that likely writes files, this is inadequate disclosure.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is brief and front-loaded with the core purpose in the first clause. Both sentences are relevant, with the second adding return value information. However, it could be more structured (e.g., separating input and output details) and slightly verbose in phrasing.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 4 parameters with 0% schema coverage, no annotations, and no output schema, the description is incomplete. It omits critical details like parameter usage, file formats, error cases, and output structure beyond 'file paths'. For an export tool with multiple inputs, this leaves significant gaps for an agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate but fails to do so. It implies 'id' or 'key' parameters for image identification but doesn't explain 'dir' (output directory), 'limit' (number of images), or their interactions. No syntax, formats, or constraints are provided, leaving parameters largely undocumented.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Export images') and resource ('images'), specifying they can be identified 'by id or key' and output 'to files'. It distinguishes from siblings like image-get (retrieval) and image-delete (removal) by focusing on file export. However, it doesn't explicitly differentiate from non-image tools, keeping it at 4 rather than 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., existing images), exclusions (e.g., invalid formats), or comparisons to siblings like image-get (which might retrieve without exporting). The description only states what it does, not when to choose it.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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