Skip to main content
Glama
dan1d

mercadolibre-mcp

search_items

Search products on MercadoLibre marketplace using keywords, with filters for category, price range, and country-specific sites like Argentina, Brazil, or Mexico.

Instructions

Search products on MercadoLibre by keyword. Supports filtering by category, price range, and site (MLA=Argentina, MLB=Brazil, MLM=Mexico, etc.)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query
site_idNoSite ID (default: MLA). MLA=Argentina, MLB=Brazil, MLM=Mexico, MLC=Chile, MCO=Colombia
categoryNoCategory ID to filter
price_minNoMinimum price
price_maxNoMaximum price
limitNoMax results (default 10, max 50)
offsetNoPagination offset

Implementation Reference

  • The searchItems handler function that executes the search logic. It takes a client and SearchItemsParams, builds query parameters with optional filters (site_id, category, price range, limit, offset), and calls the MercadoLibre API at /sites/{siteId}/search.
    export async function searchItems(
      client: MercadoLibreClient,
      params: SearchItemsParams
    ): Promise<unknown> {
      const siteId = params.site_id ?? "MLA";
      const qp: Record<string, string> = { q: params.query };
      if (params.category) qp.category = params.category;
      if (params.price_min !== undefined) qp.price_min = String(params.price_min);
      if (params.price_max !== undefined) qp.price_max = String(params.price_max);
      qp.limit = String(Math.min(params.limit ?? 10, 50));
      if (params.offset !== undefined) qp.offset = String(params.offset);
      return client.get(`/sites/${encodeURIComponent(siteId)}/search`, qp);
    }
  • TypeScript interface defining the input parameters for search_items including required query field and optional filters (site_id, category, price_min, price_max, limit, offset).
    export interface SearchItemsParams {
      query: string;
      site_id?: string;
      category?: string;
      price_min?: number;
      price_max?: number;
      limit?: number;
      offset?: number;
    }
  • MCP tool registration for search_items with Zod schema validation. Defines the tool name, description, input schema with field descriptions, and the async handler that calls tools.search_items and returns formatted JSON results.
    server.tool(
      "search_items",
      "Search products on MercadoLibre by keyword. Supports filtering by category, price range, and site (MLA=Argentina, MLB=Brazil, MLM=Mexico, etc.)",
      {
        query: z.string().describe("Search query"),
        site_id: z.string().optional().describe("Site ID (default: MLA). MLA=Argentina, MLB=Brazil, MLM=Mexico, MLC=Chile, MCO=Colombia"),
        category: z.string().optional().describe("Category ID to filter"),
        price_min: z.number().optional().describe("Minimum price"),
        price_max: z.number().optional().describe("Maximum price"),
        limit: z.number().optional().describe("Max results (default 10, max 50)"),
        offset: z.number().optional().describe("Pagination offset"),
      },
      async (params) => {
        try {
          const result = await tools.search_items(params);
          return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
        } catch (error) {
          const message = error instanceof Error ? error.message : String(error);
          return { content: [{ type: "text", text: message }], isError: true };
        }
      },
    );
  • src/index.ts:23-37 (registration)
    Factory function that creates the MercadoLibre tools object. Line 28 wraps the searchItems handler with the client instance and exports it as search_items.
    export function createMercadoLibreTools(accessToken?: string) {
      const client = new MercadoLibreClient(accessToken);
    
      return {
        tools: {
          search_items: (params: SearchItemsParams) => searchItems(client, params),
          get_item: (params: GetItemParams) => getItem(client, params),
          get_item_description: (params: GetItemDescriptionParams) => getItemDescription(client, params),
          get_categories: (params?: GetCategoriesParams) => getCategories(client, params),
          get_category: (params: GetCategoryParams) => getCategory(client, params),
          get_seller_info: (params: GetSellerInfoParams) => getSellerInfo(client, params),
          get_trends: (params?: GetTrendsParams) => getTrends(client, params),
          get_currency_conversion: (params: GetCurrencyConversionParams) => getCurrencyConversion(client, params),
        },
      };

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/dan1d/mercadolibre-mcp'

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