get_service_info
Retrieve Windows service information, including detailed status for specific services or query all services, to monitor and manage system processes.
Instructions
Retrieve information about Windows services. Can query all services or get detailed status of a specific service.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | No | Action to perform | query |
| serviceName | No | Service name to get info about (optional) |
Implementation Reference
- index.ts:333-392 (handler)The handler function for the 'get_service_info' tool. It checks if the platform is Windows, constructs a PowerShell command based on the 'action' ('query' or 'status') and optional 'serviceName', executes it using executeCommand, and returns the stdout or an error.async ({ action, serviceName }) => { if (!isWindows) { return { content: [ { type: "text", text: "The service info tool is only available on Windows. Current platform: " + platform(), }, ], }; } try { let cmd = "powershell.exe -Command \""; if (action === "query") { if (serviceName) { cmd += "Get-Service -Name '" + serviceName + "' | Format-List Name, DisplayName, Status, StartType, Description"; } else { cmd += "Get-Service | Select-Object Name, DisplayName, Status, StartType | Format-Table -AutoSize | Out-String"; } } else if (action === "status" && serviceName) { cmd += "Get-Service -Name '" + serviceName + "' | Format-List *; " + "Get-CimInstance -ClassName Win32_Service -Filter \"Name='" + serviceName + "'\" | Format-List *"; } else { return { isError: true, content: [ { type: "text", text: "For 'status' action, serviceName parameter is required", }, ], }; } cmd += "\""; const stdout = executeCommand(cmd); return { content: [ { type: "text", text: stdout.toString(), }, ], }; } catch (error) { return { isError: true, content: [ { type: "text", text: `Error retrieving service info: ${error}`, }, ], }; } }
- index.ts:329-332 (schema)Input schema for the 'get_service_info' tool using Zod validation: 'action' enum (query/status, default query) and optional 'serviceName' string.{ action: z.enum(["query", "status"]).default("query").describe("Action to perform"), serviceName: z.string().optional().describe("Service name to get info about (optional)"), },
- index.ts:326-393 (registration)Registration of the 'get_service_info' tool on the MCP server, including name, description, input schema, and handler function.server.tool( "get_service_info", "Retrieve information about Windows services. Can query all services or get detailed status of a specific service.", { action: z.enum(["query", "status"]).default("query").describe("Action to perform"), serviceName: z.string().optional().describe("Service name to get info about (optional)"), }, async ({ action, serviceName }) => { if (!isWindows) { return { content: [ { type: "text", text: "The service info tool is only available on Windows. Current platform: " + platform(), }, ], }; } try { let cmd = "powershell.exe -Command \""; if (action === "query") { if (serviceName) { cmd += "Get-Service -Name '" + serviceName + "' | Format-List Name, DisplayName, Status, StartType, Description"; } else { cmd += "Get-Service | Select-Object Name, DisplayName, Status, StartType | Format-Table -AutoSize | Out-String"; } } else if (action === "status" && serviceName) { cmd += "Get-Service -Name '" + serviceName + "' | Format-List *; " + "Get-CimInstance -ClassName Win32_Service -Filter \"Name='" + serviceName + "'\" | Format-List *"; } else { return { isError: true, content: [ { type: "text", text: "For 'status' action, serviceName parameter is required", }, ], }; } cmd += "\""; const stdout = executeCommand(cmd); return { content: [ { type: "text", text: stdout.toString(), }, ], }; } catch (error) { return { isError: true, content: [ { type: "text", text: `Error retrieving service info: ${error}`, }, ], }; } } );