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
| 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. 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), }, ], }; }, ); - src/tools/products.ts:123-127 (schema)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"), }; - src/tools/products.ts:158-186 (registration)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") }] }; }, ); - src/tools/products.ts:35-67 (helper)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 } } } } } - src/tools/products.ts:333-336 (helper)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}`; }