Skip to main content
Glama

gemini_analyze_image

Analyze images using Google Gemini's multimodal AI to extract descriptions, answer questions, or process visual content through configurable models and output formats.

Instructions

Use Google Gemini CLI to describe or analyze an image using multimodal capabilities.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
imageYesLocal file path, http(s) URL, or base64-encoded image to analyze.
promptNoInstruction for Gemini. Defaults to config value.
modelNoGemini model identifier (e.g., gemini-2.0-flash).
cliPathNoOverride the Gemini CLI executable path.
sandboxNoWhether to run the CLI with the sandbox flag (-s).
outputFormatNoRequest Gemini CLI to return the specified output format.
extraFlagsNoAdditional CLI flags to append as-is.
timeoutMsNoMaximum time (in milliseconds) to wait for CLI execution.

Implementation Reference

  • The main handler function for the gemini_analyze_image tool. Prepares the image input, constructs the analysis prompt, invokes the Gemini image analysis helper, formats the output with metadata, and handles errors appropriately.
    async execute(args: GeminiArgs) {
      const prepared = await prepareImage(args.image, appConfig);
      const prompt =
        args.prompt?.trim() ??
        appConfig.gemini.defaultPrompt ??
        "Describe this image.";
      const attachment = createAttachmentReference(prepared.path);
      try {
        const result = await runGeminiImageAnalysis({
          prompt,
          model: args.model,
          sandbox: args.sandbox,
          outputFormat: args.outputFormat,
          extraFlags: args.extraFlags,
          timeoutMs: args.timeoutMs ?? appConfig.commandTimeoutMs,
          imageReference: attachment,
          preparedImage: prepared,
          commandOverride: args.cliPath,
        });
    
        const cleaned = result.stdout || "(Gemini CLI returned no output)";
        const metaLines = [
          `model: ${result.model ?? "default"}`,
          `imageSource: ${prepared.source}`,
          `durationMs: ${result.durationMs}`,
        ];
        if (prepared.source === "local") {
          metaLines.push(`imagePath: ${prepared.path}`);
        }
    
        return {
          content: [
            {
              type: "text",
              text: [
                "### Gemini Output",
                cleaned,
                "",
                metaLines.join("\n"),
              ].join("\n"),
            },
          ],
          isError: false,
        } as const;
      } catch (error) {
        if (error instanceof CommandError) {
          const details = [
            error.message,
            error.result.stderr.trim() && `stderr:\n${error.result.stderr.trim()}`,
            error.result.stdout.trim() && `stdout:\n${error.result.stdout.trim()}`,
          ]
            .filter(Boolean)
            .join("\n\n");
          return {
            content: [
              {
                type: "text",
                text: `Gemini CLI failed:\n${details}`,
              },
            ],
            isError: true,
          };
        }
        throw error;
      } finally {
        await prepared.cleanup();
      }
    },
  • Zod schema defining the input validation and descriptions for the gemini_analyze_image tool parameters.
    const geminiSchema = z
      .object({
        image: z
          .string()
          .min(1)
          .describe(
            "Local file path, http(s) URL, or base64-encoded image to analyze."
          ),
        prompt: z
          .string()
          .min(1)
          .optional()
          .describe("Instruction for Gemini. Defaults to config value."),
        model: z
          .string()
          .min(1)
          .optional()
          .describe("Gemini model identifier (e.g., gemini-2.0-flash)."),
        cliPath: z
          .string()
          .min(1)
          .optional()
          .describe("Override the Gemini CLI executable path."),
        sandbox: z
          .boolean()
          .optional()
          .describe("Whether to run the CLI with the sandbox flag (-s)."),
        outputFormat: z
          .enum(["text", "json"])
          .optional()
          .describe("Request Gemini CLI to return the specified output format."),
        extraFlags: z
          .array(z.string().min(1))
          .optional()
          .describe("Additional CLI flags to append as-is."),
        timeoutMs: z
          .number()
          .int()
          .positive()
          .max(600_000)
          .optional()
          .describe("Maximum time (in milliseconds) to wait for CLI execution."),
      })
      .describe("Invoke Gemini CLI to analyze an image.");
  • Tool registration call that defines the name, description, schema, and handler for gemini_analyze_image.
    registerTool({
      name: "gemini_analyze_image",
      description:
        "Use Google Gemini CLI to describe or analyze an image using multimodal capabilities.",
      schema: geminiSchema,
      async execute(args: GeminiArgs) {
        const prepared = await prepareImage(args.image, appConfig);
        const prompt =
          args.prompt?.trim() ??
          appConfig.gemini.defaultPrompt ??
          "Describe this image.";
        const attachment = createAttachmentReference(prepared.path);
        try {
          const result = await runGeminiImageAnalysis({
            prompt,
            model: args.model,
            sandbox: args.sandbox,
            outputFormat: args.outputFormat,
            extraFlags: args.extraFlags,
            timeoutMs: args.timeoutMs ?? appConfig.commandTimeoutMs,
            imageReference: attachment,
            preparedImage: prepared,
            commandOverride: args.cliPath,
          });
    
          const cleaned = result.stdout || "(Gemini CLI returned no output)";
          const metaLines = [
            `model: ${result.model ?? "default"}`,
            `imageSource: ${prepared.source}`,
            `durationMs: ${result.durationMs}`,
          ];
          if (prepared.source === "local") {
            metaLines.push(`imagePath: ${prepared.path}`);
          }
    
          return {
            content: [
              {
                type: "text",
                text: [
                  "### Gemini Output",
                  cleaned,
                  "",
                  metaLines.join("\n"),
                ].join("\n"),
              },
            ],
            isError: false,
          } as const;
        } catch (error) {
          if (error instanceof CommandError) {
            const details = [
              error.message,
              error.result.stderr.trim() && `stderr:\n${error.result.stderr.trim()}`,
              error.result.stdout.trim() && `stdout:\n${error.result.stdout.trim()}`,
            ]
              .filter(Boolean)
              .join("\n\n");
            return {
              content: [
                {
                  type: "text",
                  text: `Gemini CLI failed:\n${details}`,
                },
              ],
              isError: true,
            };
          }
          throw error;
        } finally {
          await prepared.cleanup();
        }
      },
    });
  • Helper function that constructs and executes the Gemini CLI command for image analysis, building arguments from options and running the command via runCommand.
    export async function runGeminiImageAnalysis(
      options: GeminiImageOptions
    ): Promise<GeminiSuccessResult> {
      const cliArgs: string[] = [];
    
      const model = options.model ?? appConfig.gemini.defaultModel;
      if (model) {
        cliArgs.push("-m", model);
      }
    
      const outputFormat =
        options.outputFormat ?? appConfig.gemini.defaultOutputFormat;
      if (outputFormat && outputFormat !== "text") {
        cliArgs.push("-o", outputFormat);
      }
    
      if (options.sandbox) {
        cliArgs.push("-s");
      }
    
      if (appConfig.gemini.extraArgs?.length) {
        cliArgs.push(...appConfig.gemini.extraArgs);
      }
    
      if (options.extraFlags?.length) {
        cliArgs.push(...options.extraFlags);
      }
    
      const finalPrompt = `${options.prompt.trim()}\n\n${options.imageReference}`;
      cliArgs.push("-p", finalPrompt);
    
      const command = options.commandOverride ?? appConfig.gemini.command;
    
      const result = await runCommand(command, cliArgs, {
        timeoutMs: options.timeoutMs,
      });
    
      return {
        stdout: result.stdout.trim(),
        durationMs: result.durationMs,
        model,
      };
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure but offers minimal information. It mentions 'multimodal capabilities' but doesn't explain what this means operationally, nor does it cover important behavioral aspects like rate limits, authentication requirements, error handling, or what happens when the CLI fails. The description is too vague about the tool's actual behavior.

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

Conciseness5/5

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

The description is extremely concise at just one sentence with zero wasted words. It's front-loaded with the core functionality and efficiently communicates the essential purpose without unnecessary elaboration. Every word earns its place in this minimal description.

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?

For a tool with 8 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what the tool returns, how to interpret results, error conditions, or operational constraints. The description fails to compensate for the lack of structured metadata, leaving significant gaps in understanding how to effectively use this complex tool.

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

Parameters3/5

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

With 100% schema description coverage, the schema already documents all 8 parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema, so it meets the baseline of 3. The description doesn't explain parameter interactions, default behaviors, or provide examples of effective parameter combinations.

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 ('describe or analyze an image') and the technology used ('Google Gemini CLI with multimodal capabilities'), which provides a specific verb+resource combination. However, it doesn't explicitly differentiate from its sibling 'qwen_analyze_image' beyond mentioning the different technology stack.

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?

The description provides no guidance on when to use this tool versus alternatives, including its sibling 'qwen_analyze_image'. There's no mention of specific use cases, prerequisites, or comparative advantages that would help an agent choose between available image analysis tools.

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/ah-wq/mcp-vision-relay'

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