cancel_run
Stop a coding-agent execution in progress by providing its run ID. This tool halts ongoing external coding tasks managed by the Orchestration MCP server.
Instructions
Cancel a running external coding-agent run.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| run_id | Yes |
Implementation Reference
- src/core/run-manager.ts:223-258 (handler)The core handler implementation for cancel_run. Validates the run exists and is active, calls the adapter's cancel method, persists a status_changed event, and returns the cancellation result.
async cancelRun(input: CancelRunInput): Promise<CancelRunResult> { const managed = this.findManagedRun(input.run_id); if (!managed) { const existing = await this.storage.readRunRecordById(input.run_id); if (!existing) { throw new Error(`Unknown run_id: ${input.run_id}`); } throw new Error(`run is not active in this process: ${existing.status}`); } if (isTerminalStatus(managed.record.status)) { throw new Error(`run is already terminal: ${managed.record.status}`); } await managed.adapter.cancel(managed.handle); const cancelledAt = new Date().toISOString(); const event = this.prepareEvent(managed, { seq: 0, ts: cancelledAt, run_id: '', session_id: managed.record.sessionId, backend: managed.record.backend, type: 'status_changed', data: { status: 'cancelled', }, }); managed.record.result = managed.handle.getResult(); await this.persistEvent(managed, event); return { run_id: managed.record.runId, status: managed.record.status, cancelled_at: cancelledAt, }; } - src/tools/cancel-run.ts:11-28 (registration)Registration function that binds the 'cancel_run' tool name to its handler. Defines the tool description, input/output schemas, and wraps the manager.cancelRun call with error handling.
export function registerCancelRunTool(server: McpServer, manager: RunManager): void { server.registerTool( 'cancel_run', { description: 'Cancel a running external coding-agent run.', inputSchema: cancelRunSchema, outputSchema: cancelRunResultSchema, }, async (args) => { try { const result = await manager.cancelRun(args); return asToolResult(result); } catch (error) { return asToolError(String(error)); } }, ); } - src/core/schemas.ts:140-142 (schema)Input validation schema for cancel_run, requiring a non-empty run_id string.
export const cancelRunSchema = z.object({ run_id: z.string().min(1), }); - src/core/schemas.ts:233-237 (schema)Output validation schema for cancel_run result, containing run_id, status, and cancelled_at timestamp.
export const cancelRunResultSchema = z.object({ run_id: z.string(), status: runStatusSchema, cancelled_at: z.string(), }); - src/core/types.ts:206-214 (schema)TypeScript type definitions for cancel_run input and output structures.
export interface CancelRunInput { run_id: string; } export interface CancelRunResult { run_id: string; status: RunStatus; cancelled_at: string; }