Skip to main content
Glama

update-order

Modify Shopify order details including customer information, shipping address, tags, notes, and custom attributes through the Shopify MCP Server.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYes
tagsNo
emailNo
noteNo
customAttributesNo
metafieldsNo
shippingAddressNo

Implementation Reference

  • The execute method contains the main handler logic for updating an order. It performs a GraphQL mutation (orderUpdate) with the provided input, handles errors, and returns the updated order data including id, name, email, note, tags, customAttributes, metafields, and shippingAddress.
    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)
          }`
        );
      }
    }
  • The UpdateOrderInputSchema defines the input validation schema using zod. It specifies required field 'id' (string), and optional fields: tags (string array), email (email string), note (string), customAttributes (array of key-value objects), metafields (array with id, namespace, key, value, type), and shippingAddress (object with address fields).
    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)
    Registers the 'update-order' tool with the MCP server. Defines the input schema (duplicate of UpdateOrderInputSchema) and provides an async handler that calls updateOrder.execute(args) and returns the result as JSON string content.
    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) }]
        };
      }
    );
  • The initialize method sets up the GraphQL client (shopifyClient) that will be used to make requests to the Shopify API.
    initialize(client: GraphQLClient) {
      shopifyClient = client;
    },
  • Initializes the updateOrder tool with the Shopify GraphQL client, enabling it to make API requests.
    updateOrder.initialize(shopifyClient);

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/anass319/shopify-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server