Skip to main content
Glama
run-as-root

Warden Magento MCP Server

by run-as-root

warden_run_unit_tests

Execute PHPUnit unit tests in Warden-managed Magento 2 environments to validate code functionality and ensure reliability.

Instructions

Run unit tests using PHPUnit in the php-fpm container

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_pathYesPath to the project directory
config_fileNoPHPUnit configuration file (auto-detects phpunit.xml.dist or phpunit.xml)
test_pathNoOptional path to specific test file or directory
extra_argsNoAdditional PHPUnit arguments

Implementation Reference

  • The handler function for 'warden_run_unit_tests' that runs PHPUnit unit tests inside the Warden php-fpm container, auto-detecting config files and handling arguments.
      async runUnitTests(args) {
        const {
          project_path,
          config_file = "",
          test_path = "",
          extra_args = [],
        } = args;
    
        // Determine which config file to use
        let actualConfigFile = config_file;
        if (!actualConfigFile) {
          const normalizedProjectPath = project_path.replace(/\/+$/, "");
          const absoluteProjectPath = resolve(normalizedProjectPath);
    
          // Check for phpunit.xml.dist first, then fallback to phpunit.xml
          const phpunitDistPath = join(absoluteProjectPath, "phpunit.xml.dist");
          const phpunitPath = join(absoluteProjectPath, "phpunit.xml");
    
          if (existsSync(phpunitDistPath)) {
            actualConfigFile = "phpunit.xml.dist";
          } else if (existsSync(phpunitPath)) {
            actualConfigFile = "phpunit.xml";
          } else {
            throw new Error(
              "No PHPUnit configuration file found (phpunit.xml.dist or phpunit.xml)",
            );
          }
        }
    
        const wardenCommand = [
          "env",
          "exec",
          "-T",
          "php-fpm",
          "php",
          "vendor/phpunit/phpunit/phpunit",
          "-c",
          actualConfigFile,
        ];
    
        if (test_path && test_path.trim() !== "") {
          wardenCommand.push(test_path);
        }
    
        wardenCommand.push(...extra_args);
    
        const commandStr = `warden ${wardenCommand.join(" ")}`;
        const normalizedProjectPath = project_path.replace(/\/+$/, "");
        const absoluteProjectPath = resolve(normalizedProjectPath);
    
        const debugInfo = `
    Debug Information:
    - Project Path: ${absoluteProjectPath}
    - Config File Used: ${actualConfigFile}
    - Test Path: ${test_path || "(all tests)"}
    - Extra Args: ${extra_args.length > 0 ? extra_args.join(" ") : "(none)"}
    - Full Command: ${commandStr}
    `;
    
        try {
          const result = await this.executeCommand(
            "warden",
            wardenCommand,
            absoluteProjectPath,
          );
    
          const isSuccess = result.code === 0;
    
          return {
            content: [
              {
                type: "text",
                text: `Running PHPUnit tests with config: ${actualConfigFile} ${isSuccess ? "completed successfully" : "failed"}!\n${debugInfo}\nExit Code: ${result.code}\n\nOutput:\n${result.stdout || "(no output)"}\n\nErrors:\n${result.stderr || "(no errors)"}`,
              },
            ],
            isError: !isSuccess,
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Failed to execute PHPUnit tests:\n${debugInfo}\nError: ${error.message}\n\nOutput:\n${error.stdout || "(no output)"}\n\nErrors:\n${error.stderr || "(no errors)"}`,
              },
            ],
            isError: true,
          };
        }
      }
  • The input schema definition for the 'warden_run_unit_tests' tool, specifying parameters like project_path, config_file, test_path, and extra_args.
    {
      name: "warden_run_unit_tests",
      description:
        "Run unit tests using PHPUnit in the php-fpm container",
      inputSchema: {
        type: "object",
        properties: {
          project_path: {
            type: "string",
            description: "Path to the project directory",
          },
          config_file: {
            type: "string",
            description:
              "PHPUnit configuration file (auto-detects phpunit.xml.dist or phpunit.xml)",
            default: "",
          },
          test_path: {
            type: "string",
            description:
              "Optional path to specific test file or directory",
            default: "",
          },
          extra_args: {
            type: "array",
            description: "Additional PHPUnit arguments",
            items: {
              type: "string",
            },
            default: [],
          },
        },
        required: ["project_path"],
      },
    },
  • server.js:337-338 (registration)
    Registration and dispatch of the 'warden_run_unit_tests' tool in the CallToolRequestSchema handler switch statement.
    case "warden_run_unit_tests":
      return await this.runUnitTests(request.params.arguments);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the execution environment ('php-fpm container') but omits critical details such as whether this requires a running project, potential side effects (e.g., test output or database interactions), error handling, or runtime constraints. This is inadequate for a tool that likely involves system-level operations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, direct sentence with no wasted words. It front-loads the core action and specifies the technology and environment efficiently, making it easy to parse and understand at a glance.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of running unit tests in a containerized environment, no annotations, and no output schema, the description is insufficient. It fails to address behavioral aspects like execution context, output format, error conditions, or dependencies on other tools (e.g., warden_start_project), leaving significant gaps for an AI agent to operate effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the input schema fully documents all parameters. The description adds no additional semantic context beyond implying PHPUnit usage, which is already covered by the tool's purpose. This meets the baseline for high schema coverage but doesn't enhance parameter understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Run unit tests') and the technology used ('using PHPUnit in the php-fpm container'), which is specific and actionable. However, it doesn't explicitly differentiate from sibling tools like warden_php_script or warden_magento_cli, which could also involve PHP execution in similar contexts, leaving some ambiguity about when this tool is uniquely appropriate.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. The description lacks context about prerequisites (e.g., needing a running project or specific setup), exclusions (e.g., not for integration tests), or comparisons to siblings like warden_php_script for general PHP execution. This leaves the agent without clear direction for tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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