Skip to main content
Glama

Windows Automation MCP Server

clipboard.js2.42 kB
/** * 剪贴板工具 */ import { exec } from 'child_process'; import { promisify } from 'util'; const execAsync = promisify(exec); export class ClipboardTools { getToolDefinitions() { return [ { name: 'get_clipboard', description: '获取剪贴板内容', inputSchema: { type: 'object', properties: {}, }, }, { name: 'set_clipboard', description: '设置剪贴板内容', inputSchema: { type: 'object', properties: { text: { type: 'string', description: '要设置的文本内容' }, }, required: ['text'], }, }, { name: 'clear_clipboard', description: '清空剪贴板', inputSchema: { type: 'object', properties: {}, }, }, ]; } canHandle(toolName) { const tools = ['get_clipboard', 'set_clipboard', 'clear_clipboard']; return tools.includes(toolName); } async executeTool(name, args) { switch (name) { case 'get_clipboard': return await this.getClipboard(); case 'set_clipboard': return await this.setClipboard(args.text); case 'clear_clipboard': return await this.clearClipboard(); default: throw new Error(`未知工具: ${name}`); } } async getClipboard() { try { const { stdout } = await execAsync('powershell -Command "Get-Clipboard"', { shell: 'powershell.exe' }); return { success: true, content: stdout.trim() }; } catch (error) { return { success: false, error: error.message }; } } async setClipboard(text) { try { // 转义特殊字符 const escapedText = text.replace(/"/g, '`"').replace(/\$/g, '`$'); await execAsync(`powershell -Command "Set-Clipboard -Value '${escapedText}'"`, { shell: 'powershell.exe' }); return { success: true, message: '剪贴板已设置', length: text.length }; } catch (error) { return { success: false, error: error.message }; } } async clearClipboard() { try { await execAsync('powershell -Command "Set-Clipboard -Value $null"', { shell: 'powershell.exe' }); return { success: true, message: '剪贴板已清空' }; } catch (error) { return { success: false, error: error.message }; } } }

Implementation Reference

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