cancel_print_job
Cancel specific print jobs by ID or stop all pending print jobs for a printer. Manage print queues to remove unwanted documents before they print.
Instructions
Cancel a specific print job by job ID or cancel all jobs for a printer.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cancel_all | No | Cancel all jobs for the specified printer | |
| job_id | No | Job ID to cancel (get from get_print_queue) | |
| printer | No | Printer name (required if canceling all jobs) |
Implementation Reference
- src/tools/batch-helpers.ts:420-457 (handler)Core handler function that executes the lprm command to cancel a specific print job by ID or all jobs for a printer.export async function handleCancel(spec: JobCancelSpec): Promise<CancelJobResult> { const { job_id, printer, cancel_all = false } = spec // Determine the action description for consistent messaging const actionDescription = cancel_all ? `all jobs for printer: ${printer}` : `job: ${job_id}` try { const lprmArgs: string[] = [] if (cancel_all && printer) { lprmArgs.push("-P", printer, "-") } else if (job_id) { if (printer) { lprmArgs.push("-P", printer) } lprmArgs.push(job_id) } else { return { success: false, message: "Invalid parameters", error: "Must provide either job_id or set cancel_all=true with printer", } } await execa("lprm", lprmArgs) return { success: true, message: `Cancelled ${actionDescription}`, } } catch (error) { const message = error instanceof Error ? error.message : String(error) return { success: false, message: `Failed to cancel ${actionDescription}`, error: message, } }
- src/tools/printer.ts:180-196 (handler)The registered tool handler: orchestrates batch cancellation by checking size limits, calling handleCancel for each job, and formatting results.async ({ jobs }) => { // Check for large batch size const batchSizeWarning = checkBatchSizeLimit(jobs.length, "jobs") if (batchSizeWarning) { return batchSizeWarning } // Process each cancellation in the batch const results: CancelJobResult[] = [] for (const jobSpec of jobs) { const result = await handleCancel(jobSpec) results.push(result) } return formatCancelResults(results) } )
- src/tools/printer.ts:158-178 (schema)Zod input schema defining an array of job cancellation specs with job_id (optional), printer (optional), and cancel_all (default false).inputSchema: { jobs: z .array( z.object({ job_id: z .string() .optional() .describe("Job ID to cancel (get from get_print_queue)"), printer: z .string() .optional() .describe("Printer name (required if canceling all jobs)"), cancel_all: z .boolean() .optional() .default(false) .describe("Cancel all jobs for the specified printer"), }) ) .describe("Array of job cancellations (use single-element array for one job)"), },
- src/tools/printer.ts:152-197 (registration)Registers the cancel_print_job tool with the MCP server, conditionally if MCP_PRINTER_ENABLE_MANAGEMENT is true.if (config.enableManagement) { server.registerTool( "cancel_print_job", { title: "Cancel Print Job", description: "Cancel a specific print job by job ID or cancel all jobs for a printer.", inputSchema: { jobs: z .array( z.object({ job_id: z .string() .optional() .describe("Job ID to cancel (get from get_print_queue)"), printer: z .string() .optional() .describe("Printer name (required if canceling all jobs)"), cancel_all: z .boolean() .optional() .default(false) .describe("Cancel all jobs for the specified printer"), }) ) .describe("Array of job cancellations (use single-element array for one job)"), }, }, async ({ jobs }) => { // Check for large batch size const batchSizeWarning = checkBatchSizeLimit(jobs.length, "jobs") if (batchSizeWarning) { return batchSizeWarning } // Process each cancellation in the batch const results: CancelJobResult[] = [] for (const jobSpec of jobs) { const result = await handleCancel(jobSpec) results.push(result) } return formatCancelResults(results) } ) }
- src/tools/batch-helpers.ts:472-505 (helper)Helper function to format the results of multiple job cancellations into a readable text response for the MCP tool.export function formatCancelResults(results: CancelJobResult[]): { content: Array<{ type: "text"; text: string }> } { const successful = results.filter((r) => r.success) const failed = results.filter((r) => !r.success) let text = `Cancel Results: ${successful.length}/${results.length} successful` if (failed.length > 0) { text += `, ${failed.length} failed` } text += "\n\n" // Show successful cancellations for (const result of successful) { text += `✓ ${result.message}\n\n` } // Show failed cancellations for (const result of failed) { text += `✗ ${result.message}` if (result.error) { text += `: ${result.error}` } text += "\n\n" } return { content: [ { type: "text", text: text.trim(), }, ], }