Skip to main content
Glama
boldcommerce

Magento 2 MCP Server

by boldcommerce

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
NameRequiredDescriptionDefault
skuYesThe SKU (Stock Keeping Unit) of the product

Implementation Reference

  • 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 }; } }
  • 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 }; } } );

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