使用模型上下文协议自动化与SAP GUI的交互,通过点击、输入、滚动和事务管理等工具实现对SAP事务的精确控制。
os-automationother
639 查看 · 2026-07-07 更新
简介
使用模型上下文协议自动化与SAP GUI的交互,通过点击、输入、滚动和事务管理等工具实现对SAP事务的精确控制。
简介
使用模型上下文协议自动化与SAP GUI的交互,通过点击、输入、滚动和事务管理等工具实现对SAP事务的精确控制。
MCP SAP GUI 服务器
用于SAP GUI自动化的模型上下文协议(MCP)服务器。该服务器提供了自动化与SAP GUI交互的工具,实现了对SAP事务的编程控制。
要求
- Python 3.8 或更高版本
- 已安装并配置好的 SAP GUI
- 有效的SAP凭证(系统、客户端、用户、密码)
- Node.js (用于 npx)
安装
- 克隆 GitHub 文件夹并通过设置脚本运行自动化安装:
setup.bat
这将引导您完成构建过程,并根据您的选择直接将其集成到 Cline 或 Roo 中。
- 或者使用构建脚本手动安装...:
build.bat
- 配置SAP凭证:
- 将
.env.example复制为.env - 使用您的SAP凭证更新这些值
- 使用 mcp 检查器测试服务器:
run.bat debug
- 使用集成脚本来自动配置MCP设置:
integrate.bat cline # Configure for Cline integrate.bat roo # Configure for Roo
该脚本将:
- 自动确定正确的设置文件路径
- 在进行任何更改之前创建备份
- 安全地更新MCP配置
- 验证更改以防止损坏
手动配置(如果需要):
"mcp-sap-gui": { "command": "python", "args": [ "-m", "sap_gui_server.server" ], "cwd": "PATH_TO_YOUR_FOLDER/mcp-sap-gui", "disabled": false, "autoApprove": [] }
- 使用此提示向您的AI模型解释工具:
**Important Safety Notice:** SAP is a highly sensitive system where incorrect interactions can have serious consequences. Every action must be performed with utmost precision and care. When in doubt about any action, STOP immediately and request user assistance. **Available Tools:** The `mcp-sap-gui` server provides tools for SAP GUI interaction: * `launch_transaction`: Start a new transaction * `sap_click`: Click at specific coordinates * `sap_move_mouse`: Move mouse to coordinates * `sap_type`: Enter text into fields * `end_transaction`: Close the current transaction **Technical Limitations and Requirements:** 1. You will receive only screenshot images of the SAP GUI window after each action 2. No direct access to screen element metadata or technical representation 3. You must use image recognition to: * Identify UI elements (fields, buttons, etc.) * Determine precise x/y coordinates for interactions * Verify element sizes and positions 4. All coordinates must be exact - approximate clicking is not acceptable **Step-by-Step Process:** 1. Start SAP GUI Session: * Call `launch_transaction` with desired transaction code * Analyze the returned screenshot carefully 2. Interact with Screen: * Use image recognition to identify needed elements * Calculate exact coordinates for interaction * Execute appropriate action (`sap_click`, `sap_type`, etc.) * Verify result in next screenshot 3. Capture Screenshots: * Save screenshots at key points in the process 4. End Session: * Call `end_transaction` when finished **Best Practices:** 1. Always verify screen state before any action 2. Double-check coordinates before clicking 3. Document each step with clear annotations 4. If uncertain about any element position, request user verification 5. Maintain consistent screenshot naming convention
可用工具
MCP SAP GUI 服务器提供以下用于SAP自动化的工具:
事务管理
launch_transaction: 启动特定的SAP交易代码end_transaction: 结束当前的SAP交易
界面交互
sap_click: 在SAP GUI窗口中的特定坐标点击sap_move_mouse: 将鼠标光标移动到特定坐标sap_type: 在当前光标位置键入文本sap_scroll: 滚动SAP GUI屏幕(向上/向下)
屏幕捕获
save_last_screenshot: 保存SAP GUI窗口的最后一次截图。返回所保存图像的绝对文件路径。
截图返回格式
所有与SAP GUI窗口交互的工具(如 launch_transaction, sap_click, sap_move_mouse, sap_type, sap_scroll)支持通过 return_screenshot 参数控制的不同截图返回格式:
none(默认):仅返回成功/错误消息
{ "type": "text", "text": "Status: success" }
as_file: 将截图保存到指定的目标文件夹,并返回路径
{ "type": "text", "text": "Screenshot saved as C:/path/to/file/screenshot.png" }
注意:当使用 as_file 时,必须使用 as_file_target_folder 参数指定目标文件夹。如果该文件夹不存在,则会创建它。
as_base64: 返回原始的base64字符串
{ "type": "text", "text": "base64_encoded_string_here" }
as_imagecontent: 返回MCP ImageContent对象
{ "type": "image", "data": "base64_encoded_string_here", "mimeType": "image/png" }
as_imageurl: 返回嵌入的数据URL资源
{ "type": "resource", "resource": { "uri": "application:image", "mimeType": "image/png", "text": "data:image/png;base64,..." } }
示例用法:
# Default - no screenshot result = await client.call_tool("launch_transaction", { "transaction": "VA01" }) # Save to specific folder result = await client.call_tool("launch_transaction", { "transaction": "VA01", "return_screenshot": "as_file", "as_file_target_folder": "C:/screenshots" }) # Get base64 string result = await client.call_tool("launch_transaction", { "transaction": "VA01", "return_screenshot": "as_base64" })
工具参数摘要:
| Tool | Parameter | Type | Default | Description |
|---|---|---|---|---|
launch_transaction | transaction | string | SAP transaction code to launch (e.g., VA01, ME21N, MM03) | |
return_screenshot | string | none | Screenshot return format (none, as_file, as_base64, as_imagecontent, as_imageurl) | |
as_file_target_folder | string | Target folder path for saving screenshots when using 'as_file' return format | ||
sap_click | x | integer | Horizontal pixel coordinate (0-1920) where the click should occur | |
y | integer | Vertical pixel coordinate (0-1080) where the click should occur | ||
return_screenshot | string | none | Screenshot return format (none, as_file, as_base64, as_imagecontent, as_imageurl) | |
as_file_target_folder | string | Target folder path for saving screenshots when using 'as_file' return format | ||
sap_move_mouse | x | integer | Horizontal pixel coordinate (0-1920) to move the cursor to | |
y | integer | Vertical pixel coordinate (0-1080) to move the cursor to | ||
return_screenshot | string | none | Screenshot return format (none, as_file, as_base64, as_imagecontent, as_imageurl) | |
as_file_target_folder | string | Target folder path for saving screenshots when using 'as_file' return format | ||
sap_type | text | string | Text to enter at the current cursor position in the SAP GUI window | |
return_screenshot | string | none | Screenshot return format (none, as_file, as_base64, as_imagecontent, as_imageurl) | |
as_file_target_folder | string | Target folder path for saving screenshots when using 'as_file' return format | ||
sap_scroll | direction | string | Direction to scroll the screen ('up' moves content down, 'down' moves up) | |
return_screenshot | string | none | Screenshot return format (none, as_file, as_base64, as_imagecontent, as_imageurl) | |
as_file_target_folder | string | Target folder path for saving screenshots when using 'as_file' return format | ||
end_transaction | ||||
save_last_screenshot | filename | string | Path where the screenshot will be saved |
开发
运行测试
- 使用 mcp 检查器测试服务器(构建 + 调试):
./run.bat full
- 或者使用测试套件: 测试套件包括与 SAP GUI 交互的实时测试。请确保在运行测试之前已经安装并配置好了 SAP GUI。
运行测试:
run.bat test server
测试套件包括:
- SapGuiServer 测试 (test_server.py)
- 工具注册
- 请求处理
- 响应格式化
- 错误处理
项目结构
mcp-sap-gui/ ├── src/ │ └── sap_gui_server/ │ ├── __init__.py │ ├── sap_controller.py # SAP GUI interaction logic │ └── server.py # MCP server implementation ├── tests/ │ ├── __init__.py │ ├── test_sap_controller.py │ └── test_server.py ├── build.bat # Build and test script ├── integrate.bat # Integration script for Cline/Roo ├── integrate.py # Python script for safe MCP settings updates ├── requirements.txt # Production dependencies └── requirements-dev.txt # Development dependencies
许可证
[MIT License]
来源
- 来源:github
- 链接:https://github.com/mario-andreschak/mcp-sap-gui