Skip to main content
Glama
boldcommerce

Magento 2 MCP Server

by boldcommerce

search_products

Search for products in a Magento 2 store using search criteria like product name or description, with pagination controls for results.

Instructions

Search for products using Magento search criteria

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query (product name, description, etc.)
page_sizeNoNumber of results per page (default: 10)
current_pageNoPage number (default: 1)

Implementation Reference

  • The main handler function for the search_products tool that constructs Magento API search criteria for product name matching, fetches results, formats them, and handles errors.
    async ({ query, page_size = 10, current_page = 1 }) => {
      try {
        // Build search criteria for a simple name search
        const searchCriteria = `searchCriteria[filter_groups][0][filters][0][field]=name&` +
                              `searchCriteria[filter_groups][0][filters][0][value]=%25${encodeURIComponent(query)}%25&` +
                              `searchCriteria[filter_groups][0][filters][0][condition_type]=like&` +
                              `searchCriteria[pageSize]=${page_size}&` +
                              `searchCriteria[currentPage]=${current_page}`;
        
        const productData = await callMagentoApi(`/products?${searchCriteria}`);
        const formattedResults = formatSearchResults(productData);
        
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(formattedResults, null, 2)
            }
          ]
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error searching products: ${error.message}`
            }
          ],
          isError: true
        };
      }
    }
  • Zod schema defining input parameters: query (required string), page_size and current_page (optional numbers).
    {
      query: z.string().describe("Search query (product name, description, etc.)"),
      page_size: z.number().optional().describe("Number of results per page (default: 10)"),
      current_page: z.number().optional().describe("Page number (default: 1)")
    },
  • mcp-server.js:417-457 (registration)
    MCP server.tool registration call that defines the tool name, description, input schema, and handler function.
    server.tool(
      "search_products",
      "Search for products using Magento search criteria",
      {
        query: z.string().describe("Search query (product name, description, etc.)"),
        page_size: z.number().optional().describe("Number of results per page (default: 10)"),
        current_page: z.number().optional().describe("Page number (default: 1)")
      },
      async ({ query, page_size = 10, current_page = 1 }) => {
        try {
          // Build search criteria for a simple name search
          const searchCriteria = `searchCriteria[filter_groups][0][filters][0][field]=name&` +
                                `searchCriteria[filter_groups][0][filters][0][value]=%25${encodeURIComponent(query)}%25&` +
                                `searchCriteria[filter_groups][0][filters][0][condition_type]=like&` +
                                `searchCriteria[pageSize]=${page_size}&` +
                                `searchCriteria[currentPage]=${current_page}`;
          
          const productData = await callMagentoApi(`/products?${searchCriteria}`);
          const formattedResults = formatSearchResults(productData);
          
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(formattedResults, null, 2)
              }
            ]
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error searching products: ${error.message}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • Helper function used by the handler to format raw Magento product search results into a simplified structure with essential fields.
    function formatSearchResults(results) {
      if (!results || !results.items || !Array.isArray(results.items)) {
        return "No products found";
      }
      
      return {
        total_count: results.total_count,
        items: results.items.map(item => ({
          id: item.id,
          sku: item.sku,
          name: item.name,
          price: item.price,
          status: item.status,
          type_id: item.type_id
        }))
      };
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the basic action without disclosing behavioral traits like pagination behavior, rate limits, authentication needs, or what 'Magento search criteria' specifically means. It lacks details on return format, error handling, or performance characteristics, which are critical for a search tool.

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

Conciseness4/5

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

The description is a single, efficient sentence with no wasted words, making it front-loaded and easy to parse. However, it could be more structured by explicitly mentioning key aspects like pagination or sibling differentiation, but it's appropriately sized for its content.

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 (search with pagination), lack of annotations, and no output schema, the description is incomplete. It doesn't explain return values, error cases, or how 'Magento search criteria' works, leaving gaps that could hinder an AI agent's ability to use the tool effectively.

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 input schema fully documents parameters (query, page_size, current_page). The description adds no additional meaning beyond implying 'Magento search criteria' might relate to the query parameter, but this is minimal. Baseline 3 is appropriate as the schema does the heavy lifting.

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 'Search for products using Magento search criteria' clearly states the action (search) and resource (products), but it's vague about scope and doesn't differentiate from sibling tools like 'advanced_product_search' or 'get_product_by_id'. It specifies the platform (Magento) but lacks detail on what 'search criteria' entails.

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 explicit guidance is provided on when to use this tool versus alternatives such as 'advanced_product_search' or 'get_product_by_id'. The description implies a general search function but doesn't clarify use cases, exclusions, or prerequisites, leaving the agent to infer usage from the tool name 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/boldcommerce/magento2-mcp'

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