Skip to main content
Glama
smithery-ai

Shopify Update MCP Server

by smithery-ai

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,
        });
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but offers minimal insight. It mentions three actions but doesn't describe what each does operationally (e.g., whether 'subscribe' creates a persistent subscription, 'find' retrieves existing ones, or 'unsubscribe' removes them), nor does it cover permissions, rate limits, or side effects. This leaves significant gaps for a tool with mutation capabilities.

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 and front-loaded, consisting of a single, efficient phrase that directly states the tool's scope. Every word earns its place, with no redundant or verbose elements, making it easy 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) and lack of annotations or output schema, the description is incomplete. It doesn't explain return values, error conditions, or behavioral nuances, leaving the agent under-informed about how to use it effectively in context with sibling tools.

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 all four parameters. The description adds no additional parameter semantics beyond implying the tool handles webhooks, which aligns with parameter names like 'callbackUrl' and 'topic'. This meets the baseline for high schema coverage without extra value.

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, or unsubscribe') and resource ('webhooks'), making it immediately understandable. However, it doesn't differentiate this multi-action tool from its siblings, which are mostly single-purpose CRUD operations on different resources like orders, products, and customers.

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. The description lists actions but doesn't specify prerequisites, constraints, or relationships to sibling tools. For example, it doesn't indicate whether webhooks relate to order updates (as suggested by the 'orders/updated' topic) versus other operations in the sibling set.

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/smithery-ai/shopify-mcp-server-main-1'

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