Skip to main content
Glama

qwen_analyze_image

Analyze images using Qwen's multimodal AI to extract descriptions, answer questions, and process visual content for text-based assistants.

Instructions

Use Qwen CLI to describe or analyze an image with its multimodal capabilities.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
imageYesLocal file path, http(s) URL, or base64-encoded image to analyze.
promptNoInstruction for Qwen. Defaults to config value.
modelNoQwen model identifier.
cliPathNoOverride the Qwen CLI executable path.
sandboxNoWhether to run the CLI with the sandbox flag (-s).
extraFlagsNoAdditional CLI flags to append as-is.
timeoutMsNoMaximum time (in milliseconds) to wait for CLI execution.

Implementation Reference

  • The async execute function that implements the core tool logic: prepares the image, calls runQwenImageAnalysis, formats the output with metadata, handles errors, and cleans up temporary files.
    async execute(args: QwenArgs) {
      const originalInput = args.image.trim();
      const prepared = await prepareImage(originalInput, appConfig);
      const prompt =
        args.prompt?.trim() ??
        appConfig.qwen.defaultPrompt ??
        "请描述这张图片的内容。";
    
      try {
        const result = await runQwenImageAnalysis({
          prompt,
          model: args.model,
          sandbox: args.sandbox,
          extraFlags: args.extraFlags,
          timeoutMs: args.timeoutMs ?? appConfig.commandTimeoutMs,
          originalInput,
          preparedImage: prepared,
          commandOverride: args.cliPath,
        });
    
        const cleaned = result.stdout || "(Qwen 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: [
                "### Qwen 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: `Qwen CLI failed:\n${details}`,
              },
            ],
            isError: true,
          };
        }
        throw error;
      } finally {
        await prepared.cleanup();
      }
    },
  • Zod schema (qwenSchema) defining the input parameters for the tool, including image path/URL/base64, optional prompt, model, CLI options, etc.
    const qwenSchema = 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 Qwen. Defaults to config value."),
        model: z
          .string()
          .min(1)
          .optional()
          .describe("Qwen model identifier."),
        cliPath: z
          .string()
          .min(1)
          .optional()
          .describe("Override the Qwen CLI executable path."),
        sandbox: z
          .boolean()
          .optional()
          .describe("Whether to run the CLI with the sandbox flag (-s)."),
        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 Qwen CLI to analyze an image.");
  • Tool registration via registerTool({ name: "qwen_analyze_image", description, schema, execute }) which defines and registers the tool.
    registerTool({
      name: "qwen_analyze_image",
      description:
        "Use Qwen CLI to describe or analyze an image with its multimodal capabilities.",
      schema: qwenSchema,
      async execute(args: QwenArgs) {
        const originalInput = args.image.trim();
        const prepared = await prepareImage(originalInput, appConfig);
        const prompt =
          args.prompt?.trim() ??
          appConfig.qwen.defaultPrompt ??
          "请描述这张图片的内容。";
    
        try {
          const result = await runQwenImageAnalysis({
            prompt,
            model: args.model,
            sandbox: args.sandbox,
            extraFlags: args.extraFlags,
            timeoutMs: args.timeoutMs ?? appConfig.commandTimeoutMs,
            originalInput,
            preparedImage: prepared,
            commandOverride: args.cliPath,
          });
    
          const cleaned = result.stdout || "(Qwen 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: [
                  "### Qwen 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: `Qwen CLI failed:\n${details}`,
                },
              ],
              isError: true,
            };
          }
          throw error;
        } finally {
          await prepared.cleanup();
        }
      },
    });
  • runQwenImageAnalysis helper function that constructs the data URL from image, builds CLI arguments, runs the Qwen CLI command using runCommand, and returns stdout, duration, model.
    export async function runQwenImageAnalysis(
      options: QwenImageOptions
    ): Promise<QwenSuccessResult> {
      const buffer = await fs.readFile(options.preparedImage.path);
      const mimeType = guessImageMimeType(
        options.preparedImage.path,
        "image/jpeg"
      );
      const dataUrl = `data:${mimeType};base64,${buffer.toString("base64")}`;
    
      const imageReference = /^https?:\/\//i.test(options.originalInput)
        ? options.originalInput
        : dataUrl;
    
      const cliArgs: string[] = [];
      const model = options.model ?? appConfig.qwen.defaultModel;
      if (model) {
        cliArgs.push("-m", model);
      }
    
      if (options.sandbox) {
        cliArgs.push("-s");
      }
    
      if (appConfig.qwen.extraArgs?.length) {
        cliArgs.push(...appConfig.qwen.extraArgs);
      }
    
      if (options.extraFlags?.length) {
        cliArgs.push(...options.extraFlags);
      }
    
      const finalPrompt = `${options.prompt.trim()}\n\n${imageReference}`;
      cliArgs.push("-p", finalPrompt);
    
      const result = await runCommand(
        options.commandOverride ?? appConfig.qwen.command,
        cliArgs,
        {
          timeoutMs: options.timeoutMs,
        }
      );
    
      return {
        stdout: result.stdout.trim(),
        durationMs: result.durationMs,
        model,
        promptUsed: finalPrompt,
      };
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. The description mentions 'multimodal capabilities' but doesn't explain what this entails (e.g., types of analysis, output format, limitations). It also lacks details on permissions, rate limits, error handling, or what happens during execution (e.g., whether it's synchronous). This leaves significant gaps for an agent to understand the tool's 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 a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, with every element ('Use Qwen CLI', 'describe or analyze an image', 'multimodal capabilities') contributing essential information. There's zero waste in the 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 the complexity (7 parameters, no annotations, no output schema), the description is insufficiently complete. It doesn't explain the return values or output format, which is critical since there's no output schema. It also lacks behavioral context (e.g., what 'analyze' entails, error cases, or performance characteristics). For a tool with this many parameters and no structured support, the description should provide more guidance.

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?

Schema description coverage is 100%, so the input schema fully documents all 7 parameters with clear descriptions. The tool description adds no additional parameter information beyond what's in the schema. According to the rules, when schema coverage is high (>80%), the baseline score is 3 even with no param info in the description, which applies here.

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 tool's purpose: 'describe or analyze an image with its multimodal capabilities' using Qwen CLI. It specifies the verb ('describe or analyze'), resource ('image'), and technology ('Qwen CLI'), making the purpose unambiguous. However, it doesn't explicitly differentiate from its sibling 'gemini_analyze_image' beyond mentioning Qwen specifically.

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. It doesn't mention the sibling tool 'gemini_analyze_image' or any other alternatives, nor does it provide context about when Qwen might be preferred over other image analysis tools. Usage is implied through the tool name and description but not explicitly stated.

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