get_categories
Retrieve top-level product categories from MercadoLibre to organize searches, filter listings, and navigate the marketplace efficiently.
Instructions
List all top-level categories for a MercadoLibre site.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| site_id | No | Site ID (default: MLA) |
Implementation Reference
- src/actions.ts:41-47 (handler)The core handler function that executes the get_categories tool logic. It takes an optional GetCategoriesParams object, defaults to site_id 'MLA' (Argentina), and makes an API call to fetch categories for the specified MercadoLibre site.
export async function getCategories( client: MercadoLibreClient, params?: GetCategoriesParams ): Promise<unknown> { const siteId = params?.site_id ?? "MLA"; return client.get(`/sites/${encodeURIComponent(siteId)}/categories`); } - src/schemas.ts:19-21 (schema)TypeScript interface defining the input parameters for get_categories. It accepts an optional site_id parameter to specify which MercadoLibre site to query (defaults to MLA for Argentina).
export interface GetCategoriesParams { site_id?: string; } - src/mcp-server.ts:70-85 (registration)MCP server registration of the get_categories tool. Defines the tool name, description, Zod schema for validation (site_id optional), and the async handler that calls tools.get_categories() and formats the response.
server.tool( "get_categories", "List all top-level categories for a MercadoLibre site.", { site_id: z.string().optional().describe("Site ID (default: MLA)"), }, async (params) => { try { const result = await tools.get_categories(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:31-31 (helper)Wrapper function that creates the get_categories tool interface, binding the MercadoLibre client instance to the getCategories handler function.
get_categories: (params?: GetCategoriesParams) => getCategories(client, params),