Skip to main content
Glama

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:

  1. Via Composer (recommended): composer require woocommerce/qit-cli --dev

  2. Set QIT_CLI_PATH environment variable: export QIT_CLI_PATH=/path/to/qit

  3. Ensure 'qit' is available in your system PATH

For more information, visit: https://github.com/woocommerce/qit-cli

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYesCommand to execute inside the container
env_idNoEnvironment ID. If not provided, uses the most recent environment.

Implementation Reference

  • 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 });
    },
  • 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."
        ),
    }),
  • 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);

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/woocommerce/qit-mcp'

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