Skip to main content
Glama

upload_product_image

Attach a product image from a public URL to an existing Shopify product. Each call adds a new image without removing existing ones.

Instructions

Attach an image to an existing product by URL. Shopify fetches the URL server-side and hosts the file on its CDN — the URL must be publicly reachable from Shopify's network. Multiple calls add multiple images; this tool does not replace existing images. Use the bridge tools (generate_product_image, refine_product_image) instead when you want the image generated by ComfyUI rather than provided as a URL.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
product_idYesProduct GID or numeric ID
image_urlYesPublic image URL to attach
alt_textNo

Implementation Reference

  • The tool handler function for 'upload_product_image'. It converts the product_id to a GID, then calls attachImages to attach the image URL to the product via Shopify's GraphQL API.
    server.tool(
      "upload_product_image",
      "Attach an image to an existing product by URL. Shopify fetches the URL server-side and hosts the file on its CDN — the URL must be publicly reachable from Shopify's network. Multiple calls add multiple images; this tool does not replace existing images. Use the bridge tools (generate_product_image, refine_product_image) instead when you want the image generated by ComfyUI rather than provided as a URL.",
      uploadProductImageSchema,
      async (args) => {
        const productId = toGid(args.product_id, "Product");
        const result = await attachImages(client, productId, [args.image_url], args.alt_text);
        return {
          content: [
            {
              type: "text" as const,
              text: `Attached image to ${productId}: ${result.map((m) => m.id).join(", ")}`,
            },
          ],
        };
      },
    );
  • Input schema for upload_product_image: product_id (string), image_url (URL string), and optional alt_text.
    const uploadProductImageSchema = {
      product_id: z.string().describe("Product GID or numeric ID"),
      image_url: z.string().url().describe("Public image URL to attach"),
      alt_text: z.string().optional(),
    };
  • Registration of 'upload_product_image' via server.tool() inside registerProductTools.
    server.tool(
      "upload_product_image",
      "Attach an image to an existing product by URL. Shopify fetches the URL server-side and hosts the file on its CDN — the URL must be publicly reachable from Shopify's network. Multiple calls add multiple images; this tool does not replace existing images. Use the bridge tools (generate_product_image, refine_product_image) instead when you want the image generated by ComfyUI rather than provided as a URL.",
      uploadProductImageSchema,
      async (args) => {
        const productId = toGid(args.product_id, "Product");
        const result = await attachImages(client, productId, [args.image_url], args.alt_text);
        return {
          content: [
            {
              type: "text" as const,
              text: `Attached image to ${productId}: ${result.map((m) => m.id).join(", ")}`,
            },
          ],
        };
      },
    );
  • The attachImages helper function that calls the productCreateMedia GraphQL mutation to attach images to a product by URL.
    export async function attachImages(
      client: ShopifyClient,
      productId: string,
      imageUrls: string[],
      altText?: string,
    ): Promise<Array<{ id: string }>> {
      const data = await client.graphql<{
        productCreateMedia: {
          media: Array<{ id: string } | null>;
          mediaUserErrors: ShopifyUserError[];
        };
      }>(CREATE_MEDIA_MUTATION, {
        productId,
        media: imageUrls.map((url) => ({
          originalSource: url,
          mediaContentType: "IMAGE",
          alt: altText,
        })),
      });
      throwIfUserErrors(data.productCreateMedia.mediaUserErrors, "productCreateMedia");
      return data.productCreateMedia.media.filter(
        (m): m is { id: string } => m !== null,
      );
    }
  • The stagedUploadImage helper for uploading raw image bytes to Shopify's staged storage (used by bridge tools, not upload_product_image directly).
    export async function stagedUploadImage(
      client: ShopifyClient,
      bytes: Uint8Array,
      filename: string,
      mimeType: string,
    ): Promise<string> {
      const data = await client.graphql<{
        stagedUploadsCreate: {
          stagedTargets: StagedTarget[];
          userErrors: ShopifyUserError[];
        };
      }>(STAGED_UPLOADS_CREATE_MUTATION, {
        input: [
          {
            resource: "IMAGE",
            filename,
            mimeType,
            fileSize: String(bytes.length),
            httpMethod: "POST",
          },
        ],
      });
      throwIfUserErrors(
        data.stagedUploadsCreate.userErrors,
        "stagedUploadsCreate",
      );
    
      const target = data.stagedUploadsCreate.stagedTargets[0];
      if (!target) {
        throw new Error("stagedUploadsCreate returned no target");
      }
    
      const form = new FormData();
      for (const { name, value } of target.parameters) {
        form.append(name, value);
      }
      form.append("file", new Blob([new Uint8Array(bytes)], { type: mimeType }), filename);
    
      const uploadRes = await fetch(target.url, {
        method: "POST",
        body: form,
      });
      if (!uploadRes.ok && uploadRes.status !== 201 && uploadRes.status !== 204) {
        throw new Error(
          `Shopify staged upload POST failed: ${uploadRes.status} ${await uploadRes.text()}`,
        );
      }
    
      return target.resourceUrl;
    }
Behavior4/5

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

No annotations provided, so description carries full burden. It discloses server-side fetch, CDN hosting, public URL requirement, and cumulative nature of image addition. Missing details on error handling or permissions, but still informative.

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?

Three concise, well-structured sentences. First states purpose, second adds behavioral context, third provides alternatives. No unnecessary words.

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

Completeness4/5

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

Given 3 params, no output schema, and no annotations, description covers core behavior (URL requirement, multiple calls) and usage. Lacks response details but acceptable.

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 coverage is 67% (alt_text missing description). Description adds no new info about parameters beyond schema, especially missing alt_text. Adequate but not exceptional.

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

Purpose5/5

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

The description clearly states the action ('Attach an image to an existing product by URL'), specifying the verb, resource, and method. It distinguishes from sibling bridge tools for ComfyUI-generated images.

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

Usage Guidelines5/5

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

Explicitly explains when to use (URL-based attachment) and when not to (use bridge tools for ComfyUI). Also notes that multiple calls add multiple images without replacement.

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/miller-joe/shopify-mcp'

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