Skip to main content
Glama
amir-bengherbi

Shopify MCP Server

create-draft-order

Generate draft orders in Shopify by specifying line items, customer email, and shipping address for order preparation and processing.

Instructions

Create a draft order

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
lineItemsYesLine items to add to the order
emailYesCustomer email
shippingAddressYesShipping address details
noteNoOptional note for the order

Implementation Reference

  • MCP tool handler and registration for 'create-draft-order'. Defines input schema with Zod, constructs CreateDraftOrderPayload, instantiates ShopifyClient, calls createDraftOrder method, and returns JSON response or error.
    server.tool(
      "create-draft-order",
      "Create a draft order",
      {
        lineItems: z
          .array(
            z.object({
              variantId: z.string(),
              quantity: z.number(),
            })
          )
          .describe("Line items to add to the order"),
        email: z.string().email().describe("Customer email"),
        shippingAddress: z
          .object({
            address1: z.string(),
            city: z.string(),
            province: z.string(),
            country: z.string(),
            zip: z.string(),
            firstName: z.string(),
            lastName: z.string(),
            countryCode: z.string(),
          })
          .describe("Shipping address details"),
        note: z.string().optional().describe("Optional note for the order"),
      },
      async ({ lineItems, email, shippingAddress, note }) => {
        const client = new ShopifyClient();
        try {
          const draftOrderData: CreateDraftOrderPayload = {
            lineItems,
            email,
            shippingAddress,
            billingAddress: shippingAddress, // Using same address for billing
            tags: "draft",
            note: note || "",
          };
          const draftOrder = await client.createDraftOrder(
            SHOPIFY_ACCESS_TOKEN,
            MYSHOPIFY_DOMAIN,
            draftOrderData
          );
          return {
            content: [{ type: "text", text: JSON.stringify(draftOrder, null, 2) }],
          };
        } catch (error) {
          return handleError("Failed to create draft order", error);
        }
      }
    );
  • Core implementation of draft order creation in ShopifyClient class. Executes GraphQL mutation 'draftOrderCreate' via shopifyGraphqlRequest, handles userErrors, returns DraftOrderResponse.
    async createDraftOrder(
      accessToken: string,
      myshopifyDomain: string,
      draftOrderData: CreateDraftOrderPayload
    ): Promise<DraftOrderResponse> {
      const graphqlQuery = gql`
        mutation draftOrderCreate($input: DraftOrderInput!) {
          draftOrderCreate(input: $input) {
            draftOrder {
              id
              name
            }
            userErrors {
              field
              message
            }
          }
        }
      `;
    
      const res = await this.shopifyGraphqlRequest<{
        data: {
          draftOrderCreate: {
            draftOrder: {
              id: string;
              name: string;
            };
            userErrors: Array<{
              field: string[];
              message: string;
            }>;
          };
        };
      }>({
        url: `https://${myshopifyDomain}/admin/api/${this.SHOPIFY_API_VERSION}/graphql.json`,
        accessToken,
        query: graphqlQuery,
        variables: {
          input: draftOrderData,
        },
      });
    
      const draftOrder = res.data.data.draftOrderCreate.draftOrder;
      const userErrors = res.data.data.draftOrderCreate.userErrors;
    
      if (userErrors.length > 0) {
        throw getGraphqlShopifyUserError(userErrors, {
          myshopifyDomain,
          draftOrderData,
        });
      }
    
      return {
        draftOrderId: draftOrder.id,
        draftOrderName: draftOrder.name,
      };
    }
  • Zod schema defining input parameters for the create-draft-order tool: lineItems array, email, shippingAddress object, optional note.
    {
      lineItems: z
        .array(
          z.object({
            variantId: z.string(),
            quantity: z.number(),
          })
        )
        .describe("Line items to add to the order"),
      email: z.string().email().describe("Customer email"),
      shippingAddress: z
        .object({
          address1: z.string(),
          city: z.string(),
          province: z.string(),
          country: z.string(),
          zip: z.string(),
          firstName: z.string(),
          lastName: z.string(),
          countryCode: z.string(),
        })
        .describe("Shipping address details"),
      note: z.string().optional().describe("Optional note for the order"),
    },
  • TypeScript type definition for CreateDraftOrderPayload used in the tool's handler and ShopifyClient method.
    export type CreateDraftOrderPayload = {
      lineItems: Array<{
        variantId: string;
        quantity: number;
        appliedDiscount?: {
          title: string;
          value: number;
          valueType: "FIXED_AMOUNT" | "PERCENTAGE";
        };
      }>;
      shippingAddress: {
        address1: string;
        address2?: string;
        countryCode: string;
        firstName: string;
        lastName: string;
        zip: string;
        city: string;
        country: string;
        province?: string;
        provinceCode?: string;
        phone?: string;
      };
      billingAddress: {
        address1: string;
        address2?: string;
        countryCode: string;
        firstName: string;
        lastName: string;
        zip: string;
        city: string;
        country: string;
        province?: string;
        provinceCode?: string;
        phone?: string;
      };
      email: string;
      tags: string;
      note: string;
    };
  • TypeScript type for the response returned by createDraftOrder.
    export type DraftOrderResponse = {
      draftOrderId: string;
      draftOrderName: string;
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. 'Create a draft order' implies a write/mutation operation, but it doesn't disclose any behavioral traits: no information about permissions required, whether the creation is reversible, rate limits, side effects, or what happens upon success/failure. For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

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 extremely concise at just three words, with zero wasted language. It's front-loaded with the core action and resource. While this conciseness contributes to under-specification in other dimensions, as a standalone assessment of brevity and structure, it's maximally efficient.

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 complexity (4 parameters including nested objects, no output schema, and no annotations), the description is incomplete. It doesn't explain what a draft order is, how it differs from a completed order, what the tool returns, or any behavioral context. For a mutation tool that creates a complex resource, the description fails to provide adequate context for an agent to use it effectively.

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%, with clear descriptions for each parameter (e.g., 'Line items to add to the order', 'Customer email'). The description adds no additional meaning beyond what the schema already provides. According to the rules, when schema coverage is high (>80%), the baseline score is 3 even with no parameter info in the description, which applies here.

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

Purpose2/5

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

The description 'Create a draft order' is a tautology that essentially restates the tool name 'create-draft-order'. While it indicates the action (create) and resource (draft order), it doesn't provide any additional specificity about what a draft order entails or how it differs from other order-related tools like 'complete-draft-order' or 'get-order'. The purpose is stated but lacks meaningful differentiation from siblings.

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

Usage Guidelines1/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 prerequisites (e.g., whether customer or product data must exist first), when to choose this over 'complete-draft-order', or any constraints on usage. With siblings like 'complete-draft-order' and 'get-order', the absence of comparative guidance leaves the agent guessing about appropriate contexts.

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