Skip to main content
Glama

upload_product_image

Attach an image to a product by providing a public URL. Shopify fetches and hosts the image on its CDN, adding it without replacing existing images.

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 handler for the 'upload_product_image' tool. Takes product_id, image_url, and optional alt_text, converts product_id to GID, then calls attachImages() to upload the image via Shopify's API.
      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(", ")}`,
            },
          ],
        };
      },
    );
  • Zod schema for upload_product_image: product_id (string), image_url (string/url), alt_text (optional string).
    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' tool via server.tool() inside registerProductTools(), with description and schema.
    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(", ")}`,
            },
          ],
        };
      },
    );
  • Helper function attachImages() that executes the GraphQL mutation to attach image(s) to a product. Uses CREATE_MEDIA_MUTATION.
    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,
      );
    }
  • GraphQL mutation CREATE_MEDIA_MUTATION used by attachImages to create media (images) on a product.
    const CREATE_MEDIA_MUTATION = /* GraphQL */ `
      mutation ProductCreateMedia($productId: ID!, $media: [CreateMediaInput!]!) {
        productCreateMedia(productId: $productId, media: $media) {
          media {
            ... on MediaImage {
              id
              image { url altText }
            }
          }
          mediaUserErrors { field message }
        }
      }
    `;
Behavior4/5

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

With no annotations, the description carries full burden. It discloses key behaviors: server-side fetch, URL must be publicly reachable from Shopify's network, and that multiple calls add images (not replace). Missing details on error handling or permissions, but covers essential safety-critical behaviors.

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?

Two sentences, front-loaded with the core action and key constraints. Every sentence adds value: the first explains what it does and how it works, the second provides alternative usage. No wasted 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?

For a simple attach-image tool, the description covers purpose, guidelines, behavioral traits, and key parameter context. Lacks explanation of return values or error conditions, but given the straightforward operation and no output schema, it is mostly complete.

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?

The description adds meaning for image_url by specifying that it must be publicly reachable from Shopify's network, beyond the schema's format and description. However, alt_text remains without added explanation, and schema coverage for alt_text is missing. Overall, partial compensation but not comprehensive.

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?

Clearly states 'Attach an image to an existing product by URL', specifying the verb and resource. Explicitly differentiates from sibling tools like generate_product_image and refine_product_image.

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?

Provides explicit guidance: when to use this tool vs alternatives ('Use the bridge tools... instead when you want the image generated by ComfyUI'). Also notes that multiple calls add multiple images, clarifying behavior.

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