Skip to main content
Glama
run-as-root

Warden Magento MCP Server

by run-as-root

warden_php_script

Execute PHP scripts within Warden-managed Magento 2 development environments to automate tasks, run custom code, and manage project operations directly from the container.

Instructions

Run a PHP script inside the php-fpm container

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_pathYesPath to the project directory
script_pathYesPath to the PHP script relative to project root
argsNoAdditional arguments to pass to the script

Implementation Reference

  • The handler function for 'warden_php_script' that runs a PHP script inside the Warden php-fpm container using 'warden env exec' command.
    async runPhpScript(args) {
      const { project_path, script_path, args: scriptArgs = [] } = args;
    
      const wardenCommand = [
        "env",
        "exec",
        "-T",
        "php-fpm",
        "php",
        script_path,
        ...scriptArgs,
      ];
    
      return await this.executeWardenCommand(
        project_path,
        wardenCommand,
        `Running PHP script: ${script_path}`,
      );
    }
  • Input schema definition for the warden_php_script tool, specifying parameters: project_path (required), script_path (required), and optional args array.
    inputSchema: {
      type: "object",
      properties: {
        project_path: {
          type: "string",
          description: "Path to the project directory",
        },
        script_path: {
          type: "string",
          description:
            "Path to the PHP script relative to project root",
        },
        args: {
          type: "array",
          description: "Additional arguments to pass to the script",
          items: {
            type: "string",
          },
          default: [],
        },
      },
      required: ["project_path", "script_path"],
    },
  • server.js:123-149 (registration)
    Tool registration in the ListTools response, defining name, description, and referencing the input schema.
    {
      name: "warden_php_script",
      description: "Run a PHP script inside the php-fpm container",
      inputSchema: {
        type: "object",
        properties: {
          project_path: {
            type: "string",
            description: "Path to the project directory",
          },
          script_path: {
            type: "string",
            description:
              "Path to the PHP script relative to project root",
          },
          args: {
            type: "array",
            description: "Additional arguments to pass to the script",
            items: {
              type: "string",
            },
            default: [],
          },
        },
        required: ["project_path", "script_path"],
      },
    },
  • server.js:333-334 (registration)
    Dispatch registration in the CallToolRequestSchema switch statement, mapping the tool name to its handler method.
    case "warden_php_script":
      return await this.runPhpScript(request.params.arguments);
  • Helper method used by the handler to execute Warden commands and format the response.
    async executeWardenCommand(project_path, wardenArgs, description) {
      if (!project_path) {
        throw new Error("project_path is required");
      }
    
      const normalizedProjectPath = project_path.replace(/\/+$/, "");
      const absoluteProjectPath = resolve(normalizedProjectPath);
    
      if (!existsSync(absoluteProjectPath)) {
        throw new Error(
          `Project directory does not exist: ${absoluteProjectPath}`,
        );
      }
    
      try {
        const result = await this.executeCommand(
          "warden",
          wardenArgs,
          absoluteProjectPath,
        );
    
        const commandStr = `warden ${wardenArgs.join(" ")}`;
        const isSuccess = result.code === 0;
    
        return {
          content: [
            {
              type: "text",
              text: `${description} ${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 = `warden ${wardenArgs.join(" ")}`;
        return {
          content: [
            {
              type: "text",
              text: `Failed to execute 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,
        };
      }
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions execution inside a container but doesn't cover critical aspects like permissions required, whether it's read-only or destructive, error handling, output format, or execution limits. For a tool that runs arbitrary code, this is a significant gap.

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, efficient sentence that directly states the tool's purpose without unnecessary words. It is appropriately sized and front-loaded, making it easy to 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 arbitrary PHP scripts in a containerized environment, the description is incomplete. With no annotations, no output schema, and minimal behavioral context, it lacks details on safety, output, errors, and integration with sibling tools, making it inadequate for informed tool selection.

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 schema already documents all parameters (project_path, script_path, args) with clear descriptions. The description adds no additional parameter semantics beyond what's in the schema, such as path format examples or script behavior details.

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 a PHP script') and the context ('inside the php-fpm container'), which distinguishes it from general PHP execution tools. However, it doesn't explicitly differentiate from siblings like warden_magento_cli or warden_run_unit_tests, which might also involve PHP execution in similar environments.

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 like warden_magento_cli (for Magento-specific commands) or warden_run_unit_tests (for testing). The description implies usage for arbitrary PHP scripts but doesn't specify prerequisites, constraints, or typical use cases.

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