Skip to main content
Glama
smithery-ai

Shopify Update MCP Server

by smithery-ai

get-orders

Retrieve Shopify orders with advanced filtering, sorting, and pagination to manage and analyze store transactions.

Instructions

Get shopify orders with advanced filtering and sorting

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
firstNoLimit of orders to return
afterNoNext page cursor
queryNoFilter orders using query syntax
sortKeyNoField to sort by
reverseNoReverse sort order

Implementation Reference

  • src/index.ts:304-346 (registration)
    Registration of the 'get-orders' tool, including input schema and inline handler function that delegates to ShopifyClient.loadOrders and formats output.
    server.tool(
      "get-orders",
      "Get shopify orders with advanced filtering and sorting",
      {
        first: z.number().optional().describe("Limit of orders to return"),
        after: z.string().optional().describe("Next page cursor"),
        query: z.string().optional().describe("Filter orders using query syntax"),
        sortKey: z
          .enum([
            "PROCESSED_AT",
            "TOTAL_PRICE",
            "ID",
            "CREATED_AT",
            "UPDATED_AT",
            "ORDER_NUMBER",
          ])
          .optional()
          .describe("Field to sort by"),
        reverse: z.boolean().optional().describe("Reverse sort order"),
      },
      async ({ first, after, query, sortKey, reverse }) => {
        const client = new ShopifyClient();
        try {
          const response = await client.loadOrders(
            SHOPIFY_ACCESS_TOKEN,
            MYSHOPIFY_DOMAIN,
            {
              first,
              after,
              query,
              sortKey,
              reverse,
            }
          );
          const formattedOrders = response.orders.map(formatOrder);
          return {
            content: [{ type: "text", text: formattedOrders.join("\n---\n") }],
          };
        } catch (error) {
          return handleError("Failed to retrieve orders data", error);
        }
      }
    );
  • Zod input schema defining parameters for the get-orders tool: first, after, query, sortKey, reverse.
    {
      first: z.number().optional().describe("Limit of orders to return"),
      after: z.string().optional().describe("Next page cursor"),
      query: z.string().optional().describe("Filter orders using query syntax"),
      sortKey: z
        .enum([
          "PROCESSED_AT",
          "TOTAL_PRICE",
          "ID",
          "CREATED_AT",
          "UPDATED_AT",
          "ORDER_NUMBER",
        ])
        .optional()
        .describe("Field to sort by"),
      reverse: z.boolean().optional().describe("Reverse sort order"),
    },
  • Inline handler function for get-orders tool: creates ShopifyClient, calls loadOrders, formats results with formatOrder, returns formatted text content.
      async ({ first, after, query, sortKey, reverse }) => {
        const client = new ShopifyClient();
        try {
          const response = await client.loadOrders(
            SHOPIFY_ACCESS_TOKEN,
            MYSHOPIFY_DOMAIN,
            {
              first,
              after,
              query,
              sortKey,
              reverse,
            }
          );
          const formattedOrders = response.orders.map(formatOrder);
          return {
            content: [{ type: "text", text: formattedOrders.join("\n---\n") }],
          };
        } catch (error) {
          return handleError("Failed to retrieve orders data", error);
        }
      }
    );
  • Helper function to format a ShopifyOrderGraphql object into a human-readable string.
    function formatOrder(order: ShopifyOrderGraphql): string {
      return `
      Order: ${order.name} (${order.id})
      Created At: ${order.createdAt}
      Status: ${order.displayFinancialStatus || "N/A"}
      Email: ${order.email || "N/A"}
      Phone: ${order.phone || "N/A"}
      
      Total Price: ${order.totalPriceSet.shopMoney.amount} ${
        order.totalPriceSet.shopMoney.currencyCode
      }
      
      Customer: ${
        order.customer
          ? `
        ID: ${order.customer.id}
        Email: ${order.customer.email}`
          : "No customer information"
      }
    
      Shipping Address: ${
        order.shippingAddress
          ? `
        Province: ${order.shippingAddress.provinceCode || "N/A"}
        Country: ${order.shippingAddress.countryCode}`
          : "No shipping address"
      }
    
      Line Items: ${
        order.lineItems.nodes.length > 0
          ? order.lineItems.nodes
              .map(
                (item) => `
        Title: ${item.title}
        Quantity: ${item.quantity}
        Price: ${item.originalTotalSet.shopMoney.amount} ${
                  item.originalTotalSet.shopMoney.currencyCode
                }
        Variant: ${
          item.variant
            ? `
          Title: ${item.variant.title}
          SKU: ${item.variant.sku || "N/A"}
          Price: ${item.variant.price}`
            : "No variant information"
        }`
              )
              .join("\n")
          : "No items"
      }
      `;
  • Core helper method in ShopifyClient class that executes GraphQL query to Shopify Admin API to fetch orders with pagination, filtering, sorting.
    async loadOrders(
      accessToken: string,
      shop: string,
      queryParams: ShopifyOrdersGraphqlQueryParams
    ): Promise<ShopifyOrdersGraphqlResponse> {
      const myshopifyDomain = await this.getMyShopifyDomain(accessToken, shop);
    
      const graphqlQuery = gql`
        query getOrdersDetailed(
          $first: Int
          $after: String
          $query: String
          $sortKey: OrderSortKeys
          $reverse: Boolean
        ) {
          orders(
            first: $first
            after: $after
            query: $query
            sortKey: $sortKey
            reverse: $reverse
          ) {
            nodes {
              id
              name
              createdAt
              displayFinancialStatus
              email
              phone
              totalPriceSet {
                shopMoney {
                  amount
                  currencyCode
                }
                presentmentMoney {
                  amount
                  currencyCode
                }
              }
              customer {
                id
                email
              }
              shippingAddress {
                provinceCode
                countryCode
              }
              lineItems(first: 50) {
                nodes {
                  id
                  title
                  quantity
                  originalTotalSet {
                    shopMoney {
                      amount
                      currencyCode
                    }
                  }
                  variant {
                    id
                    title
                    sku
                    price
                  }
                }
              }
            }
            pageInfo {
              hasNextPage
              endCursor
            }
          }
        }
      `;
    
      const variables = {
        first: queryParams.first || 50,
        after: queryParams.after,
        query: queryParams.query,
        sortKey: queryParams.sortKey,
        reverse: queryParams.reverse,
      };
    
      const res = await this.shopifyGraphqlRequest<{
        data: {
          orders: {
            nodes: ShopifyOrderGraphql[];
            pageInfo: {
              hasNextPage: boolean;
              endCursor: string | null;
            };
          };
        };
      }>({
        url: `https://${myshopifyDomain}/admin/api/${this.SHOPIFY_API_VERSION}/graphql.json`,
        accessToken,
        query: graphqlQuery,
        variables,
      });
    
      return {
        orders: res.data.data.orders.nodes,
        pageInfo: res.data.data.orders.pageInfo,
      };
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions 'advanced filtering and sorting' but doesn't describe what 'advanced' means, whether this is a read-only operation, if there are rate limits, authentication requirements, pagination behavior (though schema hints at it), or what the response format looks like. For a tool with 5 parameters and no annotations, this is insufficient behavioral context.

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?

The description is a single, efficient sentence that communicates the core purpose upfront. Every word earns its place - 'Get shopify orders' establishes the action and resource, while 'with advanced filtering and sorting' adds valuable capability context without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 5 parameters, 100% schema coverage, no annotations, and no output schema, the description is minimally adequate. It establishes the basic purpose but lacks important context about behavioral characteristics, usage guidelines, and output expectations. The schema handles parameter documentation, but the description doesn't compensate for the missing annotation and output information.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, so all parameters are documented in the schema itself. The description adds 'advanced filtering and sorting' which aligns with the 'query' and 'sortKey' parameters but doesn't provide additional semantic context beyond what's already in the schema. This meets the baseline expectation when schema coverage is complete.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get') and resource ('shopify orders'), making the purpose immediately understandable. It adds 'with advanced filtering and sorting' which provides useful context about capabilities. However, it doesn't specifically differentiate from sibling tools like 'get-order' (singular) or explain how this differs from other retrieval tools in the set.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'get-order' (singular) or other retrieval tools in the sibling list. There's no mention of prerequisites, appropriate contexts, or exclusions. The phrase 'advanced filtering and sorting' implies capability but doesn't provide usage context.

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/smithery-ai/shopify-mcp-server-main-1'

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