SAP RFC MCP Server

SAP RFC MCP Server

An enterprise-grade MCP server that enables AI agents to execute SAP RFC functions and read business data securely through the Model Context Protocol.

Category
Visit Server

README

SAP RFC MCP Server

基于 Model Context Protocol (MCP) 的企业级 SAP RFC 连接器。本项目旨在为 AI 智能体(如 Claude Desktop, GPT-4, Cursor 等)提供安全、高效、上下文感知的 SAP 系统访问能力。通过标准化的 MCP 协议,Agent 可以像调用本地函数一样执行 SAP RFC 并检索业务数据。


🌟 项目亮点

  • 企业级安全:支持 Master Key 管理架构,具备动态令牌(Dynamic Tokens)生成、有效期管理及一键撤销功能。
  • 全链路追踪:身份感知的日志系统,每条日志均包含客户端 IP 和 Agent 身份,支持每日凌晨自动分割。
  • 智能表读取:内置数据缓冲区保护机制,自动处理 DATA_BUFFER_EXCEEDED 错误,支持大规模数据的迭代安全读取。
  • AI 优化元数据:提供详尽的函数接口定义、参数描述,并支持导出 RAG(检索增强生成)友好格式的知识库。
  • 高可用会话:支持智能会话复用,Agent 无需手动管理 Session ID,系统自动基于 Token 恢复活跃会话。

🚀 核心能力 (Tools)

本服务器向 MCP 客户端暴露了以下工具集,涵盖了从系统发现到数据操作的全流程:

1. 核心 RFC 交互

  • call_rfc_function: 动态调用任意 SAP RFC 函数,支持复杂嵌套结构的参数传递。
  • rfc_system_info: 获取 SAP 系统版本、协议、内核、数据库类型等元数据。
  • get_rfc_functions: 通过模糊匹配查询 SAP 系统中可用的远程调用函数。

2. 安全数据读取

  • read_table: 具备自动溢出保护的表读取工具,能根据 RFC 512 字节限制自动选择字段。
  • read_table_complete: 迭代读取模式,支持请求超过缓冲区限制的大量字段,自动分批处理。
  • get_table_structure: 检索 SAP 表的详细定义,包括字段技术属性和多语言描述。
  • test_table_access: 快速验证当前用户对特定表的读取权限及数据连通性。

3. 元数据管理

  • get_function_metadata: 获取函数的完整“说明书”,包括参数方向、类型、长度及多语言注释。
  • search_rfc_functions: 针对函数名和描述进行全文检索,帮助 Agent 发现合适的接口。
  • export_metadata_for_rag: 将 SAP 接口知识导出为 JSON,用于构建 Agent 的离线知识库。

� 运行模式

项目支持三种运行模式,满足不同场景下的集成需求:

  • HTTP 模式 (默认):基于 FastAPI 提供的 Streamable HTTP 传输,支持流式 (SSE) 响应,适用于远程 Agent 访问。
  • STDIO 模式:通过标准输入输出通信,适用于 Claude Desktop 等本地安装的 MCP 客户端。
  • 双模式 (Dual):同时开启 HTTP 和 STDIO,兼顾本地调试与远程服务。

📦 快速部署

1. 环境要求

  • Python: 3.9 或更高版本。
  • SAP NW RFC SDK: 必须安装 SAP 官方 SDK,并配置 SAPNWRFC_HOME 环境变量。

2. 安装

git clone <repo_url>
cd sap-rfc-mcp-server
python -m venv .venv
source .venv/bin/activate  # Windows 使用 .venv\Scripts\activate
pip install -e .

3. 配置

复制 .env.example.env 并填写您的 SAP 连接参数及安全密钥:

# SAP 连接
SAP_ASHOST=192.168.1.100
SAP_SYSNR=00
SAP_CLIENT=100
SAP_USER=YOUR_USER
SAP_PASSWD=YOUR_PASSWD

# 安全密钥
MCP_MASTER_KEY=admin-secret-key-2026

� 身份验证指南

服务器采用双层认证架构:

  1. 管理层 (Master):使用 MCP_MASTER_KEY 访问 /auth/* 接口,执行 Token 颁发。
  2. 业务层 (Agent):使用生成的动态 Token 访问 /mcp/* 接口调用 SAP 功能。

生成 Token 示例 (使用 Master Key)

POST /auth/token/generate
X-API-Key: admin-secret-key-2026
Body: {"agent_name": "Finance_Agent", "ttl_hours": 48}

📂 项目结构

sap_rfc_mcp_server/
├── auth.py                # 动态 Token 管理与持久化
├── server.py              # MCP 工具定义与处理核心逻辑
├── sap_client.py          # 底层 pyrfc 连接管理与池化
├── rfc_table_reader.py    # 增强型表数据安全读取逻辑
├── streamable_http_server.py # HTTP/SSE 传输层实现
├── logger.py              # 身份感知的自动切分日志系统
└── metadata_manager.py    # SAP 元数据分析与 RAG 优化

📖 更多文档


© 2026 SAP RFC MCP Server Team. Licensed under MIT.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured