get_product
Fetch a product's complete data by GID or numeric ID, returning header fields, inventory totals, images, media, and variants with prices, SKUs, and inventory GIDs for downstream inventory management.
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
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Product GID (gid://shopify/Product/123...) or numeric ID |
Implementation Reference
- src/tools/products.ts:188-211 (handler)The get_product tool handler: fetches a product by GID or numeric ID via GraphQL, returns JSON with full product details including variants, images, and media.
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), }, ], }; }, ); - src/tools/products.ts:123-127 (schema)Input schema for get_product: accepts a single 'id' string parameter (Product GID or numeric ID).
const getProductSchema = { id: z .string() .describe("Product GID (gid://shopify/Product/123...) or numeric ID"), }; - src/tools/products.ts:158-161 (registration)Registration function registerProductTools is called from src/server.ts line 57 with the MCP server and Shopify client, registering all product tools including get_product.
export function registerProductTools( server: McpServer, client: ShopifyClient, ): void { - src/tools/products.ts:35-68 (helper)GraphQL query used by get_product to fetch full product details including variants, images, and media.
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 } } } } } `; - src/tools/products.ts:333-336 (helper)Helper function toGid converts numeric IDs to Shopify GID format (e.g., 'gid://shopify/Product/123'), used by the get_product handler.
export function toGid(id: string, type: string): string { if (id.startsWith("gid://")) return id; return `gid://shopify/${type}/${id}`; }