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
列出所有打开的窗口
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "list_windows"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filter | No | 过滤窗口标题(可选) |
Implementation Reference
- src/tools/window.js:102-157 (handler)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 }; } } - src/tools/window.js:12-21 (schema)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: '过滤窗口标题(可选)' }, }, }, }, - src/tools/window.js:85-86 (registration)Registration in the executeTool method's switch statement, dispatching calls to the listWindows handler.
case 'list_windows': return await this.listWindows(args.filter); - src/tools/window.js:78-79 (registration)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'];