approve_command
Approve pending macOS terminal commands for execution through the Mac Shell MCP Server's security whitelisting system.
Instructions
Approve a pending command
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| commandId | Yes | ID of the command to approve |
Implementation Reference
- src/index.ts:441-476 (handler)The handler function for the 'approve_command' tool. It validates the input using Zod, calls the CommandService to approve and execute the command, and returns a formatted response with stdout and stderr.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:186-195 (schema)JSON schema defining the input parameters for the 'approve_command' tool, requiring a 'commandId' string.inputSchema: { type: 'object', properties: { commandId: { type: 'string', description: 'ID of the command to approve', }, }, required: ['commandId'], },
- src/index.ts:236-237 (registration)Registration and dispatch for the 'approve_command' tool in the switch statement of the CallToolRequest handler.case 'approve_command': return await this.handleApproveCommand(args);
- Helper method in CommandService that approves a pending command by executing it with execFileAsync, emitting events, and resolving the associated 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.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; } }