S/4HANA MCP Server
S/4HANA MCP Server
一个 MCP 服务器,通过 OData V2、OData V4 和 SOAP 为 SAP S/4HANA(云公共版和本地私有版)提供 38 个工具:业务伙伴、产品、销售定价、仓库、采购订单、采购信息记录、供应商发票(包括过账和取消)、服务输入表、日记账分录、成本中心和财务组织结构。
写入工具(create_*、cancel_supplier_invoice、check_invoice_posting_readiness)和 get_finance_structure 会将其结果以内联 JSON 形式返回。其他所有(读取)工具将其结果——集合用 CSV,单条记录用 Markdown——写入 E2B 沙箱,并返回文件路径,而不是将可能很大的 SAP 结果集(数百个业务伙伴、完整的日记账分录项目明细等)直接内联到调用代理的上下文中。此服务器仅连接到您的 MCP 客户端已拥有的 E2B 沙箱——它从不创建沙箱。 您的客户端需要自己的 E2B 集成(E2B SDK,或具有匹配代码执行访问权限的 Claude 环境)来读回文件;请参阅 E2B 沙箱设置。
快速开始
git clone https://github.com/ilia-inovaflow/s4hana-mcp-server.git
cd s4hana-mcp-server
npm install
npm run build
cp .env.example .env # fill in your E2B sandbox + SAP connection details
npm start # stdio transport (Claude Desktop, MCP Inspector, etc.)对于不先构建的本地开发:npm run dev。
Related MCP server: SAP OData MCP Server
E2B 沙箱设置
在 e2b.dev 注册免费 API 密钥,然后启动(或重用)您的 MCP 客户端可以从中读取文件的沙箱,并设置:
E2B_API_KEY=<your E2B API key>
SANDBOX_ID=<an already-running sandbox ID> # stdio only — HTTP takes this per-session在 HTTP 传输中,SANDBOX_ID 改为通过 sandbox-id 请求头按会话提供——当单个运行中的服务器实例处理多个调用方(每个都有自己的沙箱)时非常有用。
这与下面 SAP 自己的 sandbox.api.sap.com 试用主机无关——本 README 中的“沙箱”指两种不同的东西。
在没有自己的 SAP 租户的情况下试用
SAP 在 sandbox.api.sap.com 发布了一个免费、公开的只读 API 沙箱,此服务器开箱即用即可与之通信。在 api.sap.com 注册免费 API 密钥,然后设置:
SAP_HOST=https://sandbox.api.sap.com
SAP_CLIENT_ID=<your sandbox API key>无需用户名、密码或 OAuth 设置——沙箱使用单个 APIKey 标头进行身份验证。业务伙伴、产品和定价工具可立即针对沙箱演示数据工作(您仍然需要上面的 E2B 沙箱来接收读取工具的结果)。
连接真实的 SAP 租户
将 SAP_HOST 设置为您的租户 URL,并通过 SAP_AUTH_MODE 选择三种身份验证模式之一:
模式 | 使用场景 | 必需变量 |
| 快速测试,未配置 OAuth 的本地系统 |
|
| S/4HANA 云公共版,服务到服务(OAuth 2.0 客户端凭据) |
|
| 用户委托的 OAuth 授权码——仅 HTTP 传输,调用方通过 | 无(令牌来自 MCP 客户端) |
SAP_CLIENT(SAP 客户端/委托编号,例如 100)如果未设置,则默认为 100。
两个 API 系列按 SAP 设计需要基本或 X.509 身份验证,并拒绝 OAuth:日记账分录过账(create_journal_entry,SOAP SAP_COM_0002)和会计凭证明细视图(get_journal_entry,search_journal_entries 且 document_level=true)。其他所有内容在三种模式下均可工作。
请参阅 .env.example 获取完整变量列表,包括某些本地 SOAMANAGER 配置需要的可选 SAP_JE_SOAP_PATH 覆盖。
传输
stdio(默认,npm start / npm run dev)——每个进程一个 SAP 连接和一个 E2B 沙箱,完全从 .env 配置。这是 Claude Desktop 和大多数本地 MCP 客户端所期望的:
{
"mcpServers": {
"s4hana": {
"command": "node",
"args": ["/absolute/path/to/s4hana-mcp-server/dist/index.js"],
"env": {
"E2B_API_KEY": "...", "SANDBOX_ID": "...",
"SAP_HOST": "...", "SAP_AUTH_MODE": "basic", "SAP_USERNAME": "...", "SAP_PASSWORD": "..."
}
}
}
}Streamable HTTP(npm run start:http / npm run dev:http)——用于远程或多租户部署。每个会话的 SAP 连接要么从 .env 默认值配置,要么从每个请求的标头(sap-host、sap-auth-mode、sap-username、sap-password、sap-token-url、sap-client-id、sap-client-secret、sap-client、sap-je-soap-path)配置,其 E2B 沙箱从 sandbox-id 标头(或回退到 SANDBOX_ID 环境变量)配置——让一个运行中的服务器处理针对不同租户和沙箱的请求。E2B_API_KEY 始终从服务器自身环境读取。PORT(默认 3000)和 HOST(默认 localhost)配置监听器;MCP 端点为 POST /mcp,GET /health 用于存活检查。
如果您将 HTTP 传输部署到网络可达的位置,请将其放在您自己的身份验证/网络边界之后——此服务器本身不限制对 /mcp 端点的访问,仅限制对下游 SAP 连接的访问。
工具
search_business_partners— 搜索客户、供应商、人员、组织get_business_partner— 单个业务伙伴的完整详情query_business_partner_odata— 针对任何API_BUSINESS_PARTNER实体集的通用查询
search_products— 搜索物料、成品、服务、原材料get_product— 单个产品的完整详情query_product_odata— 针对任何API_PRODUCT_SRV实体集的通用查询
get_product_pricing— 物料的组合价格查找(从“X 多少钱”开始)search_pricing_conditions— 按类型/费率浏览条件记录get_pricing_condition— 单个条件记录的完整详情query_pricing_odata— 针对任何定价实体集的通用查询
list_warehousesget_warehouse
search_purchase_ordersget_purchase_orderquery_purchase_order_odata— 通用查询,包括项目/计划行级别get_purchase_order_confirmations— 供应商订单/发货/收货确认,批量查找
search_purchasing_info_recordsget_purchasing_info_recordquery_purchasing_info_record_odata
search_supplier_invoicesget_supplier_invoicequery_supplier_invoice_odatacreate_supplier_invoice_po⚠️ 写入 — 引用采购订单的三向匹配发票create_supplier_invoice_gl⚠️ 写入 — 非采购订单费用发票,直接 G/L 行create_supplier_credit_memo⚠️ 写入 — 引用采购订单的贷项凭证cancel_supplier_invoice⚠️ 写入 — 冲销已过账的发票或贷项凭证check_invoice_posting_readiness— 只读预检保护检查
search_service_entry_sheetsget_service_entry_sheetquery_service_entry_sheet_odata
create_journal_entry⚠️ 写入 — 过账 G/L 凭证(仅 SOAP,基本/X.509 身份验证)search_journal_entries— 分析(聚合)或会计凭证(行级)视图get_journal_entry— 按编号获取一个会计凭证search_gl_accountssearch_open_po_items— 一次调用获取供应商仍可开票的采购订单行search_cost_centersget_cost_center_hierarchy— 标准成本中心层次结构树get_finance_structure— 公司代码、分类账、会计科目表、段、业务范围
每个写入工具在过账前都会运行服务器端保护检查(存在性、阻止标志、重复检测、余额验证),并在任何保护失败时报告结构化原因列表——不向 SAP 发送任何内容。确定性的 SAP 拒绝(过账期间已关闭、缺少税务管辖权等)会被转换为可操作的消息,而不是原始错误代码。
架构
src/
├── server.ts # McpServer factory — tool registration, schemas, annotations
├── client.ts # SapClient — OData V2/V4 requests, CSRF-protected writes, SOAP posts
├── auth.ts # Auth strategies: Basic, OAuth Client Credentials, OAuth Authorization Code
├── config.ts # Connection config + SAP public sandbox detection
├── index.ts # stdio entry point
├── http.ts # Streamable HTTP entry point (Express, per-session auth)
└── tools/
├── shared.ts # OData/CSV/error-parsing + E2B sandbox file I/O, shared by every tool
└── *.ts # one file per tool (schema + handler)对 OData V2 端点的写入遵循 SAP 的 CSRF 令牌协议:通过 GET 使用 X-CSRF-Token: Fetch 获取令牌,在 POST 时与会话 cookie 一起重新发送,在 403 时重试一次。日记账分录过账则构建并发送原始 SOAP 信封,因为该 API 没有 OData 等效项。
开发
npm run dev # stdio, hot reload via tsx
npm run dev:http # HTTP, hot reload via tsx
npm run typecheck # tsc --noEmit
npm run build # compile to dist/许可证
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables interaction with SAP ABAP systems through ABAP Development Tools (ADT), providing access to repository objects, source code, where-used analysis, and SQL queries with support for both on-premise and BTP systems.2
- FlicenseAqualityDmaintenanceEnables AI assistants to integrate with SAP systems via OData REST APIs for querying entity sets, performing CRUD operations, and executing function imports. It features automatic service discovery, CSRF token management, and smart connection handling without requiring the SAP RFC SDK.1112
- FlicenseAqualityCmaintenanceEnables interaction with SAP S/4HANA systems via OData, allowing service discovery, metadata exploration, field value retrieval, and CRUD operations through natural language.45
- FlicenseNot gradedqualityDmaintenanceEnables querying ABAP programs, classes, function modules, and other objects from SAP systems with OAuth 2.0 authentication.
Related MCP Connectors
Search, document and execute authenticated API calls across 700+ apps via one MCP server
34 production API tools over one hosted MCP endpoint.
Run SOQL queries to explore and retrieve Salesforce data. Access accounts, contacts, opportunities…
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/ilia-inovaflow/s4hana-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server