Skip to main content
Glama

set_inventory_quantity

Set absolute available inventory quantity for a variant at a location. Overwrites current count; use for cycle counts or stock receipt. Requires inventory item ID, location ID, and desired quantity.

Instructions

Set the absolute available inventory for one variant at one location. This is a direct overwrite, not an adjustment — passing 5 sets the count to 5 regardless of what was there before. The pair (inventory_item_id, location_id) uniquely identifies the inventory level: get inventory_item_id from get_product (it's on each variant) and location_id from list_locations. Records a Shopify inventory adjustment with the reason code you provide. Use 'correction' for cycle counts/manual fixes, 'received' when receiving stock, 'cycle_count_available' for systematic counts. Tracks history; the audit log shows who/when via the API user.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inventory_item_idYesInventoryItem GID ('gid://shopify/InventoryItem/123') or numeric ID. Found on each variant in get_product output as variants[].inventoryItem.id.
location_idYesLocation GID or numeric ID. Get from list_locations. Each variant tracks inventory per location.
quantityYesNew absolute available quantity. This OVERWRITES the current count, it doesn't increment — pass the desired final number, not a delta.
reasonNoShopify-defined reason code recorded in the inventory audit history. Common values: 'correction' (manual fix), 'cycle_count_available' (systematic recount), 'received' (receiving new stock), 'damaged', 'shrinkage', 'other'.correction

Implementation Reference

  • Handler function that executes the set_inventory_quantity tool: calls Shopify's inventorySetQuantities GraphQL mutation with inventoryItemId, locationId, quantity, reason, and returns a success message.
      async (args) => {
        const data = await client.graphql<{
          inventorySetQuantities: {
            inventoryAdjustmentGroup: { id: string } | null;
            userErrors: ShopifyUserError[];
          };
        }>(SET_INVENTORY_MUTATION, {
          input: {
            reason: args.reason,
            name: "available",
            ignoreCompareQuantity: true,
            quantities: [
              {
                inventoryItemId: toGid(args.inventory_item_id, "InventoryItem"),
                locationId: toGid(args.location_id, "Location"),
                quantity: args.quantity,
              },
            ],
          },
        });
        throwIfUserErrors(
          data.inventorySetQuantities.userErrors,
          "inventorySetQuantities",
        );
        const groupId = data.inventorySetQuantities.inventoryAdjustmentGroup?.id;
        return {
          content: [
            {
              type: "text" as const,
              text: `Set inventory to ${args.quantity} (item: ${args.inventory_item_id}, location: ${args.location_id}, adjustment: ${groupId ?? "(no adjustment required)"})`,
            },
          ],
        };
      },
    );
  • Zod schema defining input parameters: inventory_item_id (string), location_id (string), quantity (int >= 0), and reason (string, defaults to 'correction').
    const setInventorySchema = {
      inventory_item_id: z
        .string()
        .describe(
          "InventoryItem GID ('gid://shopify/InventoryItem/123') or numeric ID. Found on each variant in get_product output as variants[].inventoryItem.id.",
        ),
      location_id: z
        .string()
        .describe(
          "Location GID or numeric ID. Get from list_locations. Each variant tracks inventory per location.",
        ),
      quantity: z
        .number()
        .int()
        .min(0)
        .describe(
          "New absolute available quantity. This OVERWRITES the current count, it doesn't increment — pass the desired final number, not a delta.",
        ),
      reason: z
        .string()
        .default("correction")
        .describe(
          "Shopify-defined reason code recorded in the inventory audit history. Common values: 'correction' (manual fix), 'cycle_count_available' (systematic recount), 'received' (receiving new stock), 'damaged', 'shrinkage', 'other'.",
        ),
    };
  • Registration of the set_inventory_quantity tool with the MCP server via server.tool(), including its name, description, schema, and handler.
    server.tool(
      "set_inventory_quantity",
      "Set the absolute available inventory for one variant at one location. This is a direct overwrite, not an adjustment — passing 5 sets the count to 5 regardless of what was there before. The pair (inventory_item_id, location_id) uniquely identifies the inventory level: get inventory_item_id from get_product (it's on each variant) and location_id from list_locations. Records a Shopify inventory adjustment with the reason code you provide. Use 'correction' for cycle counts/manual fixes, 'received' when receiving stock, 'cycle_count_available' for systematic counts. Tracks history; the audit log shows who/when via the API user.",
      setInventorySchema,
      async (args) => {
        const data = await client.graphql<{
          inventorySetQuantities: {
            inventoryAdjustmentGroup: { id: string } | null;
            userErrors: ShopifyUserError[];
          };
        }>(SET_INVENTORY_MUTATION, {
          input: {
            reason: args.reason,
            name: "available",
            ignoreCompareQuantity: true,
            quantities: [
              {
                inventoryItemId: toGid(args.inventory_item_id, "InventoryItem"),
                locationId: toGid(args.location_id, "Location"),
                quantity: args.quantity,
              },
            ],
          },
        });
        throwIfUserErrors(
          data.inventorySetQuantities.userErrors,
          "inventorySetQuantities",
        );
        const groupId = data.inventorySetQuantities.inventoryAdjustmentGroup?.id;
        return {
          content: [
            {
              type: "text" as const,
              text: `Set inventory to ${args.quantity} (item: ${args.inventory_item_id}, location: ${args.location_id}, adjustment: ${groupId ?? "(no adjustment required)"})`,
            },
          ],
        };
      },
    );
  • Exported function registerInventoryTools that registers both set_inventory_quantity and list_locations tools with the MCP server.
    export function registerInventoryTools(
      server: McpServer,
      client: ShopifyClient,
    ): void {
      server.tool(
        "set_inventory_quantity",
        "Set the absolute available inventory for one variant at one location. This is a direct overwrite, not an adjustment — passing 5 sets the count to 5 regardless of what was there before. The pair (inventory_item_id, location_id) uniquely identifies the inventory level: get inventory_item_id from get_product (it's on each variant) and location_id from list_locations. Records a Shopify inventory adjustment with the reason code you provide. Use 'correction' for cycle counts/manual fixes, 'received' when receiving stock, 'cycle_count_available' for systematic counts. Tracks history; the audit log shows who/when via the API user.",
        setInventorySchema,
        async (args) => {
          const data = await client.graphql<{
            inventorySetQuantities: {
              inventoryAdjustmentGroup: { id: string } | null;
              userErrors: ShopifyUserError[];
            };
          }>(SET_INVENTORY_MUTATION, {
            input: {
              reason: args.reason,
              name: "available",
              ignoreCompareQuantity: true,
              quantities: [
                {
                  inventoryItemId: toGid(args.inventory_item_id, "InventoryItem"),
                  locationId: toGid(args.location_id, "Location"),
                  quantity: args.quantity,
                },
              ],
            },
          });
          throwIfUserErrors(
            data.inventorySetQuantities.userErrors,
            "inventorySetQuantities",
          );
          const groupId = data.inventorySetQuantities.inventoryAdjustmentGroup?.id;
          return {
            content: [
              {
                type: "text" as const,
                text: `Set inventory to ${args.quantity} (item: ${args.inventory_item_id}, location: ${args.location_id}, adjustment: ${groupId ?? "(no adjustment required)"})`,
              },
            ],
          };
        },
      );
    
      server.tool(
        "list_locations",
        "List the store's locations — physical or virtual places where inventory is stocked or fulfilled from (warehouses, retail stores, drop-ship partners). Returns each location's name, active/inactive flag, city + country, and GID. The location GID is required by set_inventory_quantity and create_fulfillment. Inactive locations still exist but cannot accept new inventory or fulfillments.",
        listLocationsSchema,
        async (args) => {
          const data = await client.graphql<{
            locations: {
              edges: Array<{
                node: {
                  id: string;
                  name: string;
                  isActive: boolean;
                  address?: { city?: string | null; countryCode?: string | null };
                };
              }>;
            };
          }>(LIST_LOCATIONS_QUERY, { first: args.first });
          const lines = [
            `Found ${data.locations.edges.length} location(s):`,
            ...data.locations.edges.map(({ node }) => {
              const city = node.address?.city ?? "?";
              const country = node.address?.countryCode ?? "?";
              const active = node.isActive ? "active" : "inactive";
              return `  ${node.name} (${active}) — ${city}, ${country} — ${node.id}`;
            }),
          ];
          return { content: [{ type: "text" as const, text: lines.join("\n") }] };
        },
      );
    }
  • GraphQL mutation string used by the handler to call Shopify's InventorySetQuantities API.
    const SET_INVENTORY_MUTATION = /* GraphQL */ `
      mutation InventorySetQuantities($input: InventorySetQuantitiesInput!) {
        inventorySetQuantities(input: $input) {
          inventoryAdjustmentGroup { id }
          userErrors { field message }
        }
      }
    `;
Behavior4/5

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

No annotations are provided, so the description carries the full burden. It clearly states the overwrite behavior ('passing 5 sets the count to 5 regardless of what was there before'), that it records an inventory adjustment with a reason code, and that it tracks history with audit logs. This is comprehensive behavioral disclosure.

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?

The description is a single paragraph of 4 sentences, each serving a distinct purpose: purpose and overwrite nature, specific example, ID sourcing, and reason code guidance. It is front-loaded with the most critical information and contains no superfluous content.

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 no output schema, the description covers the key aspects: what the tool does, how it behaves (overwrite), how to provide inputs (ID sourcing), and how to choose reason codes. It does not detail error handling or success response, but the absence of an output schema reduces the expectation. The description is thorough for its complexity.

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?

All 4 parameters are documented in the input schema (100% coverage). The description adds value beyond the schema by clarifying the nature of 'quantity' (absolute overwrite) and providing common reason code examples. This extra context justifies a score above the baseline of 3.

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 starts with a clear action: 'Set the absolute available inventory for one variant at one location.' It specifies the scope (one variant, one location) and uses 'overwrite' to distinguish from adjustment tools. The sibling tools include many update/delete actions, so this avoids confusion.

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?

The description explicitly states this is a direct overwrite, not an adjustment. It advises which reason codes to use ('correction' for cycle counts, 'received' for receiving, etc.) and guides on obtaining IDs from other tools. It lacks explicit 'when not to use,' but the context is sufficient.

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