Skip to main content
Glama

session_view_image

Retrieve images from visual memory using their ID for AI analysis. Returns Base64-encoded content to help LLMs process and understand visual data from stored sessions.

Instructions

Retrieve an image from visual memory using its ID. Returns the image as Base64 inline content for the LLM to analyze. Use session_load_context first to see available image IDs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectYesProject identifier.
image_idYesThe short image ID (e.g., '8f2a1b3c') from the visual memory index.

Implementation Reference

  • The handler function for 'session_view_image', which loads image metadata from storage and retrieves the file from the local vault.
    export async function sessionViewImageHandler(args: unknown) {
      if (!isSessionViewImageArgs(args)) {
        return {
          content: [{ type: "text", text: "Invalid arguments. Requires: project, image_id." }],
          isError: true,
        };
      }
    
      const { project, image_id } = args;
    
      // Load context to find image metadata
      const storage = await getStorage();
      const context = await storage.loadContext(project, "quick", PRISM_USER_ID);
      const visuals = (context as any)?.metadata?.visual_memory || [];
      const imgMeta = visuals.find((v: any) => v.id === image_id);
    
      if (!imgMeta) {
        return {
          content: [{
            type: "text",
            text: `Error: Image ID [${image_id}] not found in visual memory for project "${project}".` +
              (visuals.length > 0
                ? `\n\nAvailable IDs: ${visuals.map((v: any) => `${v.id} (${v.description})`).join(", ")}`
                : "\n\nNo images saved in visual memory yet."),
          }],
          isError: true,
        };
      }
    
      const vaultPath = nodePath.join(os.homedir(), ".prism-mcp", "media", project, imgMeta.filename);
      if (!fs.existsSync(vaultPath)) {
        return {
          content: [{
            type: "text",
            text: `Error: Image file missing from vault at "${vaultPath}". ` +
              `The metadata exists but the file was deleted.`,
          }],
          isError: true,
        };
      }
    
      // Read file and convert to base64
      const base64Data = fs.readFileSync(vaultPath).toString("base64");
    
      // Determine MIME type from extension
      const ext = nodePath.extname(imgMeta.filename).toLowerCase();
      const MIME_MAP: Record<string, string> = {
        ".png": "image/png",
        ".jpg": "image/jpeg",
        ".jpeg": "image/jpeg",
        ".webp": "image/webp",
        ".gif": "image/gif",
        ".svg": "image/svg+xml",
      };
      const mimeType = MIME_MAP[ext] || "image/png";
  • The definition of the SESSION_VIEW_IMAGE_TOOL including its input schema and description.
    export const SESSION_VIEW_IMAGE_TOOL: Tool = {
      name: "session_view_image",
      description:
        "Retrieve an image from visual memory using its ID. " +
        "Returns the image as Base64 inline content for the LLM to analyze. " +
        "Use session_load_context first to see available image IDs.",
      inputSchema: {
        type: "object",
        properties: {
          project: {
            type: "string",
            description: "Project identifier.",
          },
          image_id: {
            type: "string",
            description: "The short image ID (e.g., '8f2a1b3c') from the visual memory index.",
          },
        },
        required: ["project", "image_id"],
      },
    };
  • Type guard function 'isSessionViewImageArgs' for the 'session_view_image' tool arguments.
    export function isSessionViewImageArgs(
      args: unknown
    ): args is { project: string; image_id: string } {
      return (
        typeof args === "object" &&
        args !== null &&
        "project" in args &&
        typeof (args as { project: string }).project === "string" &&
        "image_id" in args &&
        typeof (args as { image_id: string }).image_id === "string"
      );
    }

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/dcostenco/BCBA'

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