Skip to main content
Glama
boldcommerce

Magento 2 MCP Server

by boldcommerce

get_product_by_sku

Retrieve detailed product information from a Magento 2 store using the product's SKU identifier for inventory management, order processing, or catalog updates.

Instructions

Get detailed information about a product by its SKU

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
skuYesThe SKU (Stock Keeping Unit) of the product

Implementation Reference

  • The handler function fetches the product data from Magento API using the provided SKU, formats it with formatProduct helper, and returns the JSON stringified response or an error message.
    async ({ sku }) => {
      try {
        const productData = await callMagentoApi(`/products/${sku}`);
        const formattedProduct = formatProduct(productData);
        
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(formattedProduct, null, 2)
            }
          ]
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error fetching product: ${error.message}`
            }
          ],
          isError: true
        };
      }
    }
  • Zod schema defining the input parameter 'sku' as a required string.
    {
      sku: z.string().describe("The SKU (Stock Keeping Unit) of the product")
    },
  • mcp-server.js:383-414 (registration)
    Registration of the 'get_product_by_sku' tool using McpServer's tool method, specifying name, description, input schema, and inline handler function.
    server.tool(
      "get_product_by_sku",
      "Get detailed information about a product by its SKU",
      {
        sku: z.string().describe("The SKU (Stock Keeping Unit) of the product")
      },
      async ({ sku }) => {
        try {
          const productData = await callMagentoApi(`/products/${sku}`);
          const formattedProduct = formatProduct(productData);
          
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(formattedProduct, null, 2)
              }
            ]
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error fetching product: ${error.message}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • Supporting helper function that formats raw product data from Magento API into a clean, readable object, extracting custom attributes.
    function formatProduct(product) {
      if (!product) return "Product not found";
      
      // Extract custom attributes into a more readable format
      const customAttributes = {};
      if (product.custom_attributes && Array.isArray(product.custom_attributes)) {
        product.custom_attributes.forEach(attr => {
          customAttributes[attr.attribute_code] = attr.value;
        });
      }
      
      return {
        id: product.id,
        sku: product.sku,
        name: product.name,
        price: product.price,
        status: product.status,
        visibility: product.visibility,
        type_id: product.type_id,
        created_at: product.created_at,
        updated_at: product.updated_at,
        extension_attributes: product.extension_attributes,
        custom_attributes: customAttributes
      };
    }
  • Core utility helper for making authenticated API requests to the Magento 2 REST API using axios, handling errors and SSL bypass for development.
    async function callMagentoApi(endpoint, method = 'GET', data = null) {
      try {
        const url = `${MAGENTO_BASE_URL}${endpoint}`;
        const headers = {
          'Authorization': `Bearer ${MAGENTO_API_TOKEN}`,
          'Content-Type': 'application/json'
        };
        
        const config = {
          method,
          url,
          headers,
          data: data ? JSON.stringify(data) : undefined,
          // Bypass SSL certificate verification for development
          httpsAgent: new (require('https').Agent)({
            rejectUnauthorized: false
          })
        };
        
        const response = await axios(config);
        return response.data;
      } catch (error) {
        console.error('Magento API Error:', error.response?.data || error.message);
        throw error;
      }
    }
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 states the tool retrieves 'detailed information' but doesn't specify what that includes, whether it's a read-only operation, error handling for invalid SKUs, or performance characteristics. This is a significant gap for a tool with no annotation coverage.

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 directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, with every part contributing to clarity.

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 (simple lookup), lack of annotations, and no output schema, the description is incomplete. It doesn't explain what 'detailed information' includes, how errors are handled, or the return format. For a tool with no structured output documentation, this leaves significant gaps.

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?

The schema description coverage is 100%, with the single parameter 'sku' fully documented in the schema. The description adds minimal value by mentioning 'SKU' in context, but doesn't provide additional semantics beyond what the schema already states. Baseline 3 is appropriate when schema does the heavy lifting.

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 with a specific verb ('Get') and resource ('detailed information about a product'), and identifies the key input ('by its SKU'). It distinguishes from some siblings like 'get_product_by_id' by specifying the lookup method, though it doesn't explicitly differentiate from all similar tools like 'get_product_attributes'.

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 'get_product_by_id', 'get_product_attributes', or 'search_products', nor does it specify prerequisites like needing a valid SKU. Usage is implied but not explicitly stated.

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