Skip to main content
Glama
amir-bengherbi

Shopify MCP Server

get-orders

Retrieve Shopify orders with filtering, sorting, and pagination capabilities to manage store data efficiently.

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:276-317 (registration)
    Registration of the MCP 'get-orders' tool, including input schema and the handler function that delegates to ShopifyClient.loadOrders and formats the 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);
        }
      }
  • Helper function formatOrder used by the get-orders handler to format order data into readable text.
    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 handler implementation in ShopifyClient.loadOrders that performs the GraphQL query to fetch orders from Shopify API with filtering, sorting, and pagination.
    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,
      };
    }
  • TypeScript type definitions for input parameters (ShopifyOrdersGraphqlQueryParams) and response (ShopifyOrdersGraphqlResponse) used by the loadOrders method and thus the get-orders tool.
    export type ShopifyOrdersGraphqlQueryParams = {
      first?: number;
      after?: string;
      query?: string;
      sortKey?:
        | "PROCESSED_AT"
        | "TOTAL_PRICE"
        | "ID"
        | "CREATED_AT"
        | "UPDATED_AT"
        | "ORDER_NUMBER";
      reverse?: boolean;
    };
    
    export type ShopifyOrdersGraphqlResponse = {
      orders: ShopifyOrderGraphql[];
      pageInfo: {
        hasNextPage: boolean;
        endCursor: string | null;
      };
    };
  • Type definition for ShopifyOrderGraphql, the data structure for individual orders returned by the GraphQL query in loadOrders.
    export type ShopifyOrderGraphql = {
      id: string;
      name: string;
      createdAt: string;
      displayFinancialStatus: string;
      email: string;
      phone: string | null;
      totalPriceSet: {
        shopMoney: { amount: string; currencyCode: string };
        presentmentMoney: { amount: string; currencyCode: string };
      };
      customer: {
        id: string;
        email: string;
      } | null;
      shippingAddress: {
        provinceCode: string | null;
        countryCode: string;
      } | null;
      lineItems: {
        nodes: Array<{
          id: string;
          title: string;
          quantity: number;
          originalTotalSet: {
            shopMoney: { amount: string; currencyCode: string };
          };
          variant: {
            id: string;
            title: string;
            sku: string | null;
            price: string;
          } | null;
        }>;
      };
    };
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 explain what that entails operationally. It doesn't disclose whether this is a read-only operation, what permissions are required, whether there are rate limits, pagination behavior (implied by 'first' and 'after' parameters but not stated), or what the output format looks like. For a tool with 5 parameters and no output schema, this leaves significant gaps.

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 without unnecessary words. It's appropriately sized for a tool with this complexity level and gets straight to the point. Every word earns its place, with no redundant information or fluff.

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

Completeness2/5

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

Given the tool has 5 parameters, no annotations, and no output schema, the description is insufficiently complete. It doesn't explain what 'advanced filtering' means operationally, doesn't describe the return format or structure, and provides no guidance on error conditions or limitations. For a data retrieval tool with multiple filtering/sorting options, users need more context about what to expect when invoking it.

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?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds 'advanced filtering and sorting' which aligns with the 'query' and 'sortKey'/'reverse' parameters, providing some high-level context. However, it doesn't add specific meaning beyond what the schema provides, such as explaining query syntax examples or typical sortKey usage patterns.

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 verb ('Get') and resource ('shopify orders'), making the purpose evident. It adds 'with advanced filtering and sorting' which provides useful context about capabilities. However, it doesn't explicitly differentiate from sibling tools like 'get-order' (singular) or 'get-customers', leaving some ambiguity about when to choose this specific tool.

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. It doesn't mention when to use 'get-orders' versus 'get-order' (singular), nor does it indicate prerequisites, context requirements, or typical use cases. The phrase 'advanced filtering and sorting' hints at capabilities but doesn't specify when those features are needed.

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/amir-bengherbi/shopify-mcp-server'

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