exec_in_environment
Execute commands within a QIT test environment's PHP container to run tests, manage environments, or debug WordPress/WooCommerce plugins.
Instructions
Execute a command inside a running QIT test environment's PHP container.
⚠️ QIT CLI not detected. QIT CLI not found. Please install it using one of these methods:
Via Composer (recommended): composer require woocommerce/qit-cli --dev
Set QIT_CLI_PATH environment variable: export QIT_CLI_PATH=/path/to/qit
Ensure 'qit' is available in your system PATH
For more information, visit: https://github.com/woocommerce/qit-cli
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | Command to execute inside the container | |
| env_id | No | Environment ID. If not provided, uses the most recent environment. |
Implementation Reference
- src/tools/environment.ts:277-287 (handler)The core handler function for the 'exec_in_environment' tool. It builds the QIT CLI command 'env:exec' with optional --env flag and the provided command, then executes it using executeAndFormat with a 5-minute timeout.handler: async (args: { command: string; env_id?: string }) => { const cmdArgs = ["env:exec"]; if (args.env_id) { cmdArgs.push("--env", args.env_id); } cmdArgs.push("--", args.command); return executeAndFormat(cmdArgs, { timeout: 300000 }); },
- src/tools/environment.ts:268-276 (schema)Zod input schema for the tool, requiring a 'command' string and optionally an 'env_id' string.inputSchema: z.object({ command: z.string().describe("Command to execute inside the container"), env_id: z .string() .optional() .describe( "Environment ID. If not provided, uses the most recent environment." ), }),
- src/tools/index.ts:10-19 (registration)Registration of environmentTools (containing exec_in_environment) into the aggregated allTools object exported for use by the MCP server.export const allTools = { ...authTools, ...testExecutionTools, ...testResultsTools, ...groupsTools, ...environmentTools, ...packagesTools, ...configTools, ...utilitiesTools, };
- src/server.ts:29-38 (registration)MCP ListTools handler converts allTools (including exec_in_environment) into the protocol's tool list format with name, description, and JSON schema.const tools = Object.entries(allTools).map(([_, tool]) => ({ name: tool.name, description: cliInfo ? tool.description : `${tool.description}\n\n⚠️ QIT CLI not detected. ${getQitCliNotFoundError()}`, inputSchema: zodToJsonSchema(tool.inputSchema), })); return { tools }; });
- src/server.ts:44-64 (registration)In MCP CallTool handler, retrieves the tool handler from allTools by name and invokes it with validated arguments. This is the entry point for executing exec_in_environment.const tool = allTools[name as ToolName]; if (!tool) { return { content: [ { type: "text", text: `Unknown tool: ${name}`, }, ], isError: true, }; } try { // Validate input const validatedArgs = tool.inputSchema.parse(args); // Execute tool // eslint-disable-next-line @typescript-eslint/no-explicit-any const result = await (tool.handler as (args: any) => Promise<{ content: string; isError: boolean }>)(validatedArgs);