Skip to main content
Glama

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
NameRequiredDescriptionDefault
run_idYes

Implementation Reference

  • 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,
      };
    }
  • 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));
          }
        },
      );
    }
  • Input validation schema for cancel_run, requiring a non-empty run_id string.
    export const cancelRunSchema = z.object({
      run_id: z.string().min(1),
    });
  • 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(),
    });
  • 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;
    }

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/dufangshi/orchestration-mcp'

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