Skip to main content
Glama
cfdude

Super Shell MCP Server

approve_command

Authorize pending shell commands for execution across Windows, macOS, and Linux systems. This security tool enables controlled command approval through a whitelisting mechanism.

Instructions

Approve a pending command

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandIdYesID of the command to approve

Implementation Reference

  • Main handler for the 'approve_command' MCP tool. Parses commandId argument, calls CommandService.approveCommand, handles the result or error, and returns formatted MCP response.
    private async handleApproveCommand(args: any) {
      const schema = z.object({
        commandId: z.string(),
      });
    
      logger.debug(`handleApproveCommand called with args: ${JSON.stringify(args)}`);
    
      const { commandId } = schema.parse(args);
    
      // Log the approval attempt
      logger.debug(`[Approval Attempt] ID: ${commandId}`);
    
      // Check if the command exists in our local pending approvals map
      const localPending = this.pendingApprovals.has(commandId);
      logger.debug(`Command found in local pendingApprovals: ${localPending ? 'yes' : 'no'}`);
    
      // Check if the command exists in the CommandService's pending queue
      const pendingCommands = this.commandService.getPendingCommands();
      logger.debug(`CommandService pending commands: ${pendingCommands.length}`);
      const pendingCommand = pendingCommands.find(cmd => cmd.id === commandId);
      logger.debug(`Command found in CommandService pending queue: ${pendingCommand ? 'yes' : 'no'}`);
      
      if (pendingCommand) {
        logger.debug(`Pending command details: ${JSON.stringify({
          id: pendingCommand.id,
          command: pendingCommand.command,
          args: pendingCommand.args,
          requestedAt: pendingCommand.requestedAt
        })}`);
      }
    
      try {
        logger.debug(`Calling CommandService.approveCommand with ID: ${commandId}`);
        // Use the CommandService's approveCommand method directly
        const result = await this.commandService.approveCommand(commandId);
        
        logger.debug(`[Command Approved] ID: ${commandId}, Output length: ${result.stdout.length}`);
        logger.debug(`Command output: ${result.stdout.substring(0, 100)}${result.stdout.length > 100 ? '...' : ''}`);
        
        return {
          content: [
            {
              type: 'text',
              text: `Command approved and executed successfully.\nOutput: ${result.stdout}`,
            },
            {
              type: 'text',
              text: result.stderr ? `Error output: ${result.stderr}` : '',
            },
          ],
        };
      } catch (error) {
        logger.error(`[Approval Error] ID: ${commandId}, Error: ${error instanceof Error ? error.message : 'Unknown error'}`);
        
        if (error instanceof Error) {
          return {
            content: [
              {
                type: 'text',
                text: `Command approval failed: ${error.message}`,
              },
            ],
            isError: true,
          };
        }
        throw error;
      }
    }
  • src/index.ts:242-255 (registration)
    MCP tool registration in the ListTools handler response. Defines name, description, and input schema for 'approve_command'.
    {
      name: 'approve_command',
      description: 'Approve a pending command',
      inputSchema: {
        type: 'object',
        properties: {
          commandId: {
            type: 'string',
            description: 'ID of the command to approve',
          },
        },
        required: ['commandId'],
      },
    },
  • Zod schema for input validation in the handler.
    const schema = z.object({
      commandId: z.string(),
    });
  • Core logic for approving and executing a pending command. Retrieves pending command, executes it via execFileAsync, emits events, and resolves/rejects the promise.
    public async approveCommand(commandId: string): Promise<CommandResult> {
      const pendingCommand = this.pendingCommands.get(commandId);
      if (!pendingCommand) {
        throw new Error(`No pending command with ID: ${commandId}`);
      }
    
      try {
        const { stdout, stderr } = await execFileAsync(
          pendingCommand.command,
          pendingCommand.args,
          { shell: this.useShell ? this.shell : false }
        );
    
        // Remove from pending queue
        this.pendingCommands.delete(commandId);
        
        // Emit event for approved command
        this.emit('command:approved', { commandId, stdout, stderr });
        
        // Resolve the original promise
        pendingCommand.resolve({ stdout, stderr });
        
        return { stdout, stderr };
      } catch (error) {
        // Remove from pending queue
        this.pendingCommands.delete(commandId);
        
        // Emit event for failed command
        this.emit('command:failed', { commandId, error });
        
        if (error instanceof Error) {
          // Reject the original promise
          pendingCommand.reject(error);
          throw error;
        }
        
        const genericError = new Error('Command execution failed');
        pendingCommand.reject(genericError);
        throw genericError;
      }
    }

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/cfdude/super-shell-mcp'

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