Skip to main content
Glama
amir-bengherbi

Shopify MCP Server

get-order

Retrieve specific order details by ID from a Shopify store to view, analyze, or process order information.

Instructions

Get a single order by ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
orderIdYesID of the order to retrieve

Implementation Reference

  • src/index.ts:320-341 (registration)
    Registration of the 'get-order' MCP tool, including input schema (zod) and handler function that delegates to ShopifyClient.loadOrder
    server.tool(
      "get-order",
      "Get a single order by ID",
      {
        orderId: z.string().describe("ID of the order to retrieve"),
      },
      async ({ orderId }) => {
        const client = new ShopifyClient();
        try {
          const order = await client.loadOrder(
            SHOPIFY_ACCESS_TOKEN,
            MYSHOPIFY_DOMAIN,
            { orderId }
          );
          return {
            content: [{ type: "text", text: JSON.stringify(order, null, 2) }],
          };
        } catch (error) {
          return handleError("Failed to retrieve order", error);
        }
      }
    );
  • Core handler implementation: loadOrder method performs REST API call to Shopify Admin API to fetch single order by ID
    async loadOrder(
      accessToken: string,
      shop: string,
      queryParams: ShopifyLoadOrderQueryParams
    ): Promise<ShopifyOrder> {
      const res = await this.shopifyHTTPRequest<{ order: ShopifyOrder }>({
        method: "GET",
        url: `https://${shop}/admin/api/${this.SHOPIFY_API_VERSION}/orders/${queryParams.orderId}.json`,
        accessToken,
        params: {
          fields: this.getOrdersFields(queryParams.fields),
        },
      });
    
      return res.data.order;
    }
  • Input schema for get-order tool using Zod validation
    {
      orderId: z.string().describe("ID of the order to retrieve"),
    },
  • Type definition for the ShopifyOrder returned by the tool
    export type ShopifyOrder = {
      id: string;
      createdAt: string;
      currencyCode: string;
      discountApplications: {
        nodes: Array<{
          code: string | null;
          value: {
            amount: string | null;
            percentage: number | null;
          };
          __typename: string;
        }>;
      };
      displayFinancialStatus: string | null;
      name: string;
      totalPriceSet: {
        shopMoney: { amount: string; currencyCode: string };
        presentmentMoney: { amount: string; currencyCode: string };
      };
      totalShippingPriceSet: {
        shopMoney: { amount: string; currencyCode: string };
        presentmentMoney: { amount: string; currencyCode: string };
      };
      customer?: {
        id: string;
        email: string;
        firstName: string;
        lastName: string;
        phone: string;
      };
    };
  • Helper function getOrdersFields used to specify fields in the order API request
    private getOrdersFields(fields?: string[]): string {
      const defaultFields = [
        "id",
        "order_number",
        "total_price",
        "discount_codes",
        "currency",
        "financial_status",
        "total_shipping_price_set",
        "created_at",
        "customer",
        "email",
      ];
    
      if (!fields) return defaultFields.join(",");
    
      return [...defaultFields, ...fields].join(",");
    }

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