Skip to main content
Glama

Windows Automation MCP Server

get_active_window

Retrieve the currently active window on Windows systems to monitor user activity, track application focus, or automate window-based workflows.

Instructions

获取当前激活的窗口

Input Schema

NameRequiredDescriptionDefault

No arguments

Input Schema (JSON Schema)

{ "properties": {}, "type": "object" }

Implementation Reference

  • The handler function that retrieves the title of the currently active (foreground) window using Windows API via PowerShell.
    async getActiveWindow() { try { const script = ` Add-Type @" using System; using System.Runtime.InteropServices; using System.Text; public class Win32 { [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount); } "@ $hWnd = [Win32]::GetForegroundWindow() $title = New-Object System.Text.StringBuilder 256 [Win32]::GetWindowText($hWnd, $title, 256) $title.ToString() `; const { stdout } = await execAsync(`powershell -Command "${script.replace(/"/g, '\\"')}"`, { shell: 'powershell.exe' }); return { success: true, window: stdout.trim() }; } catch (error) { return { success: false, error: error.message }; } }
  • The tool schema definition, specifying name, description, and empty input schema (no parameters required).
    { name: 'get_active_window', description: '获取当前激活的窗口', inputSchema: { type: 'object', properties: {}, }, },
  • The dispatcher method that handles tool execution, routing 'get_active_window' to the getActiveWindow handler.
    async executeTool(name, args) { switch (name) { case 'list_windows': return await this.listWindows(args.filter); case 'get_active_window': return await this.getActiveWindow(); case 'activate_window': return await this.activateWindow(args.title); case 'close_window': return await this.closeWindow(args.title); case 'minimize_window': return await this.minimizeWindow(args.title); case 'maximize_window': return await this.maximizeWindow(args.title); default: throw new Error(`未知工具: ${name}`); } }
  • The canHandle method listing supported tools, including 'get_active_window'.
    canHandle(toolName) { const tools = ['list_windows', 'get_active_window', 'activate_window', 'close_window', 'minimize_window', 'maximize_window']; return tools.includes(toolName);

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