MCP SAP GUI Server

by mario-andreschak
Verified

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Provides tools to automate interactions with SAP GUI, enabling programmatic control of SAP transactions including launching transactions, clicking at coordinates, moving the mouse, typing text, and scrolling the SAP GUI screen.

MCP SAP GUI 服务器

用于 SAP GUI 自动化的模型上下文协议 (MCP) 服务器。该服务器提供用于自动化与 SAP GUI 交互的工具,从而支持对 SAP 事务进行编程控制。

要求

  • Python 3.8 或更高版本
  • SAP GUI 安装和配置
  • 有效的 SAP 凭证(系统、客户端、用户、密码)
  • Node.js(用于 npx)

安装

  1. 克隆 github 文件夹并使用安装脚本运行自动安装:
setup.bat

这将指导您完成构建过程,并将其直接集成到 Cline 或 Roo 中(如果您选择这样做)。

  1. 或使用构建脚本手动安装..:
build.bat
  1. 配置 SAP 凭据:
  • .env.example复制到.env
  • 使用您的 SAP 凭证更新值
  1. 使用 mcp 检查器测试服务器:
run.bat debug
  1. 使用集成脚本自动配置 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": [] }
  1. 使用此提示向您的 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参数控制的不同屏幕截图返回格式:

  1. none (默认值):仅返回成功/错误消息
{ "type": "text", "text": "Status: success" }
  1. as_file :将截图保存到指定的目标文件夹并返回路径
{ "type": "text", "text": "Screenshot saved as C:/path/to/file/screenshot.png" }

注意:使用as_file时,必须使用as_file_target_folder参数指定目标文件夹。如果文件夹不存在,则会创建该文件夹。

  1. as_base64 :返回原始 base64 字符串
{ "type": "text", "text": "base64_encoded_string_here" }
  1. as_imagecontent :返回 MCP ImageContent 对象
{ "type": "image", "data": "base64_encoded_string_here", "mimeType": "image/png" }
  1. 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" })

工具参数摘要:

工具范围类型默认描述
launch_transactiontransactionstring要启动的 SAP 事务代码(例如 VA01、ME21N、MM03)
return_screenshotstringnone截图返回格式( noneas_fileas_base64as_imagecontentas_imageurl
as_file_target_folderstring使用“as_file”返回格式时保存屏幕截图的目标文件夹路径
sap_clickxinteger点击发生的水平像素坐标(0-1920)
yinteger点击发生的垂直像素坐标(0-1080)
return_screenshotstringnone截图返回格式( noneas_fileas_base64as_imagecontentas_imageurl
as_file_target_folderstring使用“as_file”返回格式时保存屏幕截图的目标文件夹路径
sap_move_mousexinteger光标移动到的水平像素坐标(0-1920)
yinteger光标移动到的垂直像素坐标(0-1080)
return_screenshotstringnone截图返回格式( noneas_fileas_base64as_imagecontentas_imageurl
as_file_target_folderstring使用“as_file”返回格式时保存屏幕截图的目标文件夹路径
sap_typetextstring在 SAP GUI 窗口的当前光标位置输入的文本
return_screenshotstringnone截图返回格式( noneas_fileas_base64as_imagecontentas_imageurl
as_file_target_folderstring使用“as_file”返回格式时保存屏幕截图的目标文件夹路径
sap_scrolldirectionstring滚动屏幕的方向(“向上”使内容向下移动,“向下”使内容向上移动)
return_screenshotstringnone截图返回格式( noneas_fileas_base64as_imagecontentas_imageurl
as_file_target_folderstring使用“as_file”返回格式时保存屏幕截图的目标文件夹路径
end_transaction
save_last_screenshotfilenamestring屏幕截图保存的路径

发展

运行测试

  1. 使用 mcp 检查器测试服务器(构建 + 调试):
./run.bat full
  1. 或者使用测试套件:测试套件包含与 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许可证]

-
security - not tested
A
license - permissive license
-
quality - not tested

使用模型上下文协议自动与 SAP GUI 进行交互,允许通过单击、键入、滚动和事务管理等工具精确控制 SAP 事务。

  1. Requirements
    1. Installation
      1. Available Tools
        1. Transaction Management
        2. Interface Interaction
        3. Screen Capture
        4. Screenshot Return Formats
      2. Development
        1. Running Tests
      3. Project Structure
        1. License
          ID: jrsv7188i3