confirm_command
Confirm or cancel the execution of a dangerous command in Windows Subsystem for Linux (WSL) using a secure validation system to prevent vulnerabilities and ensure safe operation.
Instructions
Confirm execution of a dangerous command
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| confirm | Yes | Whether to proceed with the command execution | |
| confirmation_id | Yes | Confirmation ID received from execute_command |
Implementation Reference
- src/index.ts:417-466 (handler)Executes the logic for confirming a pending dangerous command. Retrieves the pending confirmation from the map using the provided ID, deletes it, and either executes the command if confirmed=true or returns a cancellation message.async ({ confirmation_id, confirm }) => { try { const pending = this.pending_confirmations.get(confirmation_id); if (!pending) { throw new InvalidConfirmationError(confirmation_id); } this.pending_confirmations.delete(confirmation_id); if (!confirm) { return { content: [ { type: 'text' as const, text: 'Command execution cancelled.', }, ], }; } const result = await this.command_executor.execute_command( pending.command, pending.working_dir, pending.timeout, ); return { content: [ { type: 'text' as const, text: this.format_output(result), }, ], }; } catch (error) { return { content: [ { type: 'text' as const, text: `Error confirming command: ${ error instanceof Error ? error.message : String(error) }`, }, ], isError: true, }; } },
- src/index.ts:402-411 (schema)Input schema for the confirm_command tool using Valibot, requiring confirmation_id (string) and confirm (boolean).schema: v.object({ confirmation_id: v.pipe( v.string(), v.description('Confirmation ID'), ), confirm: v.pipe( v.boolean(), v.description('Proceed with execution'), ), }),
- src/index.ts:397-467 (registration)Full registration of the confirm_command tool on the MCP server, including name, description, schema, annotations, and the handler function.// confirm_command tool this.server.tool( { name: 'confirm_command', description: 'Confirm dangerous command execution', schema: v.object({ confirmation_id: v.pipe( v.string(), v.description('Confirmation ID'), ), confirm: v.pipe( v.boolean(), v.description('Proceed with execution'), ), }), annotations: { readOnlyHint: false, destructiveHint: true, }, }, async ({ confirmation_id, confirm }) => { try { const pending = this.pending_confirmations.get(confirmation_id); if (!pending) { throw new InvalidConfirmationError(confirmation_id); } this.pending_confirmations.delete(confirmation_id); if (!confirm) { return { content: [ { type: 'text' as const, text: 'Command execution cancelled.', }, ], }; } const result = await this.command_executor.execute_command( pending.command, pending.working_dir, pending.timeout, ); return { content: [ { type: 'text' as const, text: this.format_output(result), }, ], }; } catch (error) { return { content: [ { type: 'text' as const, text: `Error confirming command: ${ error instanceof Error ? error.message : String(error) }`, }, ], isError: true, }; } }, );