get-di-preferences
Retrieve dependency injection preferences for Magento 2 to understand how classes are mapped and overridden across different application scopes.
Instructions
Get Magento 2 dependency injection preferences list using magerun2
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| scope | No | The scope to get DI preferences for | global |
Implementation Reference
- src/index.ts:117-139 (handler)The inline anonymous async function that serves as the tool handler. It constructs and executes the magerun2 command for listing DI preferences in the specified scope, handles JSON output, counts entries, and returns formatted text content or an error response.async ({ scope = "global" }) => { const command = `magerun2 dev:di:preferences:list --format=json ${scope}`; const result = await executeMagerun2Command(command, true); if (!result.success) { return { content: [{ type: "text", text: result.error }], isError: true }; } const preferenceCount = Array.isArray(result.data) ? result.data.length : Object.keys(result.data).length; return { content: [{ type: "text", text: `Found ${preferenceCount} DI preferences for scope '${scope}':\n\n${JSON.stringify(result.data, null, 2)}` }] }; }
- src/index.ts:101-115 (schema)The inputSchema object defining the tool's parameters using Zod schema validation. Includes an optional 'scope' enum with common Magento DI scopes, defaulting to 'global'.inputSchema: { scope: z.enum([ "global", "adminhtml", "frontend", "crontab", "webapi_rest", "webapi_soap", "graphql", "doc", "admin" ]) .default("global") .describe("The scope to get DI preferences for") }
- src/index.ts:96-140 (registration)The server.registerTool call that registers the 'get-di-preferences' tool with the MCP server, specifying the tool name, metadata (title, description), input schema, and inline handler function.server.registerTool( "get-di-preferences", { title: "Get DI Preferences List", description: "Get Magento 2 dependency injection preferences list using magerun2", inputSchema: { scope: z.enum([ "global", "adminhtml", "frontend", "crontab", "webapi_rest", "webapi_soap", "graphql", "doc", "admin" ]) .default("global") .describe("The scope to get DI preferences for") } }, async ({ scope = "global" }) => { const command = `magerun2 dev:di:preferences:list --format=json ${scope}`; const result = await executeMagerun2Command(command, true); if (!result.success) { return { content: [{ type: "text", text: result.error }], isError: true }; } const preferenceCount = Array.isArray(result.data) ? result.data.length : Object.keys(result.data).length; return { content: [{ type: "text", text: `Found ${preferenceCount} DI preferences for scope '${scope}':\n\n${JSON.stringify(result.data, null, 2)}` }] }; } );