Skip to main content
Glama

cancel_job

Cancel an agent job by specifying its unique ID and optionally provide a reason for cancellation. Ideal for managing and terminating asynchronous tasks within the Agent Jobs system.

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 destructures job_id and optional reason from params, constructs the API endpoint, optionally includes reason in request body, calls agentJobsClient.delete with timing, formats a job summary on success using formatJobSummary, logs via mcpDebugger, and returns a text content result or 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 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."), }
  • The module exports a function that registers the 'cancel_job' tool on the MCP server, providing name, description, annotations, input schema, and handler.
    export default (server: McpServer) => { 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}`, }], }; } } ); }

Other Tools

Related 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