Skip to main content
Glama
eva-wanxin-git

Windows Automation MCP Server

list_windows

Retrieve a list of all currently open windows on a Windows system. Filter results by window title to find specific applications or processes quickly.

Instructions

列出所有打开的窗口

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filterNo过滤窗口标题(可选)

Implementation Reference

  • The main handler function that lists all visible windows using Win32 API via PowerShell script, filters by title if provided, and returns a structured response.
      async listWindows(filter = '') {
        try {
          // 使用 PowerShell 获取窗口列表
          const script = `
            Add-Type @"
              using System;
              using System.Runtime.InteropServices;
              using System.Text;
              public class Win32 {
                [DllImport("user32.dll")]
                public static extern bool EnumWindows(EnumWindowsProc enumProc, IntPtr lParam);
                [DllImport("user32.dll")]
                public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
                [DllImport("user32.dll")]
                public static extern bool IsWindowVisible(IntPtr hWnd);
                public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
              }
    "@
            $windows = @()
            [Win32]::EnumWindows({
              param($hWnd, $lParam)
              if ([Win32]::IsWindowVisible($hWnd)) {
                $title = New-Object System.Text.StringBuilder 256
                [Win32]::GetWindowText($hWnd, $title, 256)
                if ($title.Length -gt 0) {
                  $windows += $title.ToString()
                }
              }
              return $true
            }, [IntPtr]::Zero)
            $windows | ConvertTo-Json
          `;
    
          const { stdout } = await execAsync(`powershell -Command "${script.replace(/"/g, '\\"')}"`, {
            shell: 'powershell.exe'
          });
    
          let windows = [];
          try {
            windows = JSON.parse(stdout);
            if (!Array.isArray(windows)) {
              windows = [windows];
            }
          } catch {
            windows = [];
          }
    
          const filtered = filter 
            ? windows.filter(w => w.toLowerCase().includes(filter.toLowerCase()))
            : windows;
    
          return { success: true, windows: filtered, count: filtered.length };
        } catch (error) {
          return { success: false, error: error.message };
        }
      }
  • Tool schema definition in getToolDefinitions(), specifying name, description, and optional filter input schema.
    {
      name: 'list_windows',
      description: '列出所有打开的窗口',
      inputSchema: {
        type: 'object',
        properties: {
          filter: { type: 'string', description: '过滤窗口标题(可选)' },
        },
      },
    },
  • Registration in the executeTool method's switch statement, dispatching calls to the listWindows handler.
    case 'list_windows':
      return await this.listWindows(args.filter);
  • Tool name listed in the canHandle method's supported tools array.
    const tools = ['list_windows', 'get_active_window', 'activate_window', 
                   'close_window', 'minimize_window', 'maximize_window'];

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/eva-wanxin-git/windows-automation-mcp'

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