Skip to main content
Glama
jakenuts

mcp-cli-exec MCP Server

by jakenuts

cli-exec-raw

Execute raw CLI commands and receive structured output, including stdout, stderr, exit code, and execution time, via the mcp-cli-exec MCP Server.

Instructions

Execute a raw CLI command and return structured output

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYesThe CLI command to execute
timeoutNoOptional timeout in milliseconds (default: 5 minutes)

Implementation Reference

  • Main handler logic for the cli-exec-raw tool. It validates the input, executes the raw command using the CommandExecutor, measures duration, formats the output as CommandResult, and returns it as JSON-formatted text content. Handles execution errors by returning an error-formatted result.
    case 'cli-exec-raw': {
      if (!isValidExecRawArgs(request.params.arguments)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Invalid execution arguments'
        );
      }
    
      try {
        const startTime = Date.now();
        const result = await this.executor.executeCommand(
          request.params.arguments.command,
          undefined,
          request.params.arguments.timeout
        );
        const duration = Date.now() - startTime;
    
        const formattedResult: CommandResult = {
          command: request.params.arguments.command,
          success: result.exitCode === 0,
          exitCode: result.exitCode,
          stdout: result.stdout,
          stderr: result.stderr,
          duration,
          workingDirectory: process.cwd(),
        };
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(formattedResult, null, 2),
            },
          ],
        };
      } catch (error) {
        const errorResult: CommandResult = {
          command: request.params.arguments.command,
          success: false,
          exitCode: -1,
          stdout: '',
          stderr: '',
          error: error instanceof Error ? error.message : String(error),
          duration: 0,
          workingDirectory: process.cwd(),
        };
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(errorResult, null, 2),
            },
          ],
          isError: true,
        };
      }
    }
  • src/server.ts:47-65 (registration)
    Tool registration in the ListTools response, defining the name, description, and input schema for cli-exec-raw.
    {
      name: 'cli-exec-raw',
      description: 'Execute a raw CLI command and return structured output',
      inputSchema: {
        type: 'object',
        properties: {
          command: {
            type: 'string',
            description: 'The CLI command to execute',
          },
          timeout: {
            type: 'number',
            description: 'Optional timeout in milliseconds (default: 5 minutes)',
            minimum: 0,
          },
        },
        required: ['command'],
      },
    },
  • TypeScript interface defining the input arguments for cli-exec-raw.
    export interface ExecRawArgs {
      command: string;
      timeout?: number;
    }
  • Core helper method that performs the actual CLI command execution using execa, with ANSI stripping, timeout handling, and optional cwd. Used by the cli-exec-raw handler.
    async executeCommand(
      command: string,
      cwd?: string,
      timeout?: number
    ): Promise<{ exitCode: number; stdout: string; stderr: string, cwd:string }> {
      try {
      
        const result = await execa(command, [], {
          cwd: cwd,
          shell: true,
          timeout: timeout || DEFAULT_TIMEOUT,
          reject: false,
          all: true,
        });
    
        return {
          exitCode: result.exitCode ?? -1,
          stdout: stripAnsi(result.stdout ?? ''),
          stderr: stripAnsi(result.stderr ?? ''),
          cwd:result.cwd
        };
      } catch (error) {
        if (error instanceof Error) {
          throw new Error(`Command execution failed: ${error.message}`);
        }
        throw error;
      }
    }
  • Validation function for cli-exec-raw input arguments, ensuring command is string and timeout is optional number.
    export const isValidExecRawArgs = (args: any): args is ExecRawArgs =>
      typeof args === 'object' &&
      args !== null &&
      typeof args.command === 'string' &&
      (args.timeout === undefined || typeof args.timeout === 'number');
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the tool executes commands and returns structured output, but fails to address critical behavioral aspects such as security implications, execution environment, error handling, or potential side effects. This is inadequate for a tool that executes arbitrary CLI commands.

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 extremely concise and front-loaded in a single sentence that captures the core functionality. Every word earns its place with no wasted text, making it easy for an agent to parse quickly.

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?

Given the complexity of executing arbitrary CLI commands (which involves security, environment, and side-effect considerations), no annotations, and no output schema, the description is insufficiently complete. It doesn't explain what 'structured output' means, execution constraints, or safety warnings, leaving significant gaps for agent understanding.

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%, with clear parameter descriptions in the schema. The description adds no additional parameter semantics beyond what the schema provides, such as command syntax examples or timeout behavior details. Baseline 3 is appropriate when the schema does the heavy lifting.

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 tool's purpose: 'Execute a raw CLI command and return structured output'. It specifies the verb ('execute'), resource ('raw CLI command'), and outcome ('return structured output'). However, it doesn't explicitly differentiate from its sibling 'cli-exec', which likely has similar functionality, preventing a perfect score.

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 its sibling 'cli-exec' or other alternatives. It lacks context about appropriate use cases, prerequisites, or exclusions, leaving the agent with minimal direction beyond the basic purpose.

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