Skip to main content
Glama
alxspiker

Windows Command Line MCP Server

get_network_info

Retrieve network configuration details like IP addresses, adapters, and DNS settings. Filter results by specific interface to diagnose connectivity issues.

Instructions

Retrieve network configuration information including IP addresses, adapters, and DNS settings. Can be filtered to a specific interface.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
networkInterfaceNoOptional interface name to filter results

Implementation Reference

  • Handler function that executes platform-specific commands (PowerShell on Windows, ip on Unix) to retrieve network adapter information, IP addresses, MAC, DNS, etc., optionally filtered by interface.
    async ({ networkInterface }) => { try { let cmd; if (isWindows) { cmd = "powershell.exe -Command \""; if (networkInterface) { cmd += "$adapters = Get-NetAdapter | Where-Object { $_.Name -like '*" + networkInterface + "*' }; "; } else { cmd += "$adapters = Get-NetAdapter; "; } cmd += "foreach($adapter in $adapters) { " + "Write-Output ('======== ' + $adapter.Name + ' (' + $adapter.Status + ') ========'); " + "Write-Output ('Interface Description: ' + $adapter.InterfaceDescription); " + "Write-Output ('MAC Address: ' + $adapter.MacAddress); " + "Write-Output ('Link Speed: ' + $adapter.LinkSpeed); " + "$ipconfig = Get-NetIPConfiguration -InterfaceIndex $adapter.ifIndex; " + "Write-Output ('IP Address: ' + ($ipconfig.IPv4Address.IPAddress -join ', ')); " + "Write-Output ('Subnet: ' + ($ipconfig.IPv4Address.PrefixLength -join ', ')); " + "Write-Output ('Gateway: ' + ($ipconfig.IPv4DefaultGateway.NextHop -join ', ')); " + "Write-Output ('DNS Servers: ' + ($ipconfig.DNSServer.ServerAddresses -join ', ')); " + "Write-Output ''; " + "}\""; } else { // Fallback for Unix systems if (networkInterface) { cmd = `ip addr show ${networkInterface}`; } else { cmd = "ip addr"; } } const stdout = executeCommand(cmd); return { content: [ { type: "text", text: stdout.toString(), }, ], }; } catch (error) { return { isError: true, content: [ { type: "text", text: `Error retrieving network info: ${error}`, }, ], }; } }
  • Zod schema defining the input parameters for the tool: optional networkInterface string.
    { networkInterface: z.string().optional().describe("Optional interface name to filter results"), },
  • index.ts:191-253 (registration)
    Registration of the 'get_network_info' tool using server.tool(), including name, description, input schema, and handler function.
    server.tool( "get_network_info", "Retrieve network configuration information including IP addresses, adapters, and DNS settings. Can be filtered to a specific interface.", { networkInterface: z.string().optional().describe("Optional interface name to filter results"), }, async ({ networkInterface }) => { try { let cmd; if (isWindows) { cmd = "powershell.exe -Command \""; if (networkInterface) { cmd += "$adapters = Get-NetAdapter | Where-Object { $_.Name -like '*" + networkInterface + "*' }; "; } else { cmd += "$adapters = Get-NetAdapter; "; } cmd += "foreach($adapter in $adapters) { " + "Write-Output ('======== ' + $adapter.Name + ' (' + $adapter.Status + ') ========'); " + "Write-Output ('Interface Description: ' + $adapter.InterfaceDescription); " + "Write-Output ('MAC Address: ' + $adapter.MacAddress); " + "Write-Output ('Link Speed: ' + $adapter.LinkSpeed); " + "$ipconfig = Get-NetIPConfiguration -InterfaceIndex $adapter.ifIndex; " + "Write-Output ('IP Address: ' + ($ipconfig.IPv4Address.IPAddress -join ', ')); " + "Write-Output ('Subnet: ' + ($ipconfig.IPv4Address.PrefixLength -join ', ')); " + "Write-Output ('Gateway: ' + ($ipconfig.IPv4DefaultGateway.NextHop -join ', ')); " + "Write-Output ('DNS Servers: ' + ($ipconfig.DNSServer.ServerAddresses -join ', ')); " + "Write-Output ''; " + "}\""; } else { // Fallback for Unix systems if (networkInterface) { cmd = `ip addr show ${networkInterface}`; } else { cmd = "ip addr"; } } const stdout = executeCommand(cmd); return { content: [ { type: "text", text: stdout.toString(), }, ], }; } catch (error) { return { isError: true, content: [ { type: "text", text: `Error retrieving network info: ${error}`, }, ], }; } } );
  • Helper function used by the handler to execute shell commands cross-platform, with Windows priority and fallbacks.
    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()}`); } } }

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/alxspiker/Windows-Command-Line-MCP-Server'

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