Skip to main content
Glama
clavia-labs

Shopify Update MCP Server

by clavia-labs

manage-webhook

Subscribe to, find, or unsubscribe from Shopify order update webhooks to receive real-time notifications when orders change.

Instructions

Subscribe, find, or unsubscribe webhooks

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction to perform with webhook
callbackUrlYesWebhook callback URL
topicYesWebhook topic to subscribe to
webhookIdNoWebhook ID (required for unsubscribe)

Implementation Reference

  • src/index.ts:574-636 (registration)
    Registers the 'manage-webhook' MCP tool with description, Zod input schema, and async handler function that switches on 'action' to call ShopifyClient subscribe/find/unsubscribe methods.
    server.tool(
      "manage-webhook",
      "Subscribe, find, or unsubscribe webhooks",
      {
        action: z
          .enum(["subscribe", "find", "unsubscribe"])
          .describe("Action to perform with webhook"),
        callbackUrl: z.string().url().describe("Webhook callback URL"),
        topic: z
          .nativeEnum(ShopifyWebhookTopic)
          .describe("Webhook topic to subscribe to"),
        webhookId: z
          .string()
          .optional()
          .describe("Webhook ID (required for unsubscribe)"),
      },
      async ({ action, callbackUrl, topic, webhookId }) => {
        const client = new ShopifyClient();
        try {
          switch (action) {
            case "subscribe": {
              const webhook = await client.subscribeWebhook(
                SHOPIFY_ACCESS_TOKEN,
                MYSHOPIFY_DOMAIN,
                callbackUrl,
                topic
              );
              return {
                content: [{ type: "text", text: JSON.stringify(webhook, null, 2) }],
              };
            }
            case "find": {
              const webhook = await client.findWebhookByTopicAndCallbackUrl(
                SHOPIFY_ACCESS_TOKEN,
                MYSHOPIFY_DOMAIN,
                callbackUrl,
                topic
              );
              return {
                content: [{ type: "text", text: JSON.stringify(webhook, null, 2) }],
              };
            }
            case "unsubscribe": {
              if (!webhookId) {
                throw new Error("webhookId is required for unsubscribe action");
              }
              await client.unsubscribeWebhook(
                SHOPIFY_ACCESS_TOKEN,
                MYSHOPIFY_DOMAIN,
                webhookId
              );
              return {
                content: [
                  { type: "text", text: "Webhook unsubscribed successfully" },
                ],
              };
            }
          }
        } catch (error) {
          return handleError("Failed to manage webhook", error);
        }
      }
    );
  • Zod schema for tool inputs: action enum, callbackUrl (URL), topic (ShopifyWebhookTopic enum), optional webhookId.
    {
      action: z
        .enum(["subscribe", "find", "unsubscribe"])
        .describe("Action to perform with webhook"),
      callbackUrl: z.string().url().describe("Webhook callback URL"),
      topic: z
        .nativeEnum(ShopifyWebhookTopic)
        .describe("Webhook topic to subscribe to"),
      webhookId: z
        .string()
        .optional()
        .describe("Webhook ID (required for unsubscribe)"),
    },
  • Implements webhook subscription creation via GraphQL mutation 'webhookSubscriptionCreate', maps REST topic to GraphQL topic, handles user errors.
    async subscribeWebhook(
      accessToken: string,
      shop: string,
      callbackUrl: string,
      topic: ShopifyWebhookTopic
    ): Promise<ShopifyWebhook> {
      const myshopifyDomain = await this.getMyShopifyDomain(accessToken, shop);
    
      const graphqlQuery = gql`
        mutation webhookSubscriptionCreate(
          $topic: WebhookSubscriptionTopic!
          $webhookSubscription: WebhookSubscriptionInput!
        ) {
          webhookSubscriptionCreate(
            topic: $topic
            webhookSubscription: $webhookSubscription
          ) {
            webhookSubscription {
              id
              topic
              endpoint {
                __typename
                ... on WebhookHttpEndpoint {
                  callbackUrl
                }
              }
            }
            userErrors {
              field
              message
            }
          }
        }
      `;
    
      const res = await this.shopifyGraphqlRequest<{
        data: {
          webhookSubscriptionCreate: {
            webhookSubscription: {
              id: string;
              topic: ShopifyWebhookTopicGraphql;
              endpoint: {
                callbackUrl: string;
              };
            };
            userErrors: Array<{
              field: string[];
              message: string;
            }>;
          };
        };
      }>({
        url: `https://${myshopifyDomain}/admin/api/${this.SHOPIFY_API_VERSION}/graphql.json`,
        accessToken,
        query: graphqlQuery,
        variables: {
          topic: this.mapTopicToGraphqlTopic(topic),
          webhookSubscription: {
            callbackUrl,
          },
        },
      });
    
      const webhookSubscription =
        res.data.data.webhookSubscriptionCreate.webhookSubscription;
      const userErrors = res.data.data.webhookSubscriptionCreate.userErrors;
    
      if (userErrors.length > 0) {
        throw getGraphqlShopifyUserError(userErrors, {
          shop,
          topic,
          callbackUrl: callbackUrl,
        });
      }
    
      return {
        id: webhookSubscription.id,
        topic: this.mapGraphqlTopicToTopic(webhookSubscription.topic),
        callbackUrl: webhookSubscription.endpoint.callbackUrl,
      };
    }
  • Queries existing webhooks by topic and callbackUrl using GraphQL 'webhookSubscriptions' query, returns matching webhook or null.
    async findWebhookByTopicAndCallbackUrl(
      accessToken: string,
      shop: string,
      callbackUrl: string,
      topic: ShopifyWebhookTopic
    ): Promise<ShopifyWebhook | null> {
      const myshopifyDomain = await this.getMyShopifyDomain(accessToken, shop);
    
      const graphqlQuery = gql`
        query webhookSubscriptions(
          $topics: [WebhookSubscriptionTopic!]
          $callbackUrl: URL!
        ) {
          webhookSubscriptions(
            first: 10
            topics: $topics
            callbackUrl: $callbackUrl
          ) {
            edges {
              node {
                id
                topic
                endpoint {
                  __typename
                  ... on WebhookHttpEndpoint {
                    callbackUrl
                  }
                }
              }
            }
          }
        }
      `;
    
      const res = await this.shopifyGraphqlRequest<{
        data: {
          webhookSubscriptions: {
            edges: {
              node: {
                id: string;
                topic: ShopifyWebhookTopicGraphql;
                endpoint: {
                  callbackUrl: string;
                };
              };
            }[];
          };
        };
      }>({
        url: `https://${myshopifyDomain}/admin/api/${this.SHOPIFY_API_VERSION}/graphql.json`,
        accessToken,
        query: graphqlQuery,
        variables: {
          topics: [this.mapTopicToGraphqlTopic(topic)],
          callbackUrl,
        },
      });
    
      const webhookSubscriptions = res.data.data.webhookSubscriptions.edges;
      if (webhookSubscriptions.length === 0) {
        return null;
      }
    
      const webhookSubscription = webhookSubscriptions[0].node;
      return {
        id: webhookSubscription.id,
        topic: this.mapGraphqlTopicToTopic(webhookSubscription.topic),
        callbackUrl: webhookSubscription.endpoint.callbackUrl,
      };
    }
  • Deletes webhook subscription by ID using GraphQL mutation 'webhookSubscriptionDelete', throws on user errors.
    async unsubscribeWebhook(
      accessToken: string,
      shop: string,
      webhookId: string
    ): Promise<void> {
      const myshopifyDomain = await this.getMyShopifyDomain(accessToken, shop);
    
      const graphqlQuery = gql`
        mutation webhookSubscriptionDelete($id: ID!) {
          webhookSubscriptionDelete(id: $id) {
            userErrors {
              field
              message
            }
            deletedWebhookSubscriptionId
          }
        }
      `;
    
      const res = await this.shopifyGraphqlRequest<{
        data: {
          webhookSubscriptionDelete: {
            deletedWebhookSubscriptionId: string;
            userErrors: Array<{
              field: string[];
              message: string;
            }>;
          };
        };
      }>({
        url: `https://${myshopifyDomain}/admin/api/${this.SHOPIFY_API_VERSION}/graphql.json`,
        accessToken,
        query: graphqlQuery,
        variables: {
          id: webhookId,
        },
      });
    
      const userErrors = res.data.data.webhookSubscriptionDelete.userErrors;
    
      if (userErrors.length > 0) {
        throw getGraphqlShopifyUserError(userErrors, {
          shop,
          webhookId,
        });
      }
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.9/5.0
Behavior2/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. While it implies mutation (subscribe/unsubscribe) and read (find), it doesn't specify permissions required, rate limits, side effects (e.g., whether unsubscribe destroys data), or response format. For a tool with potential write operations and no annotation coverage, this leaves critical gaps in understanding its behavior.

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 (three words) and front-loaded, with zero wasted words. Every term ('subscribe', 'find', 'unsubscribe', 'webhooks') directly contributes to understanding the tool's scope without redundancy. This efficiency makes it easy for an agent to parse quickly.

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's complexity (multiple actions including mutations), lack of annotations, and no output schema, the description is incomplete. It doesn't address behavioral aspects like authentication, error handling, or return values, which are crucial for safe invocation. While concise, it fails to provide enough context for an agent to use the tool effectively without trial and error.

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 no additional meaning about parameters beyond implying the three actions map to the 'action' enum. It doesn't clarify parameter interactions (e.g., webhookId is only for unsubscribe) or provide examples, so it meets the baseline but doesn't compensate for schema gaps (there are none).

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 tool's purpose with specific verbs (subscribe, find, unsubscribe) and resource (webhooks), making it immediately understandable. However, it doesn't differentiate this multi-action tool from its siblings, which are mostly single-action retrieval tools (e.g., get-products, get-orders) or specific creation tools (e.g., create-draft-order).

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 prerequisites (e.g., authentication needs), when to choose subscribe vs. find vs. unsubscribe, or how it relates to sibling tools like get-orders (which might overlap with webhook topics). Without this context, an agent must infer usage from parameters alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.