service_manager
Manage Windows services by listing, starting, stopping, restarting, and monitoring service status. Retrieve details, filter by status or startup type, and find specific services using search terms.
Instructions
Windows service management including listing services, getting service details, starting/stopping services, and monitoring service status
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | The service management action to perform | |
| limit | No | Limit number of results (default: 50) | |
| search_term | No | Search term for finding services | |
| service_name | No | Service name for specific service operations | |
| startup_type_filter | No | Filter services by startup type (default: all) | all |
| status_filter | No | Filter services by status (default: all) | all |
Implementation Reference
- src/tools/service.ts:46-86 (handler)The main handler function 'run' for the 'service_manager' tool. It processes input arguments, dispatches to specific helper methods based on the 'action' parameter, and handles errors.async run(args: { action: string; service_name?: string; status_filter?: string; startup_type_filter?: string; search_term?: string; limit?: number; }) { try { switch (args.action) { case "list_services": return await this.listServices(args.status_filter, args.startup_type_filter, args.limit); case "get_service_details": return await this.getServiceDetails(args.service_name!); case "start_service": return await this.startService(args.service_name!); case "stop_service": return await this.stopService(args.service_name!); case "restart_service": return await this.restartService(args.service_name!); case "get_service_status": return await this.getServiceStatus(args.service_name!); case "find_service": return await this.findService(args.search_term!); case "get_running_services": return await this.getRunningServices(args.limit); case "get_startup_services": return await this.getStartupServices(args.limit); default: throw new Error(`Unknown action: ${args.action}`); } } catch (error: any) { return { content: [{ type: "text", text: `❌ Service management operation failed: ${error.message}` }], isError: true }; } },
- src/tools/service.ts:9-44 (schema)Input schema (parameters) for the 'service_manager' tool, defining the expected arguments including required 'action' and optional filters.parameters: { type: "object", properties: { action: { type: "string", enum: ["list_services", "get_service_details", "start_service", "stop_service", "restart_service", "get_service_status", "find_service", "get_running_services", "get_startup_services"], description: "The service management action to perform" }, service_name: { type: "string", description: "Service name for specific service operations" }, status_filter: { type: "string", enum: ["running", "stopped", "paused", "all"], description: "Filter services by status (default: all)", default: "all" }, startup_type_filter: { type: "string", enum: ["automatic", "manual", "disabled", "all"], description: "Filter services by startup type (default: all)", default: "all" }, search_term: { type: "string", description: "Search term for finding services" }, limit: { type: "number", description: "Limit number of results (default: 50)", default: 50 } }, required: ["action"] },
- src/index.ts:47-51 (registration)Registration of the 'service_manager' tool in the MCP server's ListToolsRequestSchema handler, providing name, description, and input schema.{ name: serviceManagerTool.name, description: serviceManagerTool.description, inputSchema: serviceManagerTool.parameters },
- src/index.ts:79-80 (registration)Dispatch/execution case for the 'service_manager' tool in the MCP server's CallToolRequestSchema handler.case "service_manager": return await serviceManagerTool.run(args as any);
- src/tools/service.ts:88-118 (helper)Helper method 'listServices' used by the handler for listing Windows services with optional status, startup type filters, and limit.async listServices(statusFilter = "all", startupTypeFilter = "all", limit = 50) { try { let whereClause = ""; const conditions: string[] = []; if (statusFilter !== "all") { conditions.push(`$_.Status -eq '${this.mapStatusFilter(statusFilter)}'`); } if (startupTypeFilter !== "all") { conditions.push(`$_.StartType -eq '${this.mapStartupTypeFilter(startupTypeFilter)}'`); } if (conditions.length > 0) { whereClause = `| Where-Object {${conditions.join(' -and ')}}`; } const command = `Get-Service ${whereClause} | Select-Object -First ${limit} Name, DisplayName, Status, StartType | Sort-Object DisplayName | Format-Table -AutoSize`; const { stdout } = await execAsync(`powershell -Command "${command}"`); return { content: [{ type: "text", text: `# Windows Services\n\nStatus Filter: ${statusFilter}\nStartup Type Filter: ${startupTypeFilter}\nLimit: ${limit}\n\n\`\`\`\n${stdout}\n\`\`\`` }] }; } catch (error: any) { throw new Error(`Failed to list services: ${error.message}`); } },