Skip to main content
Glama
run-as-root

Warden Magento MCP Server

by run-as-root

warden_composer

Execute Composer commands within the php-fpm container of a Warden-managed Magento 2 environment to manage dependencies and packages.

Instructions

Run Composer commands inside the php-fpm container

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_pathYesPath to the project directory
commandYesComposer command to execute (e.g., 'install', 'update', 'require symfony/console', 'require-commerce')

Implementation Reference

  • Main handler function for 'warden_composer' tool. Executes Composer commands inside the Warden php-fpm container. Checks for composer2 or composer availability and version (requires v2), parses command arguments, runs via 'warden env exec', and returns structured output with success status.
    async runComposer(args) {
      const { project_path, command } = args;
    
      if (!project_path) {
        throw new Error("project_path is required");
      }
    
      if (!command) {
        throw new Error("command is required");
      }
    
      const normalizedProjectPath = project_path.replace(/\/+$/, "");
      const absoluteProjectPath = resolve(normalizedProjectPath);
    
      if (!existsSync(absoluteProjectPath)) {
        throw new Error(
          `Project directory does not exist: ${absoluteProjectPath}`,
        );
      }
    
      try {
        // First, check if composer2 is available
        const composer2CheckResult = await this.executeCommand(
          "warden",
          ["env", "exec", "-T", "php-fpm", "which", "composer2"],
          absoluteProjectPath,
        );
    
        let composerCommand = "composer2";
    
        if (composer2CheckResult.code !== 0) {
          // composer2 not available, check for composer
          const composerCheckResult = await this.executeCommand(
            "warden",
            ["env", "exec", "-T", "php-fpm", "which", "composer"],
            absoluteProjectPath,
          );
    
          if (composerCheckResult.code !== 0) {
            return {
              content: [
                {
                  type: "text",
                  text: `Composer not found!\n\nNeither 'composer2' nor 'composer' commands are available in the php-fpm container.\n\nPlease install Composer version 2 in your container.`,
                },
              ],
              isError: true,
            };
          }
    
          // Check composer version
          const versionCheckResult = await this.executeCommand(
            "warden",
            ["env", "exec", "-T", "php-fpm", "composer", "--version"],
            absoluteProjectPath,
          );
    
          if (versionCheckResult.code !== 0) {
            return {
              content: [
                {
                  type: "text",
                  text: `Failed to check Composer version!\n\nCommand: composer --version\nError: ${versionCheckResult.stderr}`,
                },
              ],
              isError: true,
            };
          }
    
          // Check if it's version 2
          const versionOutput = versionCheckResult.stdout.toLowerCase();
          if (!versionOutput.includes("composer version 2")) {
            return {
              content: [
                {
                  type: "text",
                  text: `Composer version 2 is required!\n\nFound: ${versionCheckResult.stdout.trim()}\n\nPlease install or upgrade to Composer version 2.`,
                },
              ],
              isError: true,
            };
          }
    
          composerCommand = "composer";
        }
    
        // Parse the command string to handle arguments properly
        const commandParts = command.trim().split(/\s+/);
        const wardenCommand = [
          "env",
          "exec",
          "-T",
          "php-fpm",
          composerCommand,
          ...commandParts,
        ];
    
        const result = await this.executeCommand(
          "warden",
          wardenCommand,
          absoluteProjectPath,
        );
    
        const commandStr = `${composerCommand} ${command}`;
        const isSuccess = result.code === 0;
    
        return {
          content: [
            {
              type: "text",
              text: `Composer command ${isSuccess ? "completed successfully" : "failed"}!\n\nCommand: ${commandStr}\nWorking directory: ${absoluteProjectPath}\nExit Code: ${result.code}\n\nOutput:\n${result.stdout || "(no output)"}\n\nErrors:\n${result.stderr || "(no errors)"}`,
            },
          ],
          isError: !isSuccess,
        };
      } catch (error) {
        const commandStr = `composer ${command}`;
        return {
          content: [
            {
              type: "text",
              text: `Failed to execute Composer command:\n\nCommand: ${commandStr}\nWorking directory: ${absoluteProjectPath}\nError: ${error.message}\n\nOutput:\n${error.stdout || "(no output)"}\n\nErrors:\n${error.stderr || "(no errors)"}`,
            },
          ],
          isError: true,
        };
      }
    }
  • Input schema definition for the 'warden_composer' tool, specifying required parameters: project_path and command.
    {
      name: "warden_composer",
      description: "Run Composer commands inside the php-fpm container",
      inputSchema: {
        type: "object",
        properties: {
          project_path: {
            type: "string",
            description: "Path to the project directory",
          },
          command: {
            type: "string",
            description:
              "Composer command to execute (e.g., 'install', 'update', 'require symfony/console', 'require-commerce')",
          },
        },
        required: ["project_path", "command"],
      },
    },
  • server.js:339-340 (registration)
    Registration of the 'warden_composer' tool handler in the CallToolRequestSchema switch statement, dispatching to runComposer method.
    case "warden_composer":
      return await this.runComposer(request.params.arguments);

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/run-as-root/warden-mcp-server'

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