get_device_jobs
Retrieve all jobs for a specific device in NinjaOne, including running, completed, and failed jobs, with optional filtering by job type.
Instructions
Get all jobs (running, completed, and failed) for a specific device.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device_id | Yes | NinjaOne device ID | |
| job_type | No | Filter by job type (e.g., SCRIPT, PATCH_INSTALL, CONDITION_ACTION) |
Implementation Reference
- src/tools/jobs.ts:68-84 (handler)The handler function that executes the get_device_jobs tool logic. It constructs API parameters and calls the NinjaOne API endpoint `/device/${device_id}/jobs` to retrieve all jobs (running, completed, and failed) for a specific device, then returns the results as JSON.
async ({ device_id, job_type }) => { const params: Record<string, string> = {}; if (job_type) params.jobType = job_type; try { const results = await client.get( `/device/${device_id}/jobs`, params, ); return toolResult(JSON.stringify(results, null, 2)); } catch (error) { return toolResult( `Error fetching device jobs: ${error}`, true, ); } }, - src/tools/jobs.ts:59-67 (schema)Zod schema definition for the get_device_jobs tool input parameters. Defines 'device_id' as a required number (NinjaOne device ID) and 'job_type' as an optional string filter (e.g., SCRIPT, PATCH_INSTALL, CONDITION_ACTION).
{ device_id: z.number().describe("NinjaOne device ID"), job_type: z .string() .optional() .describe( "Filter by job type (e.g., SCRIPT, PATCH_INSTALL, CONDITION_ACTION)", ), }, - src/tools/jobs.ts:56-85 (registration)Complete registration of the get_device_jobs tool with the MCP server using server.tool(). Includes the tool name, description, input schema, and handler function.
server.tool( "get_device_jobs", "Get all jobs (running, completed, and failed) for a specific device.", { device_id: z.number().describe("NinjaOne device ID"), job_type: z .string() .optional() .describe( "Filter by job type (e.g., SCRIPT, PATCH_INSTALL, CONDITION_ACTION)", ), }, async ({ device_id, job_type }) => { const params: Record<string, string> = {}; if (job_type) params.jobType = job_type; try { const results = await client.get( `/device/${device_id}/jobs`, params, ); return toolResult(JSON.stringify(results, null, 2)); } catch (error) { return toolResult( `Error fetching device jobs: ${error}`, true, ); } }, ); - src/ninjaone-client.ts:105-110 (helper)The NinjaOneClient.get() method used by the handler to make HTTP GET requests to the NinjaOne API. This helper method handles authentication, request construction, and response parsing.
async get( path: string, params?: Record<string, string>, ): Promise<unknown> { return this.request("GET", path, undefined, params); }