Skip to main content
Glama

run_command

Execute shell commands like npm install or build in a sandboxed project environment for web development automation.

Instructions

Execute a shell command in the project sandbox (e.g. npm install, npm run build). Max timeout 5 minutes.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYesProject ID (UUID or url_id)
commandYesShell command to execute
cwdNoWorking directory (default: /home/user/project)
timeout_msNoTimeout in milliseconds (default: 120000, max: 300000)

Implementation Reference

  • The handler function for the run_command tool. It calls client.runCommand() with parameters (project_id, command, cwd, timeout_ms), formats the output showing exit code, stdout, and stderr, and handles errors.
    async (params) => {
      try {
        const result = await client.runCommand(params.project_id, {
          command: params.command,
          cwd: params.cwd,
          timeout_ms: params.timeout_ms,
        });
    
        let text = `Exit code: ${result.exit_code}`;
    
        if (result.stdout) {
          text += `\n\nSTDOUT:\n${result.stdout}`;
        }
    
        if (result.stderr) {
          text += `\n\nSTDERR:\n${result.stderr}`;
        }
    
        return { content: [{ type: 'text' as const, text }] };
      } catch (err: any) {
        return { content: [{ type: 'text' as const, text: `Error: ${err.message}` }], isError: true };
      }
    },
  • The runCommand method in AICre8Client class that makes the actual POST request to /projects/{projectId}/run endpoint with command parameters and returns exit_code, stdout, and stderr.
    async runCommand(
      projectId: string,
      params: { command: string; cwd?: string; timeout_ms?: number },
    ): Promise<{ exit_code: number; stdout: string; stderr: string }> {
      return this.request('POST', `/projects/${projectId}/run`, params);
    }
  • src/index.ts:188-189 (registration)
    Registration of the run_command tool with the MCP server using server.tool() method.
    server.tool(
      'run_command',
  • Zod schema definition for run_command tool parameters: project_id (required), command (required), cwd (optional), and timeout_ms (optional with max 300000ms).
    {
      project_id: z.string().describe('Project ID (UUID or url_id)'),
      command: z.string().describe('Shell command to execute'),
      cwd: z.string().optional().describe('Working directory (default: /home/user/project)'),
      timeout_ms: z
        .number()
        .optional()
        .describe('Timeout in milliseconds (default: 120000, max: 300000)'),
    },

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/AICre8dev/mcp-server'

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