Skip to main content
Glama
boldcommerce

Magento 2 MCP Server

by boldcommerce

advanced_product_search

Search Magento 2 products using specific fields and values with customizable filters, sorting, and pagination options.

Instructions

Search for products with advanced filtering options

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fieldYesField to search on (e.g., name, sku, price, status)
valueYesValue to search for
condition_typeNoCondition type (eq, like, gt, lt, etc.). Default: eq
page_sizeNoNumber of results per page (default: 10)
current_pageNoPage number (default: 1)
sort_fieldNoField to sort by (default: entity_id)
sort_directionNoSort direction (ASC or DESC, default: DESC)

Implementation Reference

  • The handler function for 'advanced_product_search' tool. It constructs search criteria for the Magento products API based on the provided field, value, condition, pagination, and sorting parameters, fetches the data, formats the results, and returns them in MCP format. Handles errors appropriately.
    async ({ field, value, condition_type = 'eq', page_size = 10, current_page = 1, sort_field = 'entity_id', sort_direction = 'DESC' }) => {
      try {
        // Build search criteria
        const searchCriteria = `searchCriteria[filter_groups][0][filters][0][field]=${encodeURIComponent(field)}&` +
                              `searchCriteria[filter_groups][0][filters][0][value]=${encodeURIComponent(value)}&` +
                              `searchCriteria[filter_groups][0][filters][0][condition_type]=${encodeURIComponent(condition_type)}&` +
                              `searchCriteria[pageSize]=${page_size}&` +
                              `searchCriteria[currentPage]=${current_page}&` +
                              `searchCriteria[sortOrders][0][field]=${encodeURIComponent(sort_field)}&` +
                              `searchCriteria[sortOrders][0][direction]=${encodeURIComponent(sort_direction)}`;
        
        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 performing advanced search: ${error.message}`
            }
          ],
          isError: true
        };
      }
    }
  • Zod schema defining the input parameters for the advanced_product_search tool, including field, value, condition_type, pagination, and sorting options.
    {
      field: z.string().describe("Field to search on (e.g., name, sku, price, status)"),
      value: z.string().describe("Value to search for"),
      condition_type: z.string().optional().describe("Condition type (eq, like, gt, lt, etc.). Default: eq"),
      page_size: z.number().optional().describe("Number of results per page (default: 10)"),
      current_page: z.number().optional().describe("Page number (default: 1)"),
      sort_field: z.string().optional().describe("Field to sort by (default: entity_id)"),
      sort_direction: z.string().optional().describe("Sort direction (ASC or DESC, default: DESC)")
    },
  • mcp-server.js:728-774 (registration)
    The registration of the 'advanced_product_search' tool using server.tool(), including name, description, input schema, and handler function.
    server.tool(
      "advanced_product_search",
      "Search for products with advanced filtering options",
      {
        field: z.string().describe("Field to search on (e.g., name, sku, price, status)"),
        value: z.string().describe("Value to search for"),
        condition_type: z.string().optional().describe("Condition type (eq, like, gt, lt, etc.). Default: eq"),
        page_size: z.number().optional().describe("Number of results per page (default: 10)"),
        current_page: z.number().optional().describe("Page number (default: 1)"),
        sort_field: z.string().optional().describe("Field to sort by (default: entity_id)"),
        sort_direction: z.string().optional().describe("Sort direction (ASC or DESC, default: DESC)")
      },
      async ({ field, value, condition_type = 'eq', page_size = 10, current_page = 1, sort_field = 'entity_id', sort_direction = 'DESC' }) => {
        try {
          // Build search criteria
          const searchCriteria = `searchCriteria[filter_groups][0][filters][0][field]=${encodeURIComponent(field)}&` +
                                `searchCriteria[filter_groups][0][filters][0][value]=${encodeURIComponent(value)}&` +
                                `searchCriteria[filter_groups][0][filters][0][condition_type]=${encodeURIComponent(condition_type)}&` +
                                `searchCriteria[pageSize]=${page_size}&` +
                                `searchCriteria[currentPage]=${current_page}&` +
                                `searchCriteria[sortOrders][0][field]=${encodeURIComponent(sort_field)}&` +
                                `searchCriteria[sortOrders][0][direction]=${encodeURIComponent(sort_direction)}`;
          
          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 performing advanced search: ${error.message}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • Helper function used by the handler to format the raw Magento API search results into a structured, readable output with key product fields.
    // Format search results for better readability
    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?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'advanced filtering options' but doesn't specify what makes them advanced (e.g., multiple filters, complex conditions). It doesn't describe pagination behavior, rate limits, authentication needs, or what happens when no results are found. For a search tool with 7 parameters, this is inadequate.

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 a single, efficient sentence that front-loads the core purpose. There's zero waste or redundancy—every word earns its place by conveying essential information about the tool's functionality.

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 (7 parameters, no annotations, no output schema), the description is incomplete. It doesn't explain return values, error conditions, or behavioral nuances like pagination limits. For an 'advanced' search tool, more context is needed to guide effective use beyond what the schema provides.

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 7 parameters thoroughly. The description adds no additional meaning beyond implying 'advanced filtering' (which the schema details with fields like 'condition_type'). Baseline 3 is appropriate when the schema does the heavy lifting, though the description doesn't compensate with higher-level context.

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 as 'Search for products with advanced filtering options', which includes a specific verb ('search') and resource ('products'). It distinguishes itself from the simpler 'search_products' sibling by emphasizing 'advanced filtering options', though it doesn't explicitly contrast with all siblings like 'get_product_by_id' or 'get_product_by_sku'.

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 when to prefer this over 'search_products' (which likely has basic filtering) or when to use simpler lookup tools like 'get_product_by_id' or 'get_product_by_sku'. There's no context about use cases or exclusions.

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