Skip to main content
Glama

cancel_order

Cancel a Shopify order while optionally issuing a full refund, restocking inventory, and notifying the customer. Choose from predefined cancellation reasons. Requires the order not be already cancelled or pending fulfillment.

Instructions

Cancel a Shopify order. Triggers an async job (the response includes a jobId; cancellation finishes shortly after the call returns). Combine with refund: true to issue a full refund of any captured payment, or refund: false if the order is unpaid or you'll handle refunds separately via refund_order. restock: true restores cancelled line items back to inventory; set false if items were physically lost/damaged. notifyCustomer: true sends the cancellation email. Cannot cancel an already-cancelled order or one with active fulfillments still in flight (cancel those fulfillments first via cancel_fulfillment).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesOrder GID or numeric ID to cancel. The order must not already be cancelled.
reasonYesWhy the order is being cancelled. CUSTOMER (customer requested), FRAUD (suspected fraud), INVENTORY (out of stock), DECLINED (payment declined), STAFF (staff decision), OTHER.
refundNoWhether to refund the customer's payment as part of cancellation. true = refund any captured payment in full; false = cancel without refunding (use for unpaid orders, or when you'll handle the refund separately).
restockNoWhether to restock cancelled line items back to inventory. true = decrement inventory back; false = leave inventory as-is (use when items were physically lost/damaged).
staffNoteNoInternal note about the cancellation reason. Visible to staff only.
notifyCustomerNoSend the customer a cancellation email. Default false.

Implementation Reference

  • The async handler function for cancel_order. Calls the ORDER_CANCEL_MUTATION GraphQL with orderId (converted via toGid), reason, refund, restock, staffNote, notifyCustomer. Throws on user errors; returns a text response with the job ID or cancellation confirmation.
    async (args) => {
      const data = await client.graphql<{
        orderCancel: {
          job: { id: string; done: boolean } | null;
          orderCancelUserErrors: ShopifyUserError[];
        };
      }>(ORDER_CANCEL_MUTATION, {
        orderId: toGid(args.id, "Order"),
        reason: args.reason,
        refund: args.refund,
        restock: args.restock,
        staffNote: args.staffNote,
        notifyCustomer: args.notifyCustomer,
      });
      throwIfUserErrors(data.orderCancel.orderCancelUserErrors, "orderCancel");
      const job = data.orderCancel.job;
      return {
        content: [
          {
            type: "text" as const,
            text: job
              ? `Queued cancellation of ${args.id} (reason: ${args.reason}). Job: ${job.id} (done=${job.done})`
              : `Cancelled ${args.id} (reason: ${args.reason}).`,
          },
        ],
      };
    },
  • Input schema for cancel_order: id (string), reason (enum: CUSTOMER, FRAUD, INVENTORY, DECLINED, OTHER, STAFF), refund (boolean, default true), restock (boolean, default true), staffNote (optional string), notifyCustomer (optional boolean).
    const cancelOrderSchema = {
      id: z
        .string()
        .describe("Order GID or numeric ID to cancel. The order must not already be cancelled."),
      reason: z
        .enum(["CUSTOMER", "FRAUD", "INVENTORY", "DECLINED", "OTHER", "STAFF"])
        .describe(
          "Why the order is being cancelled. CUSTOMER (customer requested), FRAUD (suspected fraud), INVENTORY (out of stock), DECLINED (payment declined), STAFF (staff decision), OTHER.",
        ),
      refund: z
        .boolean()
        .default(true)
        .describe(
          "Whether to refund the customer's payment as part of cancellation. true = refund any captured payment in full; false = cancel without refunding (use for unpaid orders, or when you'll handle the refund separately).",
        ),
      restock: z
        .boolean()
        .default(true)
        .describe(
          "Whether to restock cancelled line items back to inventory. true = decrement inventory back; false = leave inventory as-is (use when items were physically lost/damaged).",
        ),
      staffNote: z
        .string()
        .optional()
        .describe("Internal note about the cancellation reason. Visible to staff only."),
      notifyCustomer: z
        .boolean()
        .optional()
        .describe("Send the customer a cancellation email. Default false."),
    };
  • Registration of cancel_order on the McpServer via server.tool() with its description and schema.
    server.tool(
      "cancel_order",
      "Cancel a Shopify order. Triggers an async job (the response includes a jobId; cancellation finishes shortly after the call returns). Combine with `refund: true` to issue a full refund of any captured payment, or `refund: false` if the order is unpaid or you'll handle refunds separately via refund_order. `restock: true` restores cancelled line items back to inventory; set false if items were physically lost/damaged. `notifyCustomer: true` sends the cancellation email. Cannot cancel an already-cancelled order or one with active fulfillments still in flight (cancel those fulfillments first via cancel_fulfillment).",
      cancelOrderSchema,
      async (args) => {
        const data = await client.graphql<{
          orderCancel: {
            job: { id: string; done: boolean } | null;
            orderCancelUserErrors: ShopifyUserError[];
          };
        }>(ORDER_CANCEL_MUTATION, {
          orderId: toGid(args.id, "Order"),
          reason: args.reason,
          refund: args.refund,
          restock: args.restock,
          staffNote: args.staffNote,
          notifyCustomer: args.notifyCustomer,
        });
        throwIfUserErrors(data.orderCancel.orderCancelUserErrors, "orderCancel");
        const job = data.orderCancel.job;
        return {
          content: [
            {
              type: "text" as const,
              text: job
                ? `Queued cancellation of ${args.id} (reason: ${args.reason}). Job: ${job.id} (done=${job.done})`
                : `Cancelled ${args.id} (reason: ${args.reason}).`,
            },
          ],
        };
      },
    );
  • GraphQL mutation ORDER_CANCEL_MUTATION used by the cancel_order handler to call Shopify's orderCancel mutation.
    const ORDER_CANCEL_MUTATION = /* GraphQL */ `
      mutation OrderCancel(
        $orderId: ID!
        $reason: OrderCancelReason!
        $refund: Boolean!
        $restock: Boolean!
        $staffNote: String
        $notifyCustomer: Boolean
      ) {
        orderCancel(
          orderId: $orderId
          reason: $reason
          refund: $refund
          restock: $restock
          staffNote: $staffNote
          notifyCustomer: $notifyCustomer
        ) {
          job { id done }
          orderCancelUserErrors { field message code }
        }
      }
    `;
  • Helper function toGid that converts a numeric ID to a Shopify GID (e.g., gid://shopify/Order/123). Used by the cancel_order handler when passing the order ID.
    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?

Despite no annotations, the description details the async job behavior, jobId in response, and parameter effects (refund, restock, notify). Could mention irreversibility but covers key behavioral traits.

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?

Concise yet comprehensive; front-loaded with main action and async note. Every sentence adds value, though some might be slightly dense.

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?

Covers all parameters, use cases, warnings, and response info (jobId). No output schema, but description compensates adequately for a mutation tool.

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?

With 100% schema coverage, baseline is 3. The description adds value by explaining parameter usage beyond schema, e.g., refund ties to refund_order, restock conditions, and default values.

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 clearly states 'Cancel a Shopify order' and differentiates from sibling tools like cancel_fulfillment and refund_order by explaining when each is appropriate.

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?

Explicitly states when to use refund, restock, notifyCustomer, and warns against canceling already-cancelled orders or those with active fulfillments, directing to cancel_fulfillment first.

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