M

MCP ABAP 开发工具

@mario-andreschak/mcp-abap-abap-adt-api
0 Stars 592 次浏览 mario-andreschak 更新于 2026-08-23

一种模型上下文协议(MCP)服务器,用于促进ABAP系统与MCP客户端之间的通信,提供管理ABAP对象、处理传输请求以及执行代码分析的工具,以增强ABAP开发工作流程。

该服务暂未提供标准配置,请参考 README 手动接入

服务介绍

免责声明:此服务器仍处于试验状态!请谨慎使用!

ABAP-ADT-API MCP-Server

smithery 徽章

描述

MCP-Server mcp-abap-abap-adt-api 是一个 Model Context Protocol (MCP) 服务器,旨在促进 ABAP 系统与 MCP 客户端之间的无缝通信。它是 abap-adt-api 的封装,并提供了一套工具和资源来管理 ABAP 对象、处理传输请求、执行代码分析等,从而提高 ABAP 开发工作流程的效率和效果。

功能

  • 身份验证:使用 login 工具安全地与 ABAP 系统进行身份验证。
  • 对象管理:无缝创建、读取、更新和删除 ABAP 对象。
  • 传输处理:使用 createTransporttransportInfo 等工具管理传输请求。
  • 代码分析:执行语法检查并获取代码补全建议。
  • 可扩展性:根据需要轻松扩展服务器的其他工具和资源。
  • 会话管理:使用 dropSessionlogout 处理会话缓存和终止。

安装

通过 Smithery 安装

要通过 Smithery 自动为 Claude Desktop 安装 ABAP-ADT-API MCP-Server:

npx -y @smithery/cli install @mario-andreschak/mcp-abap-abap-adt-api --client claude

先决条件

  • Node.js:确保已安装 Node.js。你可以从 这里 下载。
  • ABAP 系统访问:访问 ABAP 系统所需的凭证和 URL。

步骤

  1. 克隆仓库

    git clone https://github.com/mario-andreschak/mcp-abap-abap-adt-api.git
    cd mcp-abap-abap-adt-api
    
  2. 安装依赖

    npm install
    
  3. 配置环境变量

    根目录中提供了一个 .env.example 文件作为所需环境变量的模板。要设置你的环境:

    a. 复制 .env.example 文件并将其重命名为 .env

    cp .env.example .env
    

    b. 打开 .env 文件并将占位符值替换为实际的 SAP 连接详细信息:

    SAP_URL=https://your-sap-server.com:44300
    SAP_USER=YOUR_SAP_USERNAME
    SAP_PASSWORD=YOUR_SAP_PASSWORD
    SAP_CLIENT=YOUR_SAP_CLIENT
    SAP_LANGUAGE=YOUR_SAP_LANGUAGE
    

    注意:SAP_CLIENT 和 SAP_LANGUAGE 变量是可选的,但推荐设置。

    如果你使用自签名证书,还可以设置:

    NODE_TLS_REJECT_UNAUTHORIZED="0"
    

    重要提示:永远不要将你的 .env 文件提交到版本控制中。它已经在 .gitignore 中被排除,以防止意外提交。

  4. 构建项目

    npm run build
    
  5. 运行服务器

    npm run start
    

    (或者可以将 MCP 服务器集成到 VSCode 中)

使用

一旦服务器运行起来,你可以使用支持模型上下文协议(MCP)的客户端或工具与其交互(例如 Cline)。为了将MCP服务器与Cline集成,请使用以下MCP配置:

    "mcp-abap-abap-adt-api": {
      "command": "node",
      "args": [
        "PATH_TO_YOUR/mcp-abap-abap-adt-api/dist/index.js"
      ],
      "disabled": true,
      "autoApprove": [
      ]
    },

自定义指令

使用此自定义指令向你的模型解释该工具:

## mcp-abap-abap-adt-api Server

This server provides tools for interacting with an SAP system via ADT (ABAP Development Tools) APIs. It allows you to retrieve information about ABAP objects, modify source code, and manage transports.

**Key Tools and Usage:**

*   **`searchObject`:** Finds ABAP objects based on a query string (e.g., class name).
    *   `query`: (string, required) The search term.
    *   Returns the object's URI.  Example: `/sap/bc/adt/oo/classes/zcl_invoice_xml_gen_model`

*   **`transportInfo`:** Retrieves transport information for a given object.
    *   `objSourceUrl`: (string, required) The object's URI (obtained from `searchObject`).
    *   Returns transport details, including the transport request number (`TRKORR` or `transportInfo.LOCKS.HEADER.TRKORR` in the JSON response).

*   **`lock`:** Locks an ABAP object for editing.
    *   `objectUrl`: (string, required) The object's URI.
    *   Returns a `lockHandle`, which is required for subsequent modifications.

*   **`unLock`:** Unlocks a previously locked ABAP object.
    *   `objectUrl`: (string, required) The object's URI.
    *   `lockHandle`: (string, required) The lock handle obtained from the `lock` operation.

*   **`setObjectSource`:** Modifies the source code of an ABAP object.
    *   `objectSourceUrl`: (string, required) The object's URI *with the suffix `/source/main`*.  Example: `/sap/bc/adt/oo/classes/zcl_invoice_xml_gen_model/source/main`
    *   `lockHandle`: (string, required) The lock handle obtained from the `lock` operation.
    *   `source`: (string, required) The complete, modified ABAP source code.
    *   `transport`: (string, optional) The transport request number.

*   **`syntaxCheckCode`:** Performs a syntax check on a given ABAP source code.
    *   `code`: (string, required) The ABAP source code to check.
    *   `url`: (string, optional) The URL of the object.
    *   `mainUrl`: (string, optional) The main URL.
    *   `mainProgram`: (string, optional) The main program.
    *   `version`: (string, optional) The version.
    *   Returns syntax check results, including any errors.

*   **`activate`:** Activates an ABAP object. (See notes below on activation/unlocking.)
    *    `object`: The object to be activated.

*   **`getObjectSource`:** Retrieves the source code of an ABAP object.
    *   `objectSourceUrl`: (string, required) The object's URI *with the suffix `/source/main`*.

**Workflow for Modifying ABAP Code:**

1.  **Find the object URI:** Use `searchObject`.
2.  **Read the original source code:** Use `getObjectSource` (with the `/source/main` suffix).
3.  **Clone and Modify the source code locally:** (e.g., `write_to_file` for creating a local copy, and using `read_file`, `replace_in_file` for modifying this local copy).
4.  **Get transport information:** Use `transportInfo`.
5.  **Lock the object:** Use `lock`.
6.  **Set the modified source code:** Use `setObjectSource` (with the `/source/main` suffix).
7.  **Perform a syntax check:** Use `syntaxCheckCode`.
8.  **Activate** the object, Use `activate`..
9.  **unLock the object:** Use `unLock`.

**Important Notes:**
*   **File Handling:** SAP is completly de-coupled from the local file system. Reading source code will only return the code as tool result - it has no effect on file. Files are not synchronized with SAP but merely a local copy for our reference. FYI: It's not strictly necessary for you to create local copies of source codes, as they have no effect on SAP, but it helps us track changes. 
*   **File Handling:** The local filenames you will use will not contain any paths, but only a filename! It's preferable to use a pattern like "[ObjectName].[ObjectType].abap". (e.g., SAPMV45A.prog.abap for a ABAP Program SAPMV45A, CL_IXML.clas.abap for a Class CL_IXML)
*   **URL Suffix:**  Remember to add `/source/main` to the object URI when using `setObjectSource` and `getObjectSource`.
*   **Transport Request:** Obtain the transport request number (e.g., from `transportInfo` or from the user) and include it in relevant operations.
*   **Lock Handle:**  The `lockHandle` obtained from the `lock` operation is crucial for `setObjectSource` and `unLock`. Ensure you are using a valid `lockHandle`. If a lock fails, you may need to re-acquire the lock. Locks can expire or be released by other users.
*   **Activation/Unlocking Order:** The exact order of `activate` and `unLock` operations might need clarification. Refer to the tool descriptions or ask the user. It appears `activate` can be used without unlocking first.
* **Error Handling:** The tools return JSON responses. Check for error messages within these responses.

## Efficient Database Access

SAP systems contain vast amounts of data.  It's crucial to write ABAP code that accesses the database efficiently to minimize performance impact and network traffic.  Avoid selecting entire tables or using broad `WHERE` clauses when you only need specific data.

*   **Use `WHERE` clauses:** Always use `WHERE` clauses in your `SELECT` statements to filter the data retrieved from the database.  Select only the specific rows you need.
*   **`UP TO 1 ROWS`:** If you only need a single record, use the `SELECT SINGLE` statement, if you can guarantee that you can provide ALL the key fields for the `SELECT SINGLE` statement. Otherwise, use the `SELECT` statement with the `UP TO 1 ROWS` addition. This tells the database to stop searching after finding the first matching record, improving performance. Example:

    ```abap
    SELECT vgbel FROM vbrp WHERE vbeln = @me->lv_vbeln INTO @DATA(lv_vgbel) UP TO 1 ROWS.
      EXIT. " Exit any loop after this.
    ENDSELECT.
    ```
## Checking Table and Structure Definitions

When working with ABAP objects, you may encounter errors related to unknown field names or incorrect table usage.  You can use the following tools to inspect table and structure definitions:

*   **`GetTable`:** Use this tool to retrieve the structure of an ABAP Dictionary table, including its field names and data types. This is helpful for verifying the correct fields to use in your `SELECT` statements.
*    If you need to inspect an include structure, you may need to use `searchObject` to find the include and then use `GetTypeInfo` or `GetStructure`. You may get a 404 error and try again with `GetStructure`
*   **`GetStructure`:** Use this tool to retrieve the structure of an ABAP Dictionary structure, including its field names and data types. This is helpful for verifying the correct fields to use in your `SELECT` statements.
*    If you need to inspect an include structure, you may need to use `searchObject` to find the include and then use `GetTypeInfo` or `GetStructure`.

贡献

欢迎贡献!请按照以下步骤进行贡献:

  1. 分叉仓库

  2. 创建新分支

    git checkout -b feature/your-feature-name
    
  3. 提交你的更改

    git commit -m "Add some feature"
    
  4. 推送到分支

    git push origin feature/your-feature-name
    
  5. 打开一个拉取请求

许可证

本项目根据 MIT许可证 发布。

相关 MCP 服务