approve_command
Approve pending macOS terminal commands securely in the Mac Shell MCP Server by specifying the command ID. Ensures controlled execution with built-in security measures.
Instructions
Approve a pending command
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| commandId | Yes | ID 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:439-476 (handler)MCP tool handler for approve_command: validates args with Zod schema, delegates to commandService.approveCommand, formats and returns success/error response with stdout/stderr.* Handle approve_command tool */ private async handleApproveCommand(args: unknown) { const schema = z.object({ commandId: z.string(), }); const { commandId } = schema.parse(args); try { const result = await this.commandService.approveCommand(commandId); return { content: [ { type: 'text', text: `Command approved and executed successfully.\nOutput: ${result.stdout}`, }, { type: 'text', text: result.stderr ? `Error output: ${result.stderr}` : '', }, ], }; } catch (error) { if (error instanceof Error) { return { content: [ { type: 'text', text: `Command approval failed: ${error.message}`, }, ], isError: true, }; } throw error; }
- src/index.ts:184-195 (schema)Input schema definition for approve_command tool in MCP listTools response.name: 'approve_command', description: 'Approve a pending command', inputSchema: { type: 'object', properties: { commandId: { type: 'string', description: 'ID of the command to approve', }, }, required: ['commandId'], },
- src/index.ts:236-237 (registration)Dispatch registration in callToolRequestSchema handler switch statement mapping 'approve_command' to its handler.case 'approve_command': return await this.handleApproveCommand(args);
- Core helper method in CommandService that executes the approved pending command using execFileAsync, handles events and promise resolution/rejection.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.shell, }); // 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; } }