Skip to main content
Glama
amir-bengherbi

Shopify MCP Server

complete-draft-order

Finalize a draft order in Shopify by converting it to a completed order using the draft order ID and variant ID.

Instructions

Complete a draft order

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
draftOrderIdYesID of the draft order to complete
variantIdYesID of the variant in the draft order

Implementation Reference

  • src/index.ts:456-481 (registration)
    MCP tool registration for 'complete-draft-order', including input schema (Zod) and thin handler that instantiates ShopifyClient and calls completeDraftOrder
    server.tool(
      "complete-draft-order",
      "Complete a draft order",
      {
        draftOrderId: z.string().describe("ID of the draft order to complete"),
        variantId: z.string().describe("ID of the variant in the draft order"),
      },
      async ({ draftOrderId, variantId }) => {
        const client = new ShopifyClient();
        try {
          const completedOrder = await client.completeDraftOrder(
            SHOPIFY_ACCESS_TOKEN,
            MYSHOPIFY_DOMAIN,
            draftOrderId,
            variantId
          );
          return {
            content: [
              { type: "text", text: JSON.stringify(completedOrder, null, 2) },
            ],
          };
        } catch (error) {
          return handleError("Failed to complete draft order", error);
        }
      }
    );
  • Type definition for the response of completeDraftOrder
    export type CompleteDraftOrderResponse = {
      draftOrderId: string;
      draftOrderName: string;
      orderId: string;
    };
  • Interface definition for ShopifyClientPort.completeDraftOrder method signature
    completeDraftOrder(
      accessToken: string,
      shop: string,
      draftOrderId: string,
      variantId: string
    ): Promise<CompleteDraftOrderResponse>;
  • Core implementation of completeDraftOrder: validates variant availability via loadVariantsByIds, executes Shopify GraphQL mutation 'draftOrderComplete', handles errors, and returns order details.
    async completeDraftOrder(
      accessToken: string,
      shop: string,
      draftOrderId: string,
      variantId: string
    ): Promise<CompleteDraftOrderResponse> {
      // First, load the variant to check if it's available for sale
      const variantResult = await this.loadVariantsByIds(accessToken, shop, [
        variantId,
      ]);
    
      if (!variantResult.variants || variantResult.variants.length === 0) {
        throw new ShopifyProductVariantNotFoundError({
          contextData: {
            shop,
            variantId,
          },
        });
      }
    
      const variant = variantResult.variants[0];
    
      if (!variant.availableForSale) {
        throw new ShopifyProductVariantNotAvailableForSaleError({
          contextData: {
            shop,
            variantId,
          },
        });
      }
    
      const myshopifyDomain = await this.getMyShopifyDomain(accessToken, shop);
    
      const graphqlQuery = gql`
        mutation draftOrderComplete($id: ID!) {
          draftOrderComplete(id: $id) {
            draftOrder {
              id
              name
              order {
                id
              }
            }
            userErrors {
              field
              message
            }
          }
        }
      `;
    
      const res = await this.shopifyGraphqlRequest<{
        data: {
          draftOrderComplete: {
            draftOrder: {
              id: string;
              name: string;
              order: {
                id: string;
              };
            };
            userErrors: Array<{
              field: string[];
              message: string;
            }>;
          };
        };
      }>({
        url: `https://${myshopifyDomain}/admin/api/${this.SHOPIFY_API_VERSION}/graphql.json`,
        accessToken,
        query: graphqlQuery,
        variables: {
          id: draftOrderId,
        },
      });
    
      const draftOrder = res.data.data.draftOrderComplete.draftOrder;
      const order = draftOrder.order;
      const userErrors = res.data.data.draftOrderComplete.userErrors;
    
      if (userErrors && userErrors.length > 0) {
        throw getGraphqlShopifyUserError(userErrors, {
          shop,
          draftOrderId,
          variantId,
        });
      }
    
      return {
        draftOrderId: draftOrder.id,
        orderId: order.id,
        draftOrderName: draftOrder.name,
      };
    }
Behavior2/5

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

With no annotations, the description carries full burden but only states the action without behavioral details. It doesn't disclose if this is a mutation (likely), requires specific permissions, has side effects (e.g., order becomes active), or any rate limits. This is inadequate for a tool that presumably changes state.

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, direct sentence with zero waste—'Complete a draft order' is front-loaded and appropriately sized for the tool's purpose. No unnecessary words or structure detract from clarity.

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 no annotations, no output schema, and a likely mutation tool, the description is incomplete. It doesn't explain what 'complete' does behaviorally, what happens after completion, or any error conditions. For a tool with two required parameters and potential state changes, more context is needed.

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 fully documents both parameters (draftOrderId, variantId). The description adds no meaning beyond this, such as explaining why variantId is required or how IDs are formatted. Baseline 3 is appropriate as the schema handles parameter semantics.

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

Purpose3/5

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

The description 'Complete a draft order' states a clear verb ('complete') and resource ('draft order'), but it's vague about what 'complete' entails—does it finalize, process, or submit the order? It distinguishes from siblings like 'create-draft-order' by implying a different stage, but lacks specificity on the action's outcome.

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?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an existing draft order), exclusions, or related tools like 'get-order' for post-completion checks, leaving the agent to infer usage from context alone.

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