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}`, }], }; } } );

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