Skip to main content
Glama
alxspiker

Windows Command Line MCP Server

list_running_processes

Identify and monitor active processes on Windows systems. Filter results by process name to quickly locate specific applications or services.

Instructions

List all running processes on the system. Can be filtered by providing an optional filter string that will match against process names.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filterNoOptional filter string to match against process names

Implementation Reference

  • index.ts:56-100 (handler)
    The asynchronous handler function for the 'list_running_processes' tool. It constructs platform-specific commands (PowerShell Get-Process on Windows with optional filter, ps aux | grep on Unix) , executes via executeCommand helper, and returns the stdout as text content or error.
      async ({ filter }) => {
        try {
          let cmd;
          
          if (isWindows) {
            cmd = "powershell.exe -Command \"Get-Process";
            
            if (filter) {
              // Add filter if provided
              cmd += ` | Where-Object { $_.ProcessName -like '*${filter}*' }`;
            }
            
            cmd += " | Select-Object Id, ProcessName, CPU, WorkingSet, Description | Format-Table -AutoSize | Out-String\"";
          } else {
            // Fallback for Unix systems
            cmd = "ps aux";
            
            if (filter) {
              cmd += ` | grep -i ${filter}`;
            }
          }
          
          const stdout = executeCommand(cmd);
          
          return {
            content: [
              {
                type: "text",
                text: stdout.toString(),
              },
            ],
          };
        } catch (error) {
          return {
            isError: true,
            content: [
              {
                type: "text",
                text: `Error listing processes: ${error}`,
              },
            ],
          };
        }
      }
    );
  • Zod input schema defining the optional 'filter' parameter as a string for matching process names.
    {
      filter: z.string().optional().describe("Optional filter string to match against process names"),
    },
  • index.ts:49-52 (registration)
    Registration of the 'list_running_processes' tool using server.tool(), including name and description.
    // Register the list_running_processes tool
    server.tool(
      "list_running_processes",
      "List all running processes on the system. Can be filtered by providing an optional filter string that will match against process names.",
  • Platform-aware helper function 'executeCommand' that runs commands via execSync, with modifications for non-Windows environments to strip Windows-specific prefixes.
    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