dev-module-observer-list
List all Magento 2 module observers to identify event handlers and their configurations. Filter by specific events to analyze observer behavior and dependencies in your development environment.
Instructions
List all Magento 2 module observers
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| event | No | Filter by specific event name | |
| format | No | Output format | table |
Implementation Reference
- src/index.ts:452-481 (handler)The handler function that constructs and executes the magerun2 dev:module:observer:list command, handles JSON parsing if needed, and returns formatted output or error.async ({ format = "table", event }) => { let command = `magerun2 dev:module:observer:list --format=${format}`; if (event) { command += ` "${event}"`; } const result = await executeMagerun2Command(command, format === "json"); if (!result.success) { return { content: [{ type: "text", text: result.error }], isError: true }; } const responseText = format === "json" ? `Observer list (${format} format):\n\n${JSON.stringify(result.data, null, 2)}` : `Observer list (${format} format):\n\n${result.data}`; return { content: [{ type: "text", text: responseText }] }; }
- src/index.ts:443-450 (schema)Zod input schema for the tool, defining output format and optional event filter.inputSchema: { format: z.enum(["table", "json", "csv"]) .default("table") .describe("Output format"), event: z.string() .optional() .describe("Filter by specific event name") }
- src/index.ts:438-482 (registration)MCP server tool registration call for 'dev-module-observer-list', including title, description, schema, and inline handler.server.registerTool( "dev-module-observer-list", { title: "Module Observer List", description: "List all Magento 2 module observers", inputSchema: { format: z.enum(["table", "json", "csv"]) .default("table") .describe("Output format"), event: z.string() .optional() .describe("Filter by specific event name") } }, async ({ format = "table", event }) => { let command = `magerun2 dev:module:observer:list --format=${format}`; if (event) { command += ` "${event}"`; } const result = await executeMagerun2Command(command, format === "json"); if (!result.success) { return { content: [{ type: "text", text: result.error }], isError: true }; } const responseText = format === "json" ? `Observer list (${format} format):\n\n${JSON.stringify(result.data, null, 2)}` : `Observer list (${format} format):\n\n${result.data}`; return { content: [{ type: "text", text: responseText }] }; } );
- src/index.ts:28-88 (helper)Shared helper function for executing magerun2 CLI commands with timeout, JSON parsing option, Magento-specific error detection, and consistent response format.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 }; } }