get_draft_order
Retrieve a single draft order with full details including status, customer, line items, invoice URL, and resulting order if completed. Use to inspect a draft before updating or completing it.
Instructions
Fetch a single draft order with full details: status, customer, line items (with quantity, title, and unit price), invoice URL, and the resulting real order if it's already been completed. Use to inspect a draft before calling update_draft_order or complete_draft_order. Returns a friendly text summary.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Draft order GID, e.g. 'gid://shopify/DraftOrder/12345'. Get one from list_draft_orders. |
Implementation Reference
- src/server.ts:62-62 (registration)Registration of draft order tools (including 'get_draft_order') on the MCP server in buildContext().
registerDraftOrderTools(s, shopify); - src/server.ts:18-18 (registration)Import of the registerDraftOrderTools function from src/tools/draft_orders.ts.
import { registerDraftOrderTools } from "./tools/draft_orders.js"; - src/tools/draft_orders.ts:323-371 (handler)Handler function for 'get_draft_order' tool — executes the GraphQL query, formats and returns a friendly text summary of the draft order.
server.tool( "get_draft_order", "Fetch a single draft order with full details: status, customer, line items (with quantity, title, and unit price), invoice URL, and the resulting real order if it's already been completed. Use to inspect a draft before calling update_draft_order or complete_draft_order. Returns a friendly text summary.", getDraftOrderSchema, async (args) => { const data = await client.graphql<{ draftOrder: DraftOrder | null }>( GET_DRAFT_ORDER_QUERY, { id: args.id }, ); if (!data.draftOrder) { return { content: [ { type: "text" as const, text: `Draft order not found: ${args.id}` }, ], }; } const d = data.draftOrder; const total = `${d.totalPriceSet.shopMoney.amount} ${d.totalPriceSet.shopMoney.currencyCode}`; const customer = d.customer ? `${d.customer.displayName ?? ""} <${d.customer.email ?? ""}>` : "(no customer)"; const lineItemLines = d.lineItems?.edges.map(({ node }) => { const price = node.originalUnitPriceSet ? `@ ${node.originalUnitPriceSet.shopMoney.amount} ${node.originalUnitPriceSet.shopMoney.currencyCode}` : ""; return ` - ${node.quantity}× ${node.title} ${price}`.trim(); }) ?? []; return { content: [ { type: "text" as const, text: [ `${d.name} [${d.status}]`, ` ID: ${d.id}`, ` Total: ${total}`, ` Customer: ${customer}`, d.invoiceUrl ? ` Invoice: ${d.invoiceUrl}` : "", d.order ? ` Completed as order: ${d.order.name} (${d.order.id})` : "", " Line items:", ...lineItemLines, ] .filter(Boolean) .join("\n"), }, ], }; }, ); - src/tools/draft_orders.ts:181-187 (schema)Input schema for 'get_draft_order' — accepts a single 'id' string (draft order GID).
const getDraftOrderSchema = { id: z .string() .describe( "Draft order GID, e.g. 'gid://shopify/DraftOrder/12345'. Get one from list_draft_orders.", ), }; - src/tools/draft_orders.ts:55-81 (helper)GraphQL query GET_DRAFT_ORDER_QUERY used by the handler to fetch draft order details.
const GET_DRAFT_ORDER_QUERY = /* GraphQL */ ` query GetDraftOrder($id: ID!) { draftOrder(id: $id) { id name status invoiceUrl totalPriceSet { shopMoney { amount currencyCode } } subtotalPriceSet { shopMoney { amount currencyCode } } customer { id displayName email } lineItems(first: 50) { edges { node { title quantity originalUnitPriceSet { shopMoney { amount currencyCode } } variant { id sku } } } } createdAt updatedAt completedAt order { id name } } } `;