Skip to main content
Glama

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
NameRequiredDescriptionDefault
device_idYesNinjaOne device ID
job_typeNoFilter by job type (e.g., SCRIPT, PATCH_INSTALL, CONDITION_ACTION)

Implementation Reference

  • 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,
        );
      }
    },
  • 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)",
        ),
    },
  • 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,
          );
        }
      },
    );
  • 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);
    }

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/fredriksknese/mcp-ninjaone'

If you have feedback or need assistance with the MCP directory API, please join our Discord server