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
| Name | Required | Description | Default |
|---|---|---|---|
| job_id | Yes | The unique identifier of the job to be canceled. Example: 'job-12345'. | |
| reason | No | An optional reason explaining why the job is being canceled. |
Implementation Reference
- src/tools/cancel_job.ts:22-74 (handler)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}`, }], }; } }
- src/tools/cancel_job.ts:15-20 (schema)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."), }
- src/tools/cancel_job.ts:8-75 (registration)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}`, }], }; } } );