Skip to main content
Glama

cancel_job

Stop an agent job by providing its unique ID. This tool allows you to terminate ongoing asynchronous tasks in the Agent Jobs system when they are no longer needed or require intervention.

Instructions

Cancels an agent job by its ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
job_idYesThe unique identifier of the job to be canceled. Example: 'job-12345'.
reasonNoAn optional reason explaining why the job is being canceled.

Implementation Reference

  • The main handler function for the 'cancel_job' tool. It extracts job_id and optional reason from params, constructs the API endpoint, makes a DELETE request via agentJobsClient, formats a summary of the canceled job, and returns a text response. Handles errors by returning an error message.
    async (params) => {
      mcpDebugger.toolCall("cancel_job", params);
    
      const { job_id, reason } = params;
      const endpoint = `/services/agent-jobs/${job_id}`;
      let requestBody: { reason: string } | undefined;
    
      if (reason) {
        requestBody = { reason };
      }
    
      mcpDebugger.debug("Job cancellation request", {
        endpoint,
        job_id,
        reason,
        hasRequestBody: !!requestBody
      });
    
      try {
        const canceledJob = await withTiming(
          () => agentJobsClient.delete(endpoint, requestBody),
          "cancel_job API call"
        );
    
        mcpDebugger.debug("Job cancellation response", { canceledJob });
    
        const summary = formatJobSummary(canceledJob);
    
        const result = {
          content: [{
            type: "text" as const,
            text: `Successfully canceled job:\n\n${summary}`,
          }]
        };
    
        mcpDebugger.toolResponse("cancel_job", {
          jobId: job_id,
          reason,
          resultLength: result.content[0].text.length
        });
    
        return result;
      } catch (error: any) {
        mcpDebugger.toolError("cancel_job", error);
    
        return {
          content: [{
            type: "text" as const,
            text: `Error canceling job: ${error.message}`,
          }],
        };
      }
    }
  • Zod-based input schema defining the parameters for the 'cancel_job' tool: required 'job_id' string and optional 'reason' string.
    inputSchema: {
      job_id: z.string({
        description: "The unique identifier of the job to be canceled. Example: 'job-12345'.",
      }),
      reason: z.string().optional().describe("An optional reason explaining why the job is being canceled."),
    }
  • Registers the 'cancel_job' tool on the MCP server with its name, description, annotations, input schema, and the handler function.
    server.registerTool(
      "cancel_job",
      {
        description: "Cancels an agent job by its ID.",
        annotations: {
          title: "Cancel Agent Job"
        },
        inputSchema: {
          job_id: z.string({
            description: "The unique identifier of the job to be canceled. Example: 'job-12345'.",
          }),
          reason: z.string().optional().describe("An optional reason explaining why the job is being canceled."),
        }
      },
      async (params) => {
        mcpDebugger.toolCall("cancel_job", params);
    
        const { job_id, reason } = params;
        const endpoint = `/services/agent-jobs/${job_id}`;
        let requestBody: { reason: string } | undefined;
    
        if (reason) {
          requestBody = { reason };
        }
    
        mcpDebugger.debug("Job cancellation request", {
          endpoint,
          job_id,
          reason,
          hasRequestBody: !!requestBody
        });
    
        try {
          const canceledJob = await withTiming(
            () => agentJobsClient.delete(endpoint, requestBody),
            "cancel_job API call"
          );
    
          mcpDebugger.debug("Job cancellation response", { canceledJob });
    
          const summary = formatJobSummary(canceledJob);
    
          const result = {
            content: [{
              type: "text" as const,
              text: `Successfully canceled job:\n\n${summary}`,
            }]
          };
    
          mcpDebugger.toolResponse("cancel_job", {
            jobId: job_id,
            reason,
            resultLength: result.content[0].text.length
          });
    
          return result;
        } catch (error: any) {
          mcpDebugger.toolError("cancel_job", error);
    
          return {
            content: [{
              type: "text" as const,
              text: `Error canceling job: ${error.message}`,
            }],
          };
        }
      }
    );
Behavior3/5

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

Annotations only provide a title, so the description carries the full burden. It states the action is to cancel a job, implying a destructive mutation, but lacks details on permissions needed, whether cancellation is reversible, rate limits, or what happens post-cancellation. It adds basic context but misses key behavioral traits.

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, efficient sentence with zero wasted words. It's front-loaded with the core action and resource, making it easy to scan and understand quickly.

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

Completeness2/5

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

For a destructive mutation tool with no annotations beyond a title and no output schema, the description is inadequate. It lacks information on permissions, side effects, error handling, or return values, leaving significant gaps in understanding the tool's behavior and 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?

Schema description coverage is 100%, with clear parameter documentation in the schema. The description doesn't add any meaning beyond what the schema provides, such as explaining parameter interactions or usage nuances. Baseline 3 is appropriate as the schema does the heavy lifting.

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 ('cancels') and target resource ('an agent job by its ID'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_job' or 'list_jobs' beyond the obvious action difference, missing specific sibling distinction.

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?

No guidance is provided on when to use this tool versus alternatives or any prerequisites. While the action 'cancels' implies it's for active jobs, there's no explicit mention of job state requirements, error conditions, or comparison with siblings like 'create_job'.

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/aiconnect-cloud/agentjobs-mcp'

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