get_system_info
Retrieve Windows system information including OS details, hardware specifications, and user data. Choose basic or full detail levels to get system insights.
Instructions
Retrieve system information including OS, hardware, and user details. Can provide basic or full details.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| detail | No | Level of detail | basic |
Implementation Reference
- index.ts:109-187 (handler)The main handler function for the 'get_system_info' tool. It constructs and executes platform-specific shell commands (PowerShell on Windows, standard Unix commands otherwise) to fetch system details like OS, CPU, memory, storage, and network info based on the 'detail' parameter ('basic' or 'full'). Returns formatted text output or error.async ({ detail }) => { try { let cmd; if (isWindows) { cmd = "powershell.exe -Command \""; if (detail === "basic") { cmd += "$OS = Get-CimInstance Win32_OperatingSystem; " + "$CS = Get-CimInstance Win32_ComputerSystem; " + "$Processor = Get-CimInstance Win32_Processor; " + "Write-Output 'OS: ' $OS.Caption $OS.Version; " + "Write-Output 'Computer: ' $CS.Manufacturer $CS.Model; " + "Write-Output 'CPU: ' $Processor.Name; " + "Write-Output 'Memory: ' [math]::Round($OS.TotalVisibleMemorySize/1MB, 2) 'GB'"; } else { cmd += "$OS = Get-CimInstance Win32_OperatingSystem; " + "$CS = Get-CimInstance Win32_ComputerSystem; " + "$Processor = Get-CimInstance Win32_Processor; " + "$Disk = Get-CimInstance Win32_LogicalDisk -Filter 'DriveType=3'; " + "$Network = Get-CimInstance Win32_NetworkAdapterConfiguration | Where-Object {$_.IPAddress -ne $null}; " + "Write-Output '=== OPERATING SYSTEM ==='; " + "Write-Output ('OS: ' + $OS.Caption + ' ' + $OS.Version); " + "Write-Output ('Architecture: ' + $OS.OSArchitecture); " + "Write-Output ('Install Date: ' + $OS.InstallDate); " + "Write-Output ('Last Boot: ' + $OS.LastBootUpTime); " + "Write-Output (''; '=== HARDWARE ==='); " + "Write-Output ('Manufacturer: ' + $CS.Manufacturer); " + "Write-Output ('Model: ' + $CS.Model); " + "Write-Output ('Serial Number: ' + (Get-CimInstance Win32_BIOS).SerialNumber); " + "Write-Output ('Processor: ' + $Processor.Name); " + "Write-Output ('Cores: ' + $Processor.NumberOfCores); " + "Write-Output ('Logical Processors: ' + $Processor.NumberOfLogicalProcessors); " + "Write-Output ('Memory: ' + [math]::Round($OS.TotalVisibleMemorySize/1MB, 2) + ' GB'); " + "Write-Output (''; '=== STORAGE ==='); " + "foreach($drive in $Disk) { " + "Write-Output ('Drive ' + $drive.DeviceID + ' - ' + [math]::Round($drive.Size/1GB, 2) + ' GB (Free: ' + [math]::Round($drive.FreeSpace/1GB, 2) + ' GB)') " + "}; " + "Write-Output (''; '=== NETWORK ==='); " + "foreach($adapter in $Network) { " + "Write-Output ('Adapter: ' + $adapter.Description); " + "Write-Output (' IP Address: ' + ($adapter.IPAddress[0])); " + "Write-Output (' MAC Address: ' + $adapter.MACAddress); " + "Write-Output (' Gateway: ' + ($adapter.DefaultIPGateway -join ', ')); " + "}"; } cmd += "\""; } else { // Fallback for Unix systems if (detail === "basic") { cmd = "uname -a && lscpu | grep 'Model name' && free -h | head -n 2"; } else { cmd = "uname -a && lscpu && free -h && df -h && ip addr"; } } const stdout = executeCommand(cmd); return { content: [ { type: "text", text: stdout.toString(), }, ], }; } catch (error) { return { isError: true, content: [ { type: "text", text: `Error retrieving system info: ${error}`, }, ], }; } }
- index.ts:107-108 (schema)Zod schema defining the input parameter 'detail' which can be 'basic' or 'full' with default 'basic'.detail: z.enum(["basic", "full"]).default("basic").describe("Level of detail"), },
- index.ts:103-188 (registration)Registration of the 'get_system_info' tool using McpServer.tool() method, specifying name, description, input schema, and handler function.server.tool( "get_system_info", "Retrieve system information including OS, hardware, and user details. Can provide basic or full details.", { detail: z.enum(["basic", "full"]).default("basic").describe("Level of detail"), }, async ({ detail }) => { try { let cmd; if (isWindows) { cmd = "powershell.exe -Command \""; if (detail === "basic") { cmd += "$OS = Get-CimInstance Win32_OperatingSystem; " + "$CS = Get-CimInstance Win32_ComputerSystem; " + "$Processor = Get-CimInstance Win32_Processor; " + "Write-Output 'OS: ' $OS.Caption $OS.Version; " + "Write-Output 'Computer: ' $CS.Manufacturer $CS.Model; " + "Write-Output 'CPU: ' $Processor.Name; " + "Write-Output 'Memory: ' [math]::Round($OS.TotalVisibleMemorySize/1MB, 2) 'GB'"; } else { cmd += "$OS = Get-CimInstance Win32_OperatingSystem; " + "$CS = Get-CimInstance Win32_ComputerSystem; " + "$Processor = Get-CimInstance Win32_Processor; " + "$Disk = Get-CimInstance Win32_LogicalDisk -Filter 'DriveType=3'; " + "$Network = Get-CimInstance Win32_NetworkAdapterConfiguration | Where-Object {$_.IPAddress -ne $null}; " + "Write-Output '=== OPERATING SYSTEM ==='; " + "Write-Output ('OS: ' + $OS.Caption + ' ' + $OS.Version); " + "Write-Output ('Architecture: ' + $OS.OSArchitecture); " + "Write-Output ('Install Date: ' + $OS.InstallDate); " + "Write-Output ('Last Boot: ' + $OS.LastBootUpTime); " + "Write-Output (''; '=== HARDWARE ==='); " + "Write-Output ('Manufacturer: ' + $CS.Manufacturer); " + "Write-Output ('Model: ' + $CS.Model); " + "Write-Output ('Serial Number: ' + (Get-CimInstance Win32_BIOS).SerialNumber); " + "Write-Output ('Processor: ' + $Processor.Name); " + "Write-Output ('Cores: ' + $Processor.NumberOfCores); " + "Write-Output ('Logical Processors: ' + $Processor.NumberOfLogicalProcessors); " + "Write-Output ('Memory: ' + [math]::Round($OS.TotalVisibleMemorySize/1MB, 2) + ' GB'); " + "Write-Output (''; '=== STORAGE ==='); " + "foreach($drive in $Disk) { " + "Write-Output ('Drive ' + $drive.DeviceID + ' - ' + [math]::Round($drive.Size/1GB, 2) + ' GB (Free: ' + [math]::Round($drive.FreeSpace/1GB, 2) + ' GB)') " + "}; " + "Write-Output (''; '=== NETWORK ==='); " + "foreach($adapter in $Network) { " + "Write-Output ('Adapter: ' + $adapter.Description); " + "Write-Output (' IP Address: ' + ($adapter.IPAddress[0])); " + "Write-Output (' MAC Address: ' + $adapter.MACAddress); " + "Write-Output (' Gateway: ' + ($adapter.DefaultIPGateway -join ', ')); " + "}"; } cmd += "\""; } else { // Fallback for Unix systems if (detail === "basic") { cmd = "uname -a && lscpu | grep 'Model name' && free -h | head -n 2"; } else { cmd = "uname -a && lscpu && free -h && df -h && ip addr"; } } const stdout = executeCommand(cmd); return { content: [ { type: "text", text: stdout.toString(), }, ], }; } catch (error) { return { isError: true, content: [ { type: "text", text: `Error retrieving system info: ${error}`, }, ], }; } } );
- index.ts:17-47 (helper)Shared helper function used by get_system_info (and other tools) to execute shell commands cross-platform, with Windows priority and fallbacks/warnings for others.function executeCommand(command: string, options: any = {}) { if (isWindows) { return execSync(command, options); } else { // Log warning for non-Windows environments console.error(`Warning: Running in a non-Windows environment (${platform()}). Windows commands may not work.`); // For testing purposes on non-Windows platforms try { // For Linux/MacOS, we'll strip cmd.exe and powershell.exe references let modifiedCmd = command; // Replace cmd.exe /c with empty string modifiedCmd = modifiedCmd.replace(/cmd\.exe\s+\/c\s+/i, ''); // Replace powershell.exe -Command with empty string or a compatible command modifiedCmd = modifiedCmd.replace(/powershell\.exe\s+-Command\s+("|')/i, ''); // Remove trailing quotes if we removed powershell -Command if (modifiedCmd !== command) { modifiedCmd = modifiedCmd.replace(/("|')$/, ''); } console.error(`Attempting to execute modified command: ${modifiedCmd}`); return execSync(modifiedCmd, options); } catch (error) { console.error(`Error executing modified command: ${error}`); return Buffer.from(`This tool requires a Windows environment. Current platform: ${platform()}`); } } }