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);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It states the action ('get') but lacks behavioral details such as whether this is a read-only operation (implied but not stated), what happens if no window is active, the format of the returned data, or any system dependencies. For a tool with zero annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence in Chinese ('获取当前激活的窗口'), which directly conveys the purpose without any wasted words. It is appropriately sized and front-loaded, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (simple read operation) but lack of annotations and output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., window title, handle, or other properties), which is critical for an agent to use it effectively. With no structured output information, the description should compensate more to be complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has 0 parameters, and the input schema has 100% description coverage (though empty). The description doesn't need to add parameter semantics, so it meets the baseline. No extra parameter information is provided or needed, but it doesn't explicitly state 'no parameters required,' which could slightly improve clarity.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description '获取当前激活的窗口' (Get the currently active window) clearly states the verb ('get') and resource ('active window'), making the purpose unambiguous. It distinguishes from siblings like 'list_windows' (which lists all windows) and 'activate_window' (which changes the active window). However, it doesn't specify what information about the window is returned (e.g., title, handle, position), keeping it from a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when the current active window information is needed, but doesn't explicitly state when to use this tool versus alternatives like 'list_windows' for all windows or 'get_screen_size' for display info. No exclusions or prerequisites are mentioned, leaving some ambiguity for the agent in tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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