Skip to main content
Glama
eva-wanxin-git

Windows Automation MCP Server

take_screenshot_region

Capture a specific rectangular area of your Windows screen by defining coordinates and dimensions, then save the screenshot to a specified path.

Instructions

截取屏幕区域

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
xYesX 坐标
yYesY 坐标
widthYes宽度
heightYes高度
pathNo保存路径(可选)

Implementation Reference

  • The core handler function that executes the region screenshot using PowerShell to capture a specific screen area and save it as PNG.
    async takeScreenshotRegion(x, y, width, height, savePath) {
      try {
        const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
        const fileName = `screenshot-region-${timestamp}.png`;
        const defaultPath = path.join(process.env.USERPROFILE, 'Desktop', fileName);
        const finalPath = savePath || defaultPath;
    
        const script = `
          Add-Type -AssemblyName System.Windows.Forms,System.Drawing
          $bitmap = New-Object System.Drawing.Bitmap ${width}, ${height}
          $graphics = [System.Drawing.Graphics]::FromImage($bitmap)
          $graphics.CopyFromScreen(${x}, ${y}, 0, 0, [System.Drawing.Size]::new(${width}, ${height}))
          $bitmap.Save("${finalPath}", [System.Drawing.Imaging.ImageFormat]::Png)
          $bitmap.Dispose()
          $graphics.Dispose()
        `;
    
        await execAsync(`powershell -Command "${script.replace(/"/g, '\\"')}"`, {
          shell: 'powershell.exe'
        });
    
        await fs.access(finalPath);
    
        return { 
          success: true, 
          path: finalPath, 
          region: { x, y, width, height },
          message: '区域截图已保存' 
        };
      } catch (error) {
        return { success: false, error: error.message };
      }
    }
  • Tool schema definition including name, description, input schema with properties x, y, width, height (required), and optional path.
    {
      name: 'take_screenshot_region',
      description: '截取屏幕区域',
      inputSchema: {
        type: 'object',
        properties: {
          x: { type: 'number', description: 'X 坐标' },
          y: { type: 'number', description: 'Y 坐标' },
          width: { type: 'number', description: '宽度' },
          height: { type: 'number', description: '高度' },
          path: { type: 'string', description: '保存路径(可选)' },
        },
        required: ['x', 'y', 'width', 'height'],
      },
    },
  • Registration of the tool handler in the executeTool switch statement, mapping tool name to the takeScreenshotRegion method.
    case 'take_screenshot_region':
      return await this.takeScreenshotRegion(args.x, args.y, args.width, args.height, args.path);
  • src/server.js:97-102 (registration)
    Tool dispatching logic in handleToolCall that routes tool calls to the appropriate module (ScreenTools) based on canHandle.
    for (const [category, toolModule] of Object.entries(this.tools)) {
      if (toolModule.canHandle(name)) {
        result = await toolModule.executeTool(name, args);
        break;
      }
    }
  • src/server.js:48-48 (registration)
    Instantiation and registration of ScreenTools instance in the server's tools object.
    screen: new ScreenTools(),

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