Skip to main content
Glama

get_product

Fetch a product by ID to get its title, handle, status, inventory totals, images, and first 20 variants with prices and inventory item IDs needed for inventory quantity updates.

Instructions

Fetch a single product's full record by GID or numeric ID. Returns header fields (title, handle, status, vendor, productType, description, tags), inventory totals, the first 10 images and 10 media items, and the first 20 variants with their prices, SKUs, inventory quantities, and inventoryItem GIDs. Returned as JSON for downstream tooling. The variant inventoryItem GIDs are needed by set_inventory_quantity. For more than 20 variants, follow up with list_variants.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesProduct GID (gid://shopify/Product/123...) or numeric ID

Implementation Reference

  • The 'get_product' tool handler. It accepts an 'id' argument, converts it to a GID via toGid(), executes the GET_PRODUCT_QUERY GraphQL query, and returns the product detail as JSON. If the product is not found, it returns a 'Product not found' message.
    server.tool(
      "get_product",
      "Fetch a single product's full record by GID or numeric ID. Returns header fields (title, handle, status, vendor, productType, description, tags), inventory totals, the first 10 images and 10 media items, and the first 20 variants with their prices, SKUs, inventory quantities, and inventoryItem GIDs. Returned as JSON for downstream tooling. The variant inventoryItem GIDs are needed by set_inventory_quantity. For more than 20 variants, follow up with list_variants.",
      getProductSchema,
      async (args) => {
        const data = await client.graphql<{ product: ProductDetail | null }>(
          GET_PRODUCT_QUERY,
          { id: toGid(args.id, "Product") },
        );
        if (!data.product) {
          return {
            content: [{ type: "text" as const, text: `Product not found: ${args.id}` }],
          };
        }
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify(data.product, null, 2),
            },
          ],
        };
      },
    );
  • Input schema for get_product. Requires a single 'id' string parameter - can be a Product GID (e.g. 'gid://shopify/Product/123') or a numeric ID.
    const getProductSchema = {
      id: z
        .string()
        .describe("Product GID (gid://shopify/Product/123...) or numeric ID"),
    };
  • The registerProductTools() function calls server.tool('get_product', ...) to register the tool on the MCP server. This is invoked from src/server.ts line 57.
    export function registerProductTools(
      server: McpServer,
      client: ShopifyClient,
    ): void {
      server.tool(
        "list_products",
        "List products in the store with cursor-based pagination. Returns each product's title, status (ACTIVE/DRAFT/ARCHIVED), GID, and total inventory across all variants/locations. Supports Shopify's product query syntax for filtering by status, vendor, type, tag, title (wildcard), and date ranges. The last line of output shows the next cursor when more pages exist — pass it as `after` on the next call. Use this to find product GIDs before calling get_product, update_product, list_variants, or any product-scoped tool.",
        listProductsSchema,
        async (args) => {
          const data = await client.graphql<{ products: Connection<Product> }>(
            LIST_PRODUCTS_QUERY,
            { first: args.first, query: args.query, after: args.after },
          );
          const lines = [
            `Found ${data.products.edges.length} product(s):`,
            ...data.products.edges.map(
              ({ node }) =>
                `  ${node.title} (${node.status}) — ${node.id}` +
                (node.totalInventory != null
                  ? ` [inventory: ${node.totalInventory}]`
                  : ""),
            ),
            data.products.pageInfo.hasNextPage
              ? `next cursor: ${data.products.edges[data.products.edges.length - 1]?.cursor}`
              : "(end of results)",
          ];
          return { content: [{ type: "text" as const, text: lines.join("\n") }] };
        },
      );
  • The GET_PRODUCT_QUERY GraphQL query that fetches a single product by ID with all fields including variants (up to 20), images (up to 10), and media (up to 10).
    const GET_PRODUCT_QUERY = /* GraphQL */ `
      query GetProduct($id: ID!) {
        product(id: $id) {
          id
          title
          handle
          status
          vendor
          productType
          description
          tags
          totalInventory
          createdAt
          updatedAt
          featuredImage { url altText }
          images(first: 10) { edges { node { url altText } } }
          variants(first: 20) {
            edges {
              node {
                id
                title
                price
                sku
                inventoryQuantity
                inventoryItem { id }
              }
            }
          }
          media(first: 10) {
            edges { node { id mediaContentType } }
          }
        }
      }
  • The toGid() helper function that converts a numeric ID to a Shopify GID if not already in GID format, e.g. '123' -> 'gid://shopify/Product/123'.
    export function toGid(id: string, type: string): string {
      if (id.startsWith("gid://")) return id;
      return `gid://shopify/${type}/${id}`;
    }
Behavior4/5

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

No annotations provided, so description carries full burden. It transparently details return structure, field limits (first 10 images, 20 variants), and the purpose of specific fields, without misleading or hiding behavior.

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

Conciseness4/5

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

Description is front-loaded with purpose, then lists returned fields concisely without redundancy. Could slightly condense but overall efficient.

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

Completeness5/5

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

Given no output schema, description fully explains the return structure (header fields, images, media, variants) and references sibling tool set_inventory_quantity, providing complete context for agent decision.

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

Parameters4/5

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

Schema has 100% coverage with a single 'id' parameter described. Description adds value by clarifying it accepts GID or numeric ID format, beyond the schema's description.

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?

Description clearly states 'Fetch a single product's full record by GID or numeric ID' and lists returned fields, differentiating it from sibling tools like list_products and list_variants.

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

Usage Guidelines4/5

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

Provides usage context by noting the need for variant inventoryItem GIDs by set_inventory_quantity and suggests following up with list_variants for more than 20 variants, but does not explicitly exclude alternatives.

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