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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
run_idYes
statusYes
cancelled_atYes

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;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action ('cancel') but doesn't explain what cancellation entails (e.g., whether it's reversible, if it stops processes immediately, what permissions are required, or any side effects like resource cleanup). For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence that directly states the tool's purpose without unnecessary words. It's front-loaded with the key action and target, making it efficient and easy to parse. Every word earns its place, with no redundancy or fluff.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (a mutation with one parameter) and the presence of an output schema (which handles return values), the description is minimally adequate. However, with no annotations and low schema coverage, it lacks details on behavioral aspects like side effects or error conditions. It meets the basic requirement but leaves gaps in understanding the tool's full context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has one parameter ('run_id') with 0% description coverage, meaning the schema provides no semantic details. The description doesn't add any information about this parameter (e.g., what a 'run_id' is, how to obtain it, or format examples). However, with only one parameter, the baseline is higher; the description implies the parameter identifies the run to cancel but doesn't compensate for the lack of schema details.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('cancel') and the target ('a running external coding-agent run'), which is specific and unambiguous. It distinguishes from siblings like 'continue_run' or 'get_run' by focusing on termination rather than continuation or retrieval. However, it doesn't explicitly differentiate from all siblings (e.g., 'spawn_run' is about creation, but this isn't stated).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., that the run must be active), exclusions (e.g., not for completed runs), or comparisons to siblings like 'continue_run' for ongoing runs or 'list_runs' for status checks. This leaves the agent to infer usage context from the tool name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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