config-set
Set Magento 2 system configuration values for different scopes to customize store settings, manage website configurations, and update store-specific parameters.
Instructions
Set Magento 2 system configuration values
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| encrypt | No | Encrypt the value | |
| path | Yes | Configuration path to set | |
| scope | No | Configuration scope (default, website, store) | |
| scopeId | No | Scope ID (website ID or store ID) | |
| value | Yes | Value to set |
Implementation Reference
- src/index.ts:802-835 (handler)Handler function that constructs and executes the magerun2 config:set command using the provided configuration path, value, optional scope, scopeId, and encrypt flag. Handles success and error responses appropriately.async ({ path, value, scope, scopeId, encrypt }) => { let command = `magerun2 config:set "${path}" "${value}"`; if (scope) { command += ` --scope="${scope}"`; } if (scopeId) { command += ` --scope-id="${scopeId}"`; } if (encrypt) { command += ` --encrypt`; } const result = await executeMagerun2Command(command); if (!result.success) { return { content: [{ type: "text", text: result.error }], isError: true }; } return { content: [{ type: "text", text: `Configuration set successfully:\n\n${result.data}` }] }; }
- src/index.ts:787-800 (schema)Zod input schema defining the parameters for the config-set tool: path (required string), value (required string), scope (optional string), scopeId (optional string), encrypt (optional boolean).path: z.string() .describe("Configuration path to set"), value: z.string() .describe("Value to set"), scope: z.string() .optional() .describe("Configuration scope (default, website, store)"), scopeId: z.string() .optional() .describe("Scope ID (website ID or store ID)"), encrypt: z.boolean() .optional() .describe("Encrypt the value") }
- src/index.ts:781-836 (registration)Full server.registerTool registration for the 'config-set' tool, including name, schema/spec, and inline handler function.server.registerTool( "config-set", { title: "Config Set", description: "Set Magento 2 system configuration values", inputSchema: { path: z.string() .describe("Configuration path to set"), value: z.string() .describe("Value to set"), scope: z.string() .optional() .describe("Configuration scope (default, website, store)"), scopeId: z.string() .optional() .describe("Scope ID (website ID or store ID)"), encrypt: z.boolean() .optional() .describe("Encrypt the value") } }, async ({ path, value, scope, scopeId, encrypt }) => { let command = `magerun2 config:set "${path}" "${value}"`; if (scope) { command += ` --scope="${scope}"`; } if (scopeId) { command += ` --scope-id="${scopeId}"`; } if (encrypt) { command += ` --encrypt`; } const result = await executeMagerun2Command(command); if (!result.success) { return { content: [{ type: "text", text: result.error }], isError: true }; } return { content: [{ type: "text", text: `Configuration set successfully:\n\n${result.data}` }] }; } );
- src/index.ts:28-88 (helper)Shared helper function executeMagerun2Command that wraps child_process.exec for running magerun2 commands, handles timeouts, stderr logging, optional JSON parsing, and provides Magento-specific error messages.async function executeMagerun2Command(command: string, parseJson: boolean = false): Promise<{ success: true; data: any; rawOutput: string; } | { success: false; error: string; isError: true; }> { try { const { stdout, stderr } = await execAsync(command, { cwd: process.cwd(), timeout: 30000 // 30 second timeout }); if (stderr && stderr.trim()) { console.error("magerun2 stderr:", stderr); } if (parseJson) { try { return { success: true, data: JSON.parse(stdout), rawOutput: stdout }; } catch (parseError) { return { success: false, error: `Error parsing magerun2 JSON output: ${parseError}\n\nRaw output:\n${stdout}`, isError: true }; } } return { success: true, data: stdout.trim(), rawOutput: stdout }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); // Check if magerun2 is not found if (errorMessage.includes("command not found") || errorMessage.includes("not recognized")) { return { success: false, error: "Error: magerun2 command not found. Please ensure n98-magerun2 is installed and available in your PATH.\n\nInstallation instructions: https://github.com/netz98/n98-magerun2", isError: true }; } // Check if not in Magento directory if (errorMessage.includes("not a Magento installation") || errorMessage.includes("app/etc/env.php")) { return { success: false, error: "Error: Current directory does not appear to be a Magento 2 installation. Please run this command from your Magento 2 root directory.", isError: true }; } return { success: false, error: `Error executing magerun2 command: ${errorMessage}`, isError: true }; } }