Skip to main content
Glama
elgentos

Magento 2 Development MCP Server

by elgentos

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
NameRequiredDescriptionDefault
scopeNoThe scope to get DI preferences forglobal

Implementation Reference

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

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/elgentos/magento2-dev-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server