SAP MCP-RFC Bridge

SAP MCP-RFC Bridge

An MCP server that enables MCP clients like Claude Code to work with SAP ABAP objects over RFC, reaching systems without HTTP/ADT endpoints such as classic ECC/R/3.

Category
访问服务器

README

MCP-RFC bridge for SAP ABAP (RFC-only / SAProuter / ECC R3)

An MCP server that lets an MCP client (e.g. Claude Code) work with SAP ABAP objects over RFC instead of ADT/HTTP. Because it speaks RFC + SAProuter, it reaches systems that expose no HTTP/ADT endpoint — including classic ECC / R/3.

Inspired by the SAP Community blog "Using Claude for SAP ABAP development on RFC-only / SAProuter systems (even ECC R/3)". This is an independent, prototype implementation — not an official SAP or Anthropic product.

Architecture

Claude Code  --stdio/MCP-->  server.py (FastMCP)
                                   |
                             sap/tools.py      (wraps standard SAP FMs)
                                   |
                             sap/connection.py (pyrfc Connection, reconnect)
                                   |
                             sap/config.py     (.env -> conn params, SAProuter)
                                   |
                                 pyrfc  --RFC/SAProuter-->  SAP system

Tools exposed

Tool Purpose Needs write?
sap_ping Test connection, system info no
sap_read_table Read a table (RFC_READ_TABLE) no
sap_read_program Read ABAP report source no
sap_read_function_module Read FM source + interface no
sap_read_class Read class/interface source no
sap_read_method Read ONE method of a class no
sap_class_api Public API only (+ dependency APIs) no
sap_dead_code Unused-method scan for a package no
sap_search_objects Search TADIR for repository objects no
sap_ddic_info Describe table/structure fields no
sap_list_dumps Recent ST22 runtime errors no
sap_list_transports List transport requests (E070) no
sap_read_transport One transport + its object list no
sap_where_used Where-used via WBCROSSGT index no
sap_read_screen Read Dynpro definition (via Z-FM) no
sap_read_gui_status Read GUI status/CUA (via Z-FM) no
sap_syntax_check Syntax-check source, no save (Z-FM) no
sap_read_cds Read CDS/DDL source (Z-FM) no
sap_textpool_read Read program text elements (Z-FM) no
sap_run_unit_tests Run ABAP Unit for a class (Z-FM) no
sap_run_atc Run ATC check (Z-FM stub) no
sap_adt_dispatch Raw ZMCP_ADT_DISPATCH call read: no / write: yes
sap_activate Activate inactive objects (Z-FM) yes
sap_textpool_write Write program text elements (Z-FM) yes
sap_write_program Create/update program (INACTIVE) yes
sap_run_rfc Call an arbitrary RFC-enabled FM yes

Custom dispatcher ZMCP_ADT_DISPATCH

The Z-FM tools above route through a custom RFC-enabled FM ZMCP_ADT_DISPATCH (function group ZMCP_ADT_UTILS) installed on the SAP system — the escape hatch for features no standard RFC FM exposes. It runs inside SAP, so it can call non-remote workbench APIs (SYNTAX-CHECK, RS_WORKING_OBJECTS_ACTIVATE, READ/INSERT TEXTPOOL, DDDDLSRC, ABAP Unit, ATC) and return JSON.

Install the two FMs from abap/ on any SAP system you want to drive (see abap/README.md for the interfaces and step-by-step setup). Action → tool map:

Action Tool Underlying ABAP
SYNTAX_CHECK sap_syntax_check SYNTAX-CHECK FOR
READ_DDLS sap_read_cds SELECT … FROM DDDDLSRC
RUN_UNIT_TESTS sap_run_unit_tests CL_AUCV_TEST_RUNNER_STANDARD
ATC_CHECK sap_run_atc CL_SATC_API_FACTORY (stub — fill in)
ACTIVATE sap_activate RS_WORKING_OBJECTS_ACTIVATE
DYNPRO_* / CUA_* sap_read_screen / sap_read_gui_status RPY_DYNPRO_* / RS_CUA_INTERNAL_*

RUN_UNIT_TESTS and ATC_CHECK use release-sensitive class APIs — verify/adjust the ABAP in SE24 for your system (ATC_CHECK ships as an explicit stub). Every write action goes through the same SAP_ALLOW_WRITE guard.

Text elements use a separate dedicated FM, ZMCP_ADT_TEXTPOOL (same function group), driven by sap_textpool_read / sap_textpool_write. Flag it Remote-Enabled in SE37 to use it. sap_textpool_write defaults to WRITE_INACTIVE (staged; published on program activation), matching the "nothing goes live until activate" model; pass active=true to write directly.

Write tools are disabled unless SAP_ALLOW_WRITE=true.

Sensitive-table policy: sap_read_table refuses tables holding credentials/PII (USR02, PA0*, SECSTORE*, …). Override the pattern list via SAP_TABLE_BLOCKLIST (comma-separated, * wildcards) in .env.

Package whitelist for writes: set SAP_ALLOWED_PACKAGES (e.g. $TMP,ZPK_SANDBOX*) to restrict sap_write_program to specific packages. Unset = no package restriction (only SAP_ALLOW_WRITE applies).

FM deny list: sap_run_rfc refuses high-risk function modules (OS command execution, arbitrary ABAP, mass delete, raw SQL, user admin, file transfer, kernel admin) even with SAP_ALLOW_WRITE=true. Override the pattern list via SAP_FM_DENYLIST (comma-separated, * wildcards).

Project layout

MCP_SAP_PRIVATE/
  bootstrap.bat              copy to a new machine: clones repo + runs setup
  setup.ps1 / setup.bat      installer + MCP registration
  README.md
  mcp/                       the MCP server (everything it needs to run)
    server.py                MCP server entrypoint (FastMCP, stdio)
    test_connection.py       standalone connectivity check
    requirements.txt
    .env / .env.example      base/shared settings (real .env is git-ignored)
    profiles/                one <name>.env per SAP system (multi-system)
      ds4.env.example        per-system profile template
    sap/                     Python package (the bridge)
      config.py              .env -> pyrfc params, SAProuter, SDK discovery
      connection.py          pyrfc wrapper, reconnect, DLL registration
      tools.py               FM wrappers behind each MCP tool
    vendor/                  third-party / licensed binaries
      nwrfcsdk/              SAP NW RFC SDK (bundled, auto-detected)
      pyrfc-3.3.1-*.whl      prebuilt pyrfc wheel (offline install)
  abap/                      ABAP to install on the SAP system (reusable)
    README.md                install guide + FM interfaces
    zmcp_adt_dispatch.abap   ZMCP_ADT_DISPATCH (screens, syntax, activate, …)
    zmcp_adt_textpool.abap   ZMCP_ADT_TEXTPOOL (text elements)

Deploy via git (clone-and-go)

This repo is meant for a private git remote: the SAP NW RFC SDK (mcp/vendor/nwrfcsdk) and the pyrfc wheel are committed, so a fresh clone runs without any SAP-portal download. Secrets are not committed — .env and mcp/profiles/*.env are git-ignored; each machine fills them in locally.

First push (once, from this folder)

git init
git add .
git commit -m "SAP MCP-RFC bridge"
git remote add origin https://github.com/ChinhHN-DEV/MCP_SAP_PRIVATE.git
git push -u origin main

The commit includes the ~60 MB SDK. Keep the remote private — the SDK is licensed and must not be public.

On a new machine (one command)

Edit the REPO= line in bootstrap.bat, copy just that one file to the new machine, and run it (or bootstrap.bat <git-url>). It clones the repo and runs setup.ps1. Afterwards, create your connection config:

# single system:
copy mcp\.env.example mcp\.env            # then edit
# or multi-system:
copy mcp\profiles\ds4.env.example mcp\profiles\ds4.env   # then edit, re-run setup.ps1

Quick install on a new machine

Copy the whole folder over, then from inside it run one of:

# Windows (PowerShell)
powershell -ExecutionPolicy Bypass -File .\setup.ps1

…or just double-click setup.bat.

setup.ps1 finds Python, installs python-dotenv + mcp, installs the matching pyrfc wheel (from vendor/, or downloads the right one), verifies the bundled SDK, creates .env from the template, and registers the sap-rfc MCP server with Claude Code using this folder's current absolute path — so it works no matter where the folder was moved to. Afterwards just edit .env and run python mcp\test_connection.py. The manual steps below are the same thing by hand.

Multiple SAP systems

Run one MCP server per system, each selected by a profile file. Claude Code then sees separate, namespaced tool sets (mcp__sap-ds4__…, mcp__sap-qa4__…) and picks the right system by server name.

  1. Put per-system logon in mcp/profiles/<name>.env (copy mcp/profiles/ds4.env.example):
    profiles/ds4.env      # DEV, SAP_ALLOW_WRITE=true
    profiles/qa4.env      # QA,  read-only
    profiles/prd.env      # PROD, read-only
    
    Shared policy (SAP_TABLE_BLOCKLIST, SAP_FM_DENYLIST, …) stays in the base .env; each profile overrides the base and holds that system's credentials + SAP_ALLOW_WRITE.
  2. Run setup.ps1 — it registers one server sap-<name> per profile file (falls back to a single sap-rfc from .env when no profiles exist).
  3. Test a specific system:
    python mcp\test_connection.py --profile qa4
    

Profile selection precedence: --env-file <path> > --profile <name> > SAP_PROFILE env var > base .env. sap_ping reports which profile answered. Keep DEV writable and QA/PROD read-only (SAP_ALLOW_WRITE=false) so the deny guards differ per system automatically.

Setup (manual)

1. SAP NW RFC SDK (prerequisite for pyrfc)

pyrfc wraps the SAP NetWeaver RFC SDK (licensed; from the SAP Support Portal). This repo bundles the Windows SDK at mcp/vendor/nwrfcsdk, auto-detected and registered at runtime (via os.add_dll_directory). No PATH edits needed. To use a different SDK location, set SAPNWRFC_HOME — it takes precedence over the bundled copy.

OS runtime prerequisite for the SDK (SAP Note 2573790)

The NW RFC SDK DLL needs the Microsoft Visual C++ 2015-2022 Redistributable x64 (vcruntime140.dll) present — without it, import pyrfc fails with a cryptic load error. setup.ps1 warns and links the installer if it is missing. Patch level of an installed SDK: findstr Patch sapnwrfc.dll.

2. Install Python dependencies

pyrfc has no PyPI wheel for recent Python, so a matching prebuilt wheel is vendored in mcp/vendor/:

python -m pip install python-dotenv mcp
python -m pip install mcp/vendor/pyrfc-3.3.1-cp312-cp312-win_amd64.whl

The wheel is cp312 / win_amd64 (Python 3.12, Windows 64-bit) from the SAP-archive/PyRFC GitHub releases. For a different Python version, fetch the matching wheel from there.

3. Configure the connection

Copy-Item mcp\.env.example mcp\.env
# then edit .env

SAProuter example — either put the full route in SAP_ASHOST:

SAP_ASHOST=/H/saprouter.example.com/S/3299/H/sapappserver.internal
SAP_SYSNR=00

…or keep a plain host and set the router prefix separately:

SAP_ASHOST=sapappserver.internal
SAP_SYSNR=00
SAP_SAPROUTER=/H/saprouter.example.com/S/3299

4. Test connectivity (no MCP needed)

python mcp\test_connection.py

5. Register the server with Claude Code

claude mcp add sap-rfc -- python "c:\Users\Administrator\Desktop\MCP_SAP_PRIVATE\mcp\server.py"

Or add to your MCP client config:

{
  "mcpServers": {
    "sap-rfc": {
      "command": "python",
      "args": ["c:\\Users\\Administrator\\Desktop\\MCP_SAP_PRIVATE\\mcp\\server.py"]
    }
  }
}

Safety

  • Read-only by default. Keep SAP_ALLOW_WRITE=false unless you intend to modify objects, and only enable writes against a DEV system.
  • Writes are saved INACTIVE — nothing goes live until you activate it in SAP.
  • Use an RFC user with the minimum authorizations required.
  • .env holds credentials — it is git-ignored; never commit it.

Verified on

Read tools (sap_ping, sap_read_table, sap_read_program, sap_read_function_module, sap_read_class, sap_search_objects) verified end-to-end against an S/4HANA system (SAP_BASIS 758) reached through a SAProuter. Class source uses the remote-enabled SIW_RFC_READ_CLIF_SOURCE.

Caveats / limits over pure RFC

  • Only remote-enabled function modules are callable over RFC. Many workbench FMs (e.g. the SEO_* class APIs, the ABAP SYNTAX-CHECK) are not RFC- enabled, so some ADT-style features simply aren't reachable this way.
  • CDS/DDL source read is not available over pure RFC on the tested system — there is no remote-enabled FM that returns DDL source text. Use ADT for that.
  • Object activation and syntax check are likewise not wired up: no clean remote-enabled FM was found on the tested release. Writes therefore stay INACTIVE; activate in SAP GUI/ADT.
  • RFC_READ_TABLE cannot select rows wider than 512 bytes or long/deep fields; long WHERE clauses are auto-wrapped to the 72-char OPTIONS line limit.
  • FM availability/interfaces can still vary by release — validate on your target.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选