Skip to main content
Glama
boldcommerce

Magento 2 MCP Server

by boldcommerce

update_product_attribute

Modify product attributes like name, price, or description by SKU to maintain accurate catalog information in Magento 2 stores.

Instructions

Update a specific attribute of a product by SKU

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
skuYesThe SKU (Stock Keeping Unit) of the product
attribute_codeYesThe code of the attribute to update (e.g., name, price, description, status, etc.)
valueNoThe new value for the attribute

Implementation Reference

  • The handler function that implements the core logic for updating a product attribute. It validates the product exists, handles both custom and standard attributes, makes a PUT request to the Magento /products/{sku} endpoint, and returns formatted success/error response.
    async ({ sku, attribute_code, value }) => {
      try {
        // First, check if the product exists
        const productData = await callMagentoApi(`/products/${sku}`).catch(() => null);
        
        if (!productData) {
          return {
            content: [
              {
                type: "text",
                text: `Product with SKU '${sku}' not found`
              }
            ],
            isError: true
          };
        }
        
        // Prepare the update data with the correct structure
        // Magento 2 API requires a "product" wrapper object
        let updateData = {
          product: {}
        };
        
        // Determine if this is a standard attribute or custom attribute
        const isCustomAttribute = productData.custom_attributes && 
                                 productData.custom_attributes.some(attr => attr.attribute_code === attribute_code);
        
        if (isCustomAttribute) {
          // For custom attributes, we need to use the custom_attributes array
          updateData.product.custom_attributes = [
            {
              attribute_code,
              value
            }
          ];
        } else {
          // For standard attributes, we set them directly on the product object
          updateData.product[attribute_code] = value;
        }
        
        // Make the API call to update the product
        const result = await callMagentoApi(`/products/${sku}`, 'PUT', updateData);
        
        return {
          content: [
            {
              type: "text",
              text: `Successfully updated '${attribute_code}' for product with SKU '${sku}'. Updated product: ${JSON.stringify(formatProduct(result), null, 2)}`
            }
          ]
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error updating product attribute: ${error.response?.data?.message || error.message}`
            }
          ],
          isError: true
        };
      }
    }
  • Zod schema defining the input parameters for the tool: sku (string), attribute_code (string), and value (any type).
    {
      sku: z.string().describe("The SKU (Stock Keeping Unit) of the product"),
      attribute_code: z.string().describe("The code of the attribute to update (e.g., name, price, description, status, etc.)"),
      value: z.any().describe("The new value for the attribute")
    },
  • mcp-server.js:777-848 (registration)
    Registers the 'update_product_attribute' tool with the MCP server, including name, description, input schema, and handler function.
    server.tool(
      "update_product_attribute",
      "Update a specific attribute of a product by SKU",
      {
        sku: z.string().describe("The SKU (Stock Keeping Unit) of the product"),
        attribute_code: z.string().describe("The code of the attribute to update (e.g., name, price, description, status, etc.)"),
        value: z.any().describe("The new value for the attribute")
      },
      async ({ sku, attribute_code, value }) => {
        try {
          // First, check if the product exists
          const productData = await callMagentoApi(`/products/${sku}`).catch(() => null);
          
          if (!productData) {
            return {
              content: [
                {
                  type: "text",
                  text: `Product with SKU '${sku}' not found`
                }
              ],
              isError: true
            };
          }
          
          // Prepare the update data with the correct structure
          // Magento 2 API requires a "product" wrapper object
          let updateData = {
            product: {}
          };
          
          // Determine if this is a standard attribute or custom attribute
          const isCustomAttribute = productData.custom_attributes && 
                                   productData.custom_attributes.some(attr => attr.attribute_code === attribute_code);
          
          if (isCustomAttribute) {
            // For custom attributes, we need to use the custom_attributes array
            updateData.product.custom_attributes = [
              {
                attribute_code,
                value
              }
            ];
          } else {
            // For standard attributes, we set them directly on the product object
            updateData.product[attribute_code] = value;
          }
          
          // Make the API call to update the product
          const result = await callMagentoApi(`/products/${sku}`, 'PUT', updateData);
          
          return {
            content: [
              {
                type: "text",
                text: `Successfully updated '${attribute_code}' for product with SKU '${sku}'. Updated product: ${JSON.stringify(formatProduct(result), null, 2)}`
              }
            ]
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error updating product attribute: ${error.response?.data?.message || error.message}`
              }
            ],
            isError: true
          };
        }
      }
    );
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. While 'Update' implies a mutation operation, the description doesn't disclose critical behavioral traits such as whether this requires specific permissions, whether changes are reversible, what happens if the SKU doesn't exist, or any rate limits. For a mutation tool with zero annotation coverage, this represents a significant gap in transparency.

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 any unnecessary words. It's appropriately sized and front-loaded, with every word earning its place. This represents optimal conciseness for a basic tool description.

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 that this is a mutation tool with no annotations, no output schema, and multiple sibling tools, the description is incomplete. It doesn't address behavioral aspects like error conditions, authentication requirements, or how it differs from other product-related tools. The description provides only the basic purpose without the contextual information needed for an agent to use it effectively in a broader system.

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 all three parameters (sku, attribute_code, value) having clear descriptions in the schema. The description adds no additional semantic information beyond what's already documented in the schema. According to the scoring rules, when schema coverage is high (>80%), the baseline score is 3 even without parameter information in the description.

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 action ('Update') and resource ('a specific attribute of a product by SKU'), making the purpose immediately understandable. However, it doesn't differentiate this tool from potential sibling tools that might also modify product data, such as if there were a 'bulk_update_product_attributes' tool. The description is specific but lacks sibling differentiation.

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. With sibling tools like 'get_product_by_sku' and 'search_products', there's no indication whether this tool should be used for single attribute updates versus broader modifications, or what prerequisites might exist (e.g., authentication needs, product existence). The description simply states what it does without contextual usage information.

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