update-order
Modify Shopify order details such as email, shipping address, custom attributes, metafields, notes, and tags using the MCP server for streamlined order management.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| customAttributes | No | ||
| No | |||
| id | Yes | ||
| metafields | No | ||
| note | No | ||
| shippingAddress | No | ||
| tags | No |
Implementation Reference
- src/tools/updateOrder.ts:62-162 (handler)The main handler function that executes the Shopify GraphQL orderUpdate mutation to update the order with provided input.execute: async (input: UpdateOrderInput) => { try { // Prepare input for GraphQL mutation const { id, ...orderFields } = input; const query = gql` mutation orderUpdate($input: OrderInput!) { orderUpdate(input: $input) { order { id name email note tags customAttributes { key value } metafields(first: 10) { edges { node { id namespace key value } } } shippingAddress { address1 address2 city company country firstName lastName phone province zip } } userErrors { field message } } } `; const variables = { input: { id, ...orderFields } }; const data = (await shopifyClient.request(query, variables)) as { orderUpdate: { order: any; userErrors: Array<{ field: string; message: string; }>; }; }; // If there are user errors, throw an error if (data.orderUpdate.userErrors.length > 0) { throw new Error( `Failed to update order: ${data.orderUpdate.userErrors .map((e) => `${e.field}: ${e.message}`) .join(", ")}` ); } // Format and return the updated order const order = data.orderUpdate.order; // Return the updated order data return { order: { id: order.id, name: order.name, email: order.email, note: order.note, tags: order.tags, customAttributes: order.customAttributes, metafields: order.metafields?.edges.map((edge: any) => edge.node) || [], shippingAddress: order.shippingAddress } }; } catch (error) { console.error("Error updating order:", error); throw new Error( `Failed to update order: ${ error instanceof Error ? error.message : String(error) }` ); } }
- src/tools/updateOrder.ts:10-48 (schema)Zod input schema defining the structure for updating an order, used by the tool.const UpdateOrderInputSchema = z.object({ id: z.string().min(1), tags: z.array(z.string()).optional(), email: z.string().email().optional(), note: z.string().optional(), customAttributes: z .array( z.object({ key: z.string(), value: z.string() }) ) .optional(), metafields: z .array( z.object({ id: z.string().optional(), namespace: z.string().optional(), key: z.string().optional(), value: z.string(), type: z.string().optional() }) ) .optional(), shippingAddress: z .object({ address1: z.string().optional(), address2: z.string().optional(), city: z.string().optional(), company: z.string().optional(), country: z.string().optional(), firstName: z.string().optional(), lastName: z.string().optional(), phone: z.string().optional(), province: z.string().optional(), zip: z.string().optional() }) .optional() });
- src/index.ts:152-199 (registration)Registration of the 'update-order' tool in the MCP server, including inline schema and wrapper handler calling the tool's execute method.server.tool( "update-order", { id: z.string().min(1), tags: z.array(z.string()).optional(), email: z.string().email().optional(), note: z.string().optional(), customAttributes: z .array( z.object({ key: z.string(), value: z.string() }) ) .optional(), metafields: z .array( z.object({ id: z.string().optional(), namespace: z.string().optional(), key: z.string().optional(), value: z.string(), type: z.string().optional() }) ) .optional(), shippingAddress: z .object({ address1: z.string().optional(), address2: z.string().optional(), city: z.string().optional(), company: z.string().optional(), country: z.string().optional(), firstName: z.string().optional(), lastName: z.string().optional(), phone: z.string().optional(), province: z.string().optional(), zip: z.string().optional() }) .optional() }, async (args) => { const result = await updateOrder.execute(args); return { content: [{ type: "text", text: JSON.stringify(result) }] }; } );
- src/tools/updateOrder.ts:58-60 (helper)Initialize method to set the Shopify GraphQL client for use in the execute handler.initialize(client: GraphQLClient) { shopifyClient = client; },