Skip to main content
Glama
jakenuts

mcp-cli-exec MCP Server

by jakenuts

cli-exec

Execute multiple CLI commands in a specified working directory with optional timeouts. Detailed results include stdout, stderr, exit code, and execution duration for each command.

Instructions

Execute one or more CLI commands in a specific working directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandsYesCommands to execute
timeoutNoOptional timeout in milliseconds per command (default: 5 minutes)
workingDirectoryYesWorking directory to execute commands in

Implementation Reference

  • src/server.ts:66-100 (registration)
    Registration of the 'cli-exec' tool with the MCP server, including name, description, and detailed input schema.
    {
      name: 'cli-exec',
      description: 'Execute one or more CLI commands in a specific working directory',
      inputSchema: {
        type: 'object',
        properties: {
          workingDirectory: {
            type: 'string',
            description: 'Working directory to execute commands in',
          },
          commands: {
            oneOf: [
              {
                type: 'string',
                description: 'Single command or && separated commands',
              },
              {
                type: 'array',
                items: {
                  type: 'string',
                },
                description: 'Array of commands to execute sequentially',
              },
            ],
            description: 'Commands to execute',
          },
          timeout: {
            type: 'number',
            description: 'Optional timeout in milliseconds per command (default: 5 minutes)',
            minimum: 0,
          },
        },
        required: ['workingDirectory', 'commands'],
      },
    },
  • MCP CallToolRequest handler implementation for 'cli-exec': validates args, parses and executes commands using CommandExecutor, formats ExecResult, handles errors.
    case 'cli-exec': {
      if (!isValidExecArgs(request.params.arguments)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Invalid execution arguments'
        );
      }
    
      try {
        const startTime = Date.now();
        const commands = this.executor.parseCommands(request.params.arguments.commands);
        const results = await this.executor.executeCommands(
          commands,
          request.params.arguments.workingDirectory,
          request.params.arguments.timeout
        );
    
        const execResult: ExecResult = {
          success: results.every((r) => r.success),
          results,
          totalDuration: Date.now() - startTime,
        };
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(execResult, null, 2),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(
                {
                  success: false,
                  results: [],
                  error: error instanceof Error ? error.message : String(error),
                  totalDuration: 0,
                },
                null,
                2
              ),
            },
          ],
          isError: true,
        };
      }
    }
  • Type guard function validating input arguments for 'cli-exec' tool against ExecArgs shape.
    export const isValidExecArgs = (args: any): args is ExecArgs =>
      typeof args === 'object' &&
      args !== null &&
      typeof args.workingDirectory === 'string' &&
      (typeof args.commands === 'string' ||
        (Array.isArray(args.commands) &&
          args.commands.every((cmd: any) => typeof cmd === 'string'))) &&
      (args.timeout === undefined || typeof args.timeout === 'number');
  • Core helper method that executes an array of CLI commands sequentially in a working directory, collects results, stops on failure.
    async executeCommands(
      commands: string[],
      workingDirectory: string,
      timeout?: number
    ): Promise<CommandResult[]> {
      const results: CommandResult[] = [];
    
      for (const command of commands) {
        const cmdStartTime = Date.now();
        try {    
          const result = await this.executeCommand(
            command,
            workingDirectory,
            timeout
          );
    
          const duration = Date.now() - cmdStartTime;
    
          results.push({
            command,
            success: result.exitCode === 0,
            exitCode: result.exitCode,
            stdout: result.stdout,
            stderr: result.stderr,
            duration,
            workingDirectory,
          });
    
          // Stop execution if a command fails
          if (result.exitCode !== 0) {
            break;
          }
        } catch (error) {
          results.push({
            command,
            success: false,
            exitCode: -1,
            stdout: '',
            stderr: '',
            error: error instanceof Error ? error.message : String(error),
            duration: Date.now() - cmdStartTime,
            workingDirectory,
          });
          break;
        }
      }
    
      return results;
    }
  • Utility to parse 'commands' input: splits string on '&&' or returns array directly.
      parseCommands(commands: string | string[]): string[] {
        return Array.isArray(commands)
          ? commands
          : commands
              .split('&&')
              .map((cmd) => cmd.trim())
              .filter(Boolean);
      }
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but only states basic functionality. It doesn't disclose critical behavioral traits like execution safety (potential for destructive commands), authentication needs, error handling, output format, or rate limits. The mention of 'timeout' in the schema isn't reinforced in the description.

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 front-loads the core purpose without unnecessary words. Every element ('Execute', 'CLI commands', 'specific working directory') earns its place, making it optimally concise.

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?

For a CLI execution tool with no annotations and no output schema, the description is insufficient. It lacks details on execution behavior (e.g., sequential vs. parallel), error propagation, security implications, or return values, leaving significant gaps for an agent to understand tool usage.

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 fully documents all parameters. The description adds no additional parameter semantics beyond what's in the schema, maintaining the baseline score of 3 for adequate coverage through structured data alone.

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 ('Execute') and resource ('CLI commands') with additional context about working directory. It distinguishes from sibling 'cli-exec-raw' by specifying 'in a specific working directory', though the distinction isn't fully explicit about what makes the sibling different.

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?

The description provides no guidance on when to use this tool versus the sibling 'cli-exec-raw'. It mentions the working directory context but doesn't explain alternative scenarios, prerequisites, or exclusions for tool selection.

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

Related 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/jakenuts/mcp-cli-exec'

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