Skip to main content
Glama

Super Shell MCP Server

approve_command

Authorize pending shell commands in the Super Shell MCP Server by providing a command ID to ensure secure execution across Windows, macOS, and Linux systems.

Instructions

Approve a pending command

Input Schema

NameRequiredDescriptionDefault
commandIdYesID of the command to approve

Input Schema (JSON Schema)

{ "properties": { "commandId": { "description": "ID of the command to approve", "type": "string" } }, "required": [ "commandId" ], "type": "object" }

Implementation Reference

  • src/index.ts:242-255 (registration)
    Registration of the 'approve_command' tool in the list of available tools, including its JSON schema for input validation.
    { name: 'approve_command', description: 'Approve a pending command', inputSchema: { type: 'object', properties: { commandId: { type: 'string', description: 'ID of the command to approve', }, }, required: ['commandId'], }, },
  • Main handler function for processing 'approve_command' tool calls. Validates input with Zod, delegates to CommandService.approveCommand, handles logging and response formatting.
    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; } }
  • Dispatch case in the tool call switch statement that routes 'approve_command' calls to the handler.
    case 'approve_command': return await this.handleApproveCommand(args); case 'deny_command': return await this.handleDenyCommand(args);
  • Core implementation in CommandService that approves and executes a pending command by looking it up from the queue, running execFileAsync, cleaning up the queue, emitting events, and resolving 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; } }

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

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