Skip to main content
Glama

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
NameRequiredDescriptionDefault
customAttributesNo
emailNo
idYes
metafieldsNo
noteNo
shippingAddressNo
tagsNo

Implementation Reference

  • 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)
          }`
        );
      }
    }
  • 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) }]
        };
      }
    );
  • Initialize method to set the Shopify GraphQL client for use in the execute handler.
    initialize(client: GraphQLClient) {
      shopifyClient = client;
    },
Install Server

Other Tools

Related 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/GeLi2001/shopify-mcp'

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