ninja_get_device_windows_services
Retrieve Windows services and their current status for a specified device. Filter by service name or state to narrow results.
Instructions
Get Windows services and their current status for a device.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Device ID | |
| name | No | Filter by service name | |
| state | No | Filter by state (RUNNING, STOPPED, PAUSED, etc.) |
Implementation Reference
- src/tools/devices.ts:276-278 (handler)Handler function that extracts 'id' from args and passes remaining params (name, state) as query parameters to GET /device/{id}/windows-services, using the clean() helper to remove empty/null values.
handler: async ({ id, ...params }, client: NinjaOneClient) => client.get(`/device/${id}/windows-services`, clean(params)), }, - src/tools/devices.ts:263-274 (schema)Tool definition and input schema for 'ninja_get_device_windows_services'. Requires 'id' (number) and accepts optional 'name' (string) and 'state' (string) filters.
tool: { name: 'ninja_get_device_windows_services', description: 'Get Windows services and their current status for a device.', inputSchema: { type: 'object', required: ['id'], properties: { id: { type: 'number', description: 'Device ID' }, name: { type: 'string', description: 'Filter by service name' }, state: { type: 'string', description: 'Filter by state (RUNNING, STOPPED, PAUSED, etc.)' }, }, }, - src/tools/index.ts:13-24 (registration)The tool is registered in the ALL_TOOLS array by spreading deviceTools (which includes ninja_get_device_windows_services). This array is used in src/index.ts to build the toolMap and list tools.
export const ALL_TOOLS = [ ...deviceTools, ...organizationTools, ...alertTools, ...activityTools, ...ticketingTools, ...queryTools, ...policyTools, ...userTools, ...backupTools, ...systemTools, ]; - src/index.ts:23-60 (registration)The MCP server registers all tools from ALL_TOOLS into a toolMap (line 24) and handles ListToolsRequestSchema / CallToolRequestSchema to serve and execute tools respectively.
const ninjaClient = new NinjaOneClient(NINJA_BASE_URL, NINJA_CLIENT_ID, NINJA_CLIENT_SECRET); const toolMap = new Map(ALL_TOOLS.map((def) => [def.tool.name, def.handler])); const server = new Server( { name: 'ninjaone-mcp', version: '1.0.0' }, { capabilities: { tools: {} } }, ); server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: ALL_TOOLS.map((def) => def.tool), })); server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; const handler = toolMap.get(name); if (!handler) { return { content: [{ type: 'text', text: `Unknown tool: ${name}` }], isError: true, }; } try { const result = await handler( (args ?? {}) as Record<string, unknown>, ninjaClient, ); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; } catch (err) { return { content: [{ type: 'text', text: err instanceof Error ? err.message : String(err) }], isError: true, }; } }); - src/utils.ts:1-6 (helper)The clean() utility function filters out null/empty values from the optional query parameters (name, state) before passing them to the API call.
// eslint-disable-next-line @typescript-eslint/no-explicit-any export function clean(args: Record<string, any>): Record<string, unknown> { return Object.fromEntries( Object.entries(args).filter(([, v]) => v != null && v !== ''), ); }