Skip to main content
Glama

Windows Automation MCP Server

take_screenshot_region

Capture a specific rectangular area of your screen by defining coordinates and dimensions. Save screenshots of selected regions for documentation, troubleshooting, or recording purposes.

Instructions

截取屏幕区域

Input Schema

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

Input Schema (JSON Schema)

{ "properties": { "height": { "description": "高度", "type": "number" }, "path": { "description": "保存路径(可选)", "type": "string" }, "width": { "description": "宽度", "type": "number" }, "x": { "description": "X 坐标", "type": "number" }, "y": { "description": "Y 坐标", "type": "number" } }, "required": [ "x", "y", "width", "height" ], "type": "object" }

Implementation Reference

  • Core handler function `takeScreenshotRegion` that captures a screenshot of the specified screen region using PowerShell script, handles file saving, and returns success/error response.
    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 }; } }
  • Input schema definition for the `take_screenshot_region` tool, specifying parameters 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'], }, },
  • `getToolDefinitions()` method registers the tool by returning its name, description, and schema as part of the tools list.
    getToolDefinitions() { return [ { name: 'take_screenshot', description: '截取屏幕截图', inputSchema: { type: 'object', properties: { path: { type: 'string', description: '保存路径(可选,默认桌面)' }, format: { type: 'string', enum: ['png', 'jpg'], description: '图片格式(可选,默认 png)' }, }, }, }, { 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'], }, }, ];
  • src/server.js:48-48 (registration)
    Instantiates `ScreenTools` class, making its tools (including `take_screenshot_region`) available in the MCP server.
    screen: new ScreenTools(),
  • `executeTool` method with switch case that routes `take_screenshot_region` calls to the handler function.
    async executeTool(name, args) { switch (name) { case 'take_screenshot': return await this.takeScreenshot(args.path, args.format); case 'take_screenshot_region': return await this.takeScreenshotRegion(args.x, args.y, args.width, args.height, args.path); default: throw new Error(`未知工具: ${name}`); } }

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