Skip to main content
Glama

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, }; } }

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