get_product_stock
Retrieve current stock levels for Magento 2 products using their SKU to manage inventory and prevent overselling.
Instructions
Get stock information for a product by SKU
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sku | Yes | The SKU (Stock Keeping Unit) of the product |
Implementation Reference
- mcp-server.js:592-615 (handler)Handler function that fetches product stock information from the Magento API endpoint `/stockItems/{sku}` using the provided SKU and returns the data as JSON or an error response.async ({ sku }) => { try { const stockData = await callMagentoApi(`/stockItems/${sku}`); return { content: [ { type: "text", text: JSON.stringify(stockData, null, 2) } ] }; } catch (error) { return { content: [ { type: "text", text: `Error fetching stock information: ${error.message}` } ], isError: true }; } }
- mcp-server.js:589-591 (schema)Input schema using Zod, defining the required 'sku' parameter as a string with description.{ sku: z.string().describe("The SKU (Stock Keeping Unit) of the product") },
- mcp-server.js:586-616 (registration)Registration of the 'get_product_stock' tool via server.tool(), specifying name, description, input schema, and handler function.server.tool( "get_product_stock", "Get stock information for a product by SKU", { sku: z.string().describe("The SKU (Stock Keeping Unit) of the product") }, async ({ sku }) => { try { const stockData = await callMagentoApi(`/stockItems/${sku}`); return { content: [ { type: "text", text: JSON.stringify(stockData, null, 2) } ] }; } catch (error) { return { content: [ { type: "text", text: `Error fetching stock information: ${error.message}` } ], isError: true }; } } );