Skip to main content
Glama

update_draft_order

Modify an open draft order's customer, email, note, tags, or line items. Line items replace existing ones entirely, so retrieve current items before updating.

Instructions

Modify an existing OPEN draft order's customer, email, note, tags, or line items. Important: if lineItems is provided, it REPLACES the existing items entirely (not a merge or append) — read the current items first if you need to preserve any. Cannot update completed drafts; those are real orders. To pause and pick up a draft later, leave it OPEN and re-invoke update later; nothing here triggers payment.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesGID of the draft order to update. Cannot update completed drafts (those are real orders — use the order tools).
lineItemsNoIf provided, REPLACES the entire current line-items array — this is a replace, not a merge. To add or remove specific items you must read the current items first and resubmit the full set.
customerIdNoNew customer GID to attach. Pass to swap or set the customer.
emailNoNew email for the order.
noteNoNew internal note. Replaces any prior note.
tagsNoNew tag set. Replaces existing tags entirely.

Implementation Reference

  • Registration of the 'update_draft_order' tool on the MCP server via server.tool() call. Passes schema and handler to McpServer.
    server.tool(
      "update_draft_order",
      "Modify an existing OPEN draft order's customer, email, note, tags, or line items. Important: if `lineItems` is provided, it REPLACES the existing items entirely (not a merge or append) — read the current items first if you need to preserve any. Cannot update completed drafts; those are real orders. To pause and pick up a draft later, leave it OPEN and re-invoke update later; nothing here triggers payment.",
      updateDraftOrderSchema,
      async (args) => {
        const input: Record<string, unknown> = {};
        const mapped = mapLineItemsForInput(args.lineItems);
        if (mapped) input.lineItems = mapped;
        if (args.customerId) input.customerId = args.customerId;
        if (args.email) input.email = args.email;
        if (args.note) input.note = args.note;
        if (args.tags) input.tags = args.tags;
    
        const data = await client.graphql<{
          draftOrderUpdate: {
            draftOrder: DraftOrder | null;
            userErrors: ShopifyUserError[];
          };
        }>(UPDATE_DRAFT_ORDER_MUTATION, { id: args.id, input });
        throwIfUserErrors(data.draftOrderUpdate.userErrors, "draftOrderUpdate");
        const d = data.draftOrderUpdate.draftOrder;
        if (!d) {
          return {
            content: [
              { type: "text" as const, text: "draftOrderUpdate returned no draft order." },
            ],
          };
        }
        const total = `${d.totalPriceSet.shopMoney.amount} ${d.totalPriceSet.shopMoney.currencyCode}`;
        return {
          content: [
            {
              type: "text" as const,
              text: `Updated draft order ${d.name} [${d.status}] — Total: ${total}`,
            },
          ],
        };
      },
    );
    
    server.tool(
      "complete_draft_order",
      "Convert an OPEN draft order into a real Shopify order. With paymentPending=false (default), Shopify attempts to capture payment immediately; the call fails if no payment method is on file. With paymentPending=true, the order is created in payment-pending status — useful when collecting payment offline (cash, bank transfer, manual processing). Once completed, the draft transitions to COMPLETED and the new order's GID is returned. The transition is one-way: completed drafts cannot be re-opened or edited via draft tools (use the order tools, or refund/cancel for the resulting order).",
      completeDraftOrderSchema,
      async (args) => {
        const data = await client.graphql<{
          draftOrderComplete: {
            draftOrder: DraftOrder | null;
            userErrors: ShopifyUserError[];
          };
        }>(COMPLETE_DRAFT_ORDER_MUTATION, {
          id: args.id,
          paymentPending: args.paymentPending ?? false,
        });
        throwIfUserErrors(data.draftOrderComplete.userErrors, "draftOrderComplete");
        const d = data.draftOrderComplete.draftOrder;
        if (!d) {
          return {
            content: [
              { type: "text" as const, text: "draftOrderComplete returned no draft order." },
            ],
          };
        }
        const orderInfo = d.order
          ? ` → order ${d.order.name} (${d.order.id})`
          : "";
        return {
          content: [
            {
              type: "text" as const,
              text: `Completed draft order ${d.name} [${d.status}]${orderInfo}`,
            },
          ],
        };
      },
    );
    
    server.tool(
      "delete_draft_order",
      "Permanently delete a draft order. Only OPEN/INVOICE_SENT drafts can be deleted — completed drafts are real orders and orders cannot be deleted (cancel them instead). Irreversible. Returns the deleted GID, or a no-op message if the GID didn't match anything.",
      deleteDraftOrderSchema,
      async (args) => {
        const data = await client.graphql<{
          draftOrderDelete: {
            deletedId: string | null;
            userErrors: ShopifyUserError[];
          };
        }>(DELETE_DRAFT_ORDER_MUTATION, { input: { id: args.id } });
        throwIfUserErrors(data.draftOrderDelete.userErrors, "draftOrderDelete");
        return {
          content: [
            {
              type: "text" as const,
              text: data.draftOrderDelete.deletedId
                ? `Deleted draft order ${data.draftOrderDelete.deletedId}.`
                : "No draft order matched; nothing deleted.",
            },
          ],
        };
      },
    );
  • The async handler function for update_draft_order. Builds the GraphQL input from args, calls the Shopify DraftOrderUpdate mutation, handles user errors, and returns a text response with the updated draft's details.
      async (args) => {
        const input: Record<string, unknown> = {};
        const mapped = mapLineItemsForInput(args.lineItems);
        if (mapped) input.lineItems = mapped;
        if (args.customerId) input.customerId = args.customerId;
        if (args.email) input.email = args.email;
        if (args.note) input.note = args.note;
        if (args.tags) input.tags = args.tags;
    
        const data = await client.graphql<{
          draftOrderUpdate: {
            draftOrder: DraftOrder | null;
            userErrors: ShopifyUserError[];
          };
        }>(UPDATE_DRAFT_ORDER_MUTATION, { id: args.id, input });
        throwIfUserErrors(data.draftOrderUpdate.userErrors, "draftOrderUpdate");
        const d = data.draftOrderUpdate.draftOrder;
        if (!d) {
          return {
            content: [
              { type: "text" as const, text: "draftOrderUpdate returned no draft order." },
            ],
          };
        }
        const total = `${d.totalPriceSet.shopMoney.amount} ${d.totalPriceSet.shopMoney.currencyCode}`;
        return {
          content: [
            {
              type: "text" as const,
              text: `Updated draft order ${d.name} [${d.status}] — Total: ${total}`,
            },
          ],
        };
      },
    );
  • Zod-based schema for update_draft_order input arguments. Fields: id (required), lineItems (optional array, replaces all items), customerId, email, note, tags (all optional).
    const updateDraftOrderSchema = {
      id: z
        .string()
        .describe(
          "GID of the draft order to update. Cannot update completed drafts (those are real orders — use the order tools).",
        ),
      lineItems: z
        .array(lineItemSchema)
        .optional()
        .describe(
          "If provided, REPLACES the entire current line-items array — this is a replace, not a merge. To add or remove specific items you must read the current items first and resubmit the full set.",
        ),
      customerId: z
        .string()
        .optional()
        .describe("New customer GID to attach. Pass to swap or set the customer."),
      email: z.string().email().optional().describe("New email for the order."),
      note: z.string().optional().describe("New internal note. Replaces any prior note."),
      tags: z
        .array(z.string())
        .optional()
        .describe("New tag set. Replaces existing tags entirely."),
    };
  • The GraphQL mutation string used by update_draft_order. Performs DraftOrderUpdate with id and input variables.
    const UPDATE_DRAFT_ORDER_MUTATION = /* GraphQL */ `
      mutation DraftOrderUpdate($id: ID!, $input: DraftOrderInput!) {
        draftOrderUpdate(id: $id, input: $input) {
          draftOrder {
            id
            name
            status
            totalPriceSet { shopMoney { amount currencyCode } }
          }
          userErrors { field message }
        }
      }
  • src/server.ts:18-18 (registration)
    Import of registerDraftOrderTools from the draft_orders module, called at line 62 to register all draft order tools including update_draft_order.
    import { registerDraftOrderTools } from "./tools/draft_orders.js";
Behavior4/5

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

Discloses the critical behavioral nuance that lineItems replaces entirely, and states no payment triggering. Lacks permissions/rate limits, but with no annotations, the description carries the burden well.

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?

Four sentences with zero fluff. Front-loaded with the main action, then critical behavioral note, then exclusions, then usage tip. Every sentence adds essential information.

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 key aspects: purpose, constraints (OPEN only), behavioral warning (lineItems replace), exclusion of completed drafts, and guidance on pausing. No output schema needed for this context.

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?

Input schema has 100% description coverage, so baseline is 3. The description adds extra guidance for lineItems (e.g., read current items first) and reiterates constraints, providing value beyond the schema.

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 it modifies existing OPEN draft orders, specifying fields (customer, email, note, tags, line items) and contrasting with completed drafts. This distinctively differentiates from sibling tools like create_draft_order and complete_draft_order.

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 says when to use (OPEN drafts) and when not to (completed drafts), provides alternatives (use order tools for real orders), and gives guidance on pausing drafts without triggering payment.

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