Skip to main content
Glama

refund_order

Refund specific line items, shipping, or both with options for restock behavior and customer notification.

Instructions

Issue a refund against an order — for specific line items (with quantities and optional restock behaviour), for shipping, or both. Returns the new refund's GID and total amount refunded. To refund a full order use cancel_order with refund=true instead (one-step). Use this tool when refunding partially: just one item, just shipping, an adjustment without item breakdown, or a return that needs explicit restock-to-location handling. The restockType per line item controls inventory behaviour: NO_RESTOCK (default — the items aren't coming back), CANCEL (restock as if cancelled), RETURN (restock with a return record at the given locationId). Pass notify: true to email the customer.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesOrder GID or numeric ID to refund.
refundLineItemsNoSpecific line items to refund with quantities. Omit to do a refund without item-level breakdown (use for shipping-only or adjustment refunds).
shippingNoRefund part or all of shipping. Pass {fullRefund: true} to refund everything paid in shipping; or {amount: '5.00'} for a specific amount.
currencyNoISO currency code. Required for multi-currency stores; defaults to the order's currency otherwise.
noteNoInternal note explaining the refund.
notifyNoEmail the customer a refund notification.

Implementation Reference

  • The handler function for the 'refund_order' tool. Builds the RefundInput payload (orderId, notify, refundLineItems, shipping, currency, note), calls the REFUND_CREATE_MUTATION GraphQL mutation, checks for user errors, and returns the refund GID and total refunded amount.
      async (args) => {
        const input: Record<string, unknown> = {
          orderId: toGid(args.id, "Order"),
          notify: args.notify,
        };
        if (args.refundLineItems) {
          input.refundLineItems = args.refundLineItems.map((li) => ({
            lineItemId: li.lineItemId,
            quantity: li.quantity,
            restockType: li.restockType,
            locationId: li.locationId,
          }));
        }
        if (args.shipping) input.shipping = args.shipping;
        if (args.currency) input.currency = args.currency;
        if (args.note) input.note = args.note;
    
        const data = await client.graphql<{
          refundCreate: {
            refund: {
              id: string;
              totalRefundedSet: {
                shopMoney: { amount: string; currencyCode: string };
              };
              note?: string | null;
            } | null;
            userErrors: ShopifyUserError[];
          };
        }>(REFUND_CREATE_MUTATION, { input });
        throwIfUserErrors(data.refundCreate.userErrors, "refundCreate");
        const r = data.refundCreate.refund;
        if (!r) {
          return {
            content: [
              { type: "text" as const, text: "refundCreate returned no refund." },
            ],
          };
        }
        const total = `${r.totalRefundedSet.shopMoney.amount} ${r.totalRefundedSet.shopMoney.currencyCode}`;
        return {
          content: [
            {
              type: "text" as const,
              text: `Refunded ${total} on ${args.id} — refund ${r.id}`,
            },
          ],
        };
      },
    );
  • The input schema for 'refund_order'. Defines fields: id (order GID/numeric), refundLineItems (array of line items with quantities and restockType), shipping (full refund or specific amount), currency, note, and notify flag.
    const refundOrderSchema = {
      id: z
        .string()
        .describe("Order GID or numeric ID to refund."),
      refundLineItems: z
        .array(refundLineItemSchema)
        .optional()
        .describe(
          "Specific line items to refund with quantities. Omit to do a refund without item-level breakdown (use for shipping-only or adjustment refunds).",
        ),
      shipping: z
        .object({
          fullRefund: z.boolean().optional(),
          amount: z.string().optional().describe("Specific shipping refund amount as decimal string."),
        })
        .optional()
        .describe(
          "Refund part or all of shipping. Pass {fullRefund: true} to refund everything paid in shipping; or {amount: '5.00'} for a specific amount.",
        ),
      currency: z
        .string()
        .optional()
        .describe(
          "ISO currency code. Required for multi-currency stores; defaults to the order's currency otherwise.",
        ),
      note: z.string().optional().describe("Internal note explaining the refund."),
      notify: z
        .boolean()
        .default(false)
        .describe("Email the customer a refund notification."),
    };
  • The refundLineItemSchema used within refundOrderSchema. Defines lineItemId, quantity, restockType (NO_RESTOCK, CANCEL, RETURN), and locationId.
    const refundLineItemSchema = z.object({
      lineItemId: z.string().describe("LineItem GID from the order."),
      quantity: z.number().int().min(1).describe("How many of this line item to refund."),
      restockType: z
        .enum(["NO_RESTOCK", "CANCEL", "RETURN"])
        .default("NO_RESTOCK")
        .describe(
          "How to handle inventory: NO_RESTOCK (don't restock), CANCEL (restock as if cancelled), RETURN (restock as a return).",
        ),
      locationId: z
        .string()
        .optional()
        .describe("Location GID to restock to (required when restockType is CANCEL or RETURN)."),
    });
  • The REFUND_CREATE_MUTATION GraphQL mutation string. Calls refundCreate(input:) and returns the refund id, totalRefundedSet, note, and userErrors.
    const REFUND_CREATE_MUTATION = /* GraphQL */ `
      mutation RefundCreate($input: RefundInput!) {
        refundCreate(input: $input) {
          refund {
            id
            totalRefundedSet { shopMoney { amount currencyCode } }
            note
          }
          userErrors { field message }
        }
      }
    `;
  • Registration of the 'refund_order' tool on the MCP server via server.tool(). Registered inside registerOrderTools() which is called from src/server.ts line 58.
    server.tool(
      "refund_order",
      "Issue a refund against an order — for specific line items (with quantities and optional restock behaviour), for shipping, or both. Returns the new refund's GID and total amount refunded. To refund a full order use cancel_order with refund=true instead (one-step). Use this tool when refunding partially: just one item, just shipping, an adjustment without item breakdown, or a return that needs explicit restock-to-location handling. The `restockType` per line item controls inventory behaviour: NO_RESTOCK (default — the items aren't coming back), CANCEL (restock as if cancelled), RETURN (restock with a return record at the given locationId). Pass `notify: true` to email the customer.",
      refundOrderSchema,
      async (args) => {
        const input: Record<string, unknown> = {
          orderId: toGid(args.id, "Order"),
          notify: args.notify,
        };
        if (args.refundLineItems) {
          input.refundLineItems = args.refundLineItems.map((li) => ({
            lineItemId: li.lineItemId,
            quantity: li.quantity,
            restockType: li.restockType,
            locationId: li.locationId,
          }));
        }
        if (args.shipping) input.shipping = args.shipping;
        if (args.currency) input.currency = args.currency;
        if (args.note) input.note = args.note;
    
        const data = await client.graphql<{
          refundCreate: {
            refund: {
              id: string;
              totalRefundedSet: {
                shopMoney: { amount: string; currencyCode: string };
              };
              note?: string | null;
            } | null;
            userErrors: ShopifyUserError[];
          };
        }>(REFUND_CREATE_MUTATION, { input });
        throwIfUserErrors(data.refundCreate.userErrors, "refundCreate");
        const r = data.refundCreate.refund;
        if (!r) {
          return {
            content: [
              { type: "text" as const, text: "refundCreate returned no refund." },
            ],
          };
        }
        const total = `${r.totalRefundedSet.shopMoney.amount} ${r.totalRefundedSet.shopMoney.currencyCode}`;
        return {
          content: [
            {
              type: "text" as const,
              text: `Refunded ${total} on ${args.id} — refund ${r.id}`,
            },
          ],
        };
      },
    );
Behavior4/5

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

Without annotations, the description carries the full burden. It explains return values (refund GID and total amount), restockType behaviors, and the notify option. However, it does not mention idempotency, rate limits, or authorization requirements, which are common behavioral concerns.

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?

The description is moderately sized and front-loaded with the core action. It efficiently covers key details without unnecessary repetition. Minor improvement could be made by structuring it into bullet points for quick scanning.

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 the moderate complexity (6 parameters, nested objects) and lack of output schema, the description is complete: it covers what the tool does, when to use it, parameter behaviors, return values, and customer notification. No obvious gaps.

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 description coverage is 100%, but the description adds value by clarifying when to omit refundLineItems, explaining the restockType enum in practical terms, and describing shipping options. This goes beyond the schema's basic descriptions.

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 tool's purpose is clearly stated: it issues a refund for specific line items, shipping, or both. It distinguishes from the sibling tool cancel_order by explicitly noting that refund_order is for partial refunds, while cancel_order with refund=true handles full refunds.

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?

The description explicitly outlines when to use this tool versus cancel_order, and provides scenarios such as refunding a single item, shipping, or an adjustment. It also explains the restockType controls and the notify parameter.

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