Skip to main content
Glama

run_shopifyql_query

Execute ShopifyQL analytics queries on store data and return results as an ASCII table or raw JSON payload.

Instructions

Run a ShopifyQL query against the store and return the result as a rendered ASCII table. ShopifyQL is Shopify's SQL-like analytics language. Examples: 'FROM sales SHOW total_sales BY day SINCE -30d TIMESERIES', 'FROM products SHOW product_title, quantity_sold BY product_id SINCE -7d ORDER BY quantity_sold DESC LIMIT 10'.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesShopifyQL query string. Example: 'FROM sales SHOW total_sales, gross_sales BY day SINCE -30d TIMESERIES'
rawNoReturn the raw unformatted JSON payload instead of a rendered table.

Implementation Reference

  • The 'run_shopifyql_query' tool handler: registers the tool with server.tool(), executes the ShopifyQL GraphQL query via ShopifyClient.graphql(), handles parse errors, and returns either raw JSON or a rendered ASCII table.
    export function registerAnalyticsTools(
      server: McpServer,
      client: ShopifyClient,
    ): void {
      server.tool(
        "run_shopifyql_query",
        "Run a ShopifyQL query against the store and return the result as a rendered ASCII table. ShopifyQL is Shopify's SQL-like analytics language. Examples: 'FROM sales SHOW total_sales BY day SINCE -30d TIMESERIES', 'FROM products SHOW product_title, quantity_sold BY product_id SINCE -7d ORDER BY quantity_sold DESC LIMIT 10'.",
        runShopifyqlSchema,
        async (args) => {
          const data = await client.graphql<{
            shopifyqlQuery: ShopifyqlResponse | null;
          }>(RUN_SHOPIFYQL_QUERY, { query: args.query });
          const resp = data.shopifyqlQuery;
          if (!resp) {
            return {
              content: [{ type: "text" as const, text: "ShopifyQL returned no response." }],
            };
          }
          if (resp.parseErrors && resp.parseErrors.length > 0) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: [
                    "ShopifyQL parse errors:",
                    ...resp.parseErrors.map(
                      (e) =>
                        `  [${e.code}] ${e.message}${e.range ? ` (line ${e.range.start.line}:${e.range.start.character})` : ""}`,
                    ),
                  ].join("\n"),
                },
              ],
            };
          }
          if (!resp.tableData) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: `No table data returned (typename=${resp.__typename ?? "unknown"}).`,
                },
              ],
            };
          }
          if (args.raw) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: resp.tableData.unformattedData ?? JSON.stringify(resp.tableData, null, 2),
                },
              ],
            };
          }
          return {
            content: [
              {
                type: "text" as const,
                text: [
                  `Rows: ${resp.tableData.rowData.length}`,
                  renderTable(resp.tableData),
                ].join("\n"),
              },
            ],
          };
        },
      );
    }
  • Input schema for run_shopifyql_query: 'query' (string) the ShopifyQL query string, and 'raw' (boolean, default false) to return raw JSON instead of a rendered table.
    const runShopifyqlSchema = {
      query: z
        .string()
        .describe(
          "ShopifyQL query string. Example: 'FROM sales SHOW total_sales, gross_sales BY day SINCE -30d TIMESERIES'",
        ),
      raw: z
        .boolean()
        .default(false)
        .describe("Return the raw unformatted JSON payload instead of a rendered table."),
    };
  • The GraphQL query string used by the tool, named RUN_SHOPIFYQL_QUERY, which calls shopifyqlQuery with the provided query string and extracts tableData and parseErrors.
    const RUN_SHOPIFYQL_QUERY = /* GraphQL */ `
      query RunShopifyQL($query: String!) {
        shopifyqlQuery(query: $query) {
          __typename
          ... on TableResponse {
            tableData {
              columns { name displayName dataType }
              rowData
              unformattedData
            }
            parseErrors {
              code
              message
              range {
                start { line character }
                end { line character }
              }
            }
          }
        }
      }
    `;
  • The renderTable helper function that formats TableData (columns + rows) into an ASCII table for human-readable output.
    function renderTable(td: TableData): string {
      if (td.rowData.length === 0) {
        return "(no rows)";
      }
      const headers = td.columns.map((c) => c.displayName);
      const widths = headers.map((h, i) =>
        Math.max(
          h.length,
          ...td.rowData.map((row) => (row[i] ?? "").length),
        ),
      );
      const pad = (s: string, w: number) => s + " ".repeat(Math.max(0, w - s.length));
      const headerLine = headers.map((h, i) => pad(h, widths[i] ?? 0)).join(" | ");
      const sepLine = widths.map((w) => "-".repeat(w)).join("-+-");
      const bodyLines = td.rowData.map((row) =>
        row.map((cell, i) => pad(cell ?? "", widths[i] ?? 0)).join(" | "),
      );
      const typeLine = td.columns
        .map((c, i) => pad(`(${c.dataType})`, widths[i] ?? 0))
        .join(" | ");
      return [headerLine, typeLine, sepLine, ...bodyLines].join("\n");
    }
  • src/server.ts:68-68 (registration)
    Registration call: registerAnalyticsTools is invoked with the MCP server and Shopify client in buildContext.
    registerAnalyticsTools(s, shopify);
Behavior3/5

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

With no annotations, the description carries full burden. It explains the output format (ASCII table or raw JSON) but does not explicitly state the tool is read-only or mention any side effects, auth requirements, or limits. It provides reasonable but not comprehensive behavioral cues.

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 concise and well-structured: a single purpose sentence, a brief explanation of ShopifyQL, and two illustrative examples. Every sentence adds information, no fluff.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of output schema, the description adequately describes the return format and provides examples. However, it could mention error handling, query limits, or the read-only nature for completeness. Still, it covers the core functionality well.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema already provides descriptions for both parameters (100% coverage). The description adds value by explaining ShopifyQL and giving concrete examples (e.g., 'FROM sales SHOW total_sales BY day SINCE -30d TIMESERIES'), which clarify the query parameter beyond the schema's brief description.

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

Purpose5/5

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

The description clearly states 'Run a ShopifyQL query against the store and return the result as a rendered ASCII table', using a specific verb ('run'), resource ('ShopifyQL query'), and output format. It distinguishes itself from sibling CRUD tools by being a query/analytics tool.

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

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description does not explicitly state when to use this tool versus alternatives, but its purpose as an analytics query tool is implied. No exclusions or alternative suggestions are provided, leaving the agent to infer usage context from the tool's name and examples.

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/miller-joe/shopify-mcp'

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