Skip to main content
Glama
eva-wanxin-git

Windows Automation MCP Server

get_active_window

Retrieve the currently active window on a Windows system to monitor or control application focus for automation workflows.

Instructions

获取当前激活的窗口

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function `getActiveWindow()` that executes a PowerShell script using Windows API calls (GetForegroundWindow and GetWindowText) to retrieve and return the title of the currently active (foreground) window.
      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 };
        }
      }
  • Tool definition including name, description, and input schema (empty object, no parameters required).
    {
      name: 'get_active_window',
      description: '获取当前激活的窗口',
      inputSchema: {
        type: 'object',
        properties: {},
      },
    },
  • Switch case in `executeTool` method that registers and dispatches calls to the `get_active_window` tool by invoking the handler method.
    case 'get_active_window':
      return await this.getActiveWindow();
  • src/server.js:47-52 (registration)
    Instantiation of WindowTools class in the main tools registry object, enabling discovery and execution of its tools including get_active_window.
      window: new WindowTools(),
      screen: new ScreenTools(),
      clipboard: new ClipboardTools(),
      powershell: new PowerShellTools(),
      browser: new BrowserTools(),
    };
  • The `canHandle` method's tools list explicitly includes 'get_active_window' for tool name validation.
    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