Skip to main content
Glama

cancel_order

Cancel a Shopify order, optionally refund payment, restock inventory, and notify customer. Provide reason and staff notes.

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 handler function that executes the cancel_order tool logic. Calls the ORDER_CANCEL_MUTATION GraphQL mutation with the args (id, reason, refund, restock, staffNote, notifyCustomer), throws on user errors, and returns a success message with the async job info.
      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. Defines parameters: id (Order GID or numeric ID), reason (enum: CUSTOMER, FRAUD, INVENTORY, DECLINED, OTHER, STAFF), refund (boolean, default true), restock (boolean, default true), staffNote (optional string), and 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 the 'cancel_order' tool via server.tool() inside the registerOrderTools function. Registers the tool name, description, schema (cancelOrderSchema), and the async handler.
    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}).`,
            },
          ],
        };
      },
    );
  • ORDER_CANCEL_MUTATION — the GraphQL mutation for cancelling an order with parameters: orderId, reason (OrderCancelReason), refund, restock, staffNote, and notifyCustomer.
    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 }
        }
      }
    `;
  • src/server.ts:58-58 (registration)
    Top-level registration call: registerOrderTools(s, shopify) wires up the cancel_order tool into the MCP server.
    registerOrderTools(s, shopify);
Behavior5/5

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

Even with no annotations, description fully discloses behavioral traits: async job with jobId response, side effects of refund/restock/notify, and preconditions. It does not contradict any structured fields.

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 a single paragraph but well-structured, front-loading the main purpose then detailing options. Could be slightly more structured (e.g., bullet points) but remains concise and clear.

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 6 parameters, async nature, and no output schema, description covers all necessary context: preconditions, side effects, relationships with sibling tools, and response shape (jobId). Complete for an agent to use correctly.

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 coverage is 100%, so baseline is 3. Description adds value by explaining usage context for each boolean flag (e.g., when to set refund false, restock false) and linking to refund_order. Adds moderate additional meaning.

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 'Cancel a Shopify order.' and specifies verb+resource. It distinguishes from siblings like cancel_fulfillment and refund_order by mentioning them directly.

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?

Provides explicit when-to-use and when-not-to-use guidance, including cannot cancel already-cancelled orders or orders with active fulfillments, and directs to cancel_fulfillment first. Also explains conditions for refund, restock, and notifyCustomer flags.

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