Skip to main content
Glama

get-products

Retrieve product listings from a Shopify store using search terms and quantity limits to manage inventory data through the Shopify Admin API.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
searchTitleNo
limitNo

Implementation Reference

  • The execute method implements the main tool logic: queries Shopify's GraphQL API for products with optional title search, handles pagination via limit parameter, formats product data including variants, images, and price ranges
    execute: async (input: GetProductsInput) => {
      try {
        const { searchTitle, limit } = input;
    
        // Create query based on whether we're searching by title or not
        const query = gql`
          query GetProducts($first: Int!, $query: String) {
            products(first: $first, query: $query) {
              edges {
                node {
                  id
                  title
                  description
                  handle
                  status
                  createdAt
                  updatedAt
                  totalInventory
                  priceRangeV2 {
                    minVariantPrice {
                      amount
                      currencyCode
                    }
                    maxVariantPrice {
                      amount
                      currencyCode
                    }
                  }
                  images(first: 1) {
                    edges {
                      node {
                        url
                        altText
                      }
                    }
                  }
                  variants(first: 5) {
                    edges {
                      node {
                        id
                        title
                        price
                        inventoryQuantity
                        sku
                      }
                    }
                  }
                }
              }
            }
          }
        `;
    
        const variables = {
          first: limit,
          query: searchTitle ? `title:*${searchTitle}*` : undefined
        };
    
        const data = (await shopifyClient.request(query, variables)) as {
          products: any;
        };
    
        // Extract and format product data
        const products = data.products.edges.map((edge: any) => {
          const product = edge.node;
    
          // Format variants
          const variants = product.variants.edges.map((variantEdge: any) => ({
            id: variantEdge.node.id,
            title: variantEdge.node.title,
            price: variantEdge.node.price,
            inventoryQuantity: variantEdge.node.inventoryQuantity,
            sku: variantEdge.node.sku
          }));
    
          // Get first image if it exists
          const imageUrl =
            product.images.edges.length > 0
              ? product.images.edges[0].node.url
              : null;
    
          return {
            id: product.id,
            title: product.title,
            description: product.description,
            handle: product.handle,
            status: product.status,
            createdAt: product.createdAt,
            updatedAt: product.updatedAt,
            totalInventory: product.totalInventory,
            priceRange: {
              minPrice: {
                amount: product.priceRangeV2.minVariantPrice.amount,
                currencyCode: product.priceRangeV2.minVariantPrice.currencyCode
              },
              maxPrice: {
                amount: product.priceRangeV2.maxVariantPrice.amount,
                currencyCode: product.priceRangeV2.maxVariantPrice.currencyCode
              }
            },
            imageUrl,
            variants
          };
        });
    
        return { products };
      } catch (error) {
        console.error("Error fetching products:", error);
        throw new Error(
          `Failed to fetch products: ${
            error instanceof Error ? error.message : String(error)
          }`
        );
      }
    }
  • Input schema definition using Zod for validation: requires optional searchTitle string and limit number with default of 10
    // Input schema for getProducts
    const GetProductsInputSchema = z.object({
      searchTitle: z.string().optional(),
      limit: z.number().default(10)
    });
    
    type GetProductsInput = z.infer<typeof GetProductsInputSchema>;
  • src/index.ts:82-94 (registration)
    Tool registration with MCP server: defines the tool name 'get-products', input schema matching GetProductsInputSchema, and async handler that calls getProducts.execute()
    server.tool(
      "get-products",
      {
        searchTitle: z.string().optional(),
        limit: z.number().default(10)
      },
      async (args) => {
        const result = await getProducts.execute(args);
        return {
          content: [{ type: "text", text: JSON.stringify(result) }]
        };
      }
    );
  • Tool object definition containing name, description, schema reference, and initialize method for GraphQL client setup
    const getProducts = {
      name: "get-products",
      description: "Get all products or search by title",
      schema: GetProductsInputSchema,
    
      // Add initialize method to set up the GraphQL client
      initialize(client: GraphQLClient) {
        shopifyClient = client;
      },
Behavior1/5

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

Tool has no description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness1/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Tool has no description.

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

Completeness1/5

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

Tool has no description.

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

Parameters1/5

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

Tool has no description.

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

Purpose1/5

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

Tool has no description.

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?

Tool has no description.

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/anass319/shopify-MCP'

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