SAP OData MCP Server
Enables 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.
README
SAP OData MCP Server
A Model Context Protocol (MCP) server for integrating SAP systems with AI assistants like Claude using OData REST APIs. This server provides tools for connecting to SAP OData services, querying entity sets, executing CRUD operations, and calling OData functions.
Features
- SAP OData Connectivity: Connect to SAP systems via OData REST APIs
- Smart Connection Handling: Properly handles SAP OData URL structures and 404 responses
- Service Discovery: Automatically discover available OData services via catalog or common service testing
- Entity Set Queries: Query any OData entity set with filtering, sorting, and pagination
- CRUD Operations: Create, Read, Update, and Delete operations on OData entities
- Function Imports: Execute OData function imports and custom functions
- CSRF Token Handling: Automatic CSRF token management for secure operations
- Modular Architecture: Clean, maintainable TypeScript codebase with separation of concerns
Prerequisites
- Node.js 18+
- SAP system with OData services enabled
- Network access to SAP OData endpoints
- SAP user credentials with appropriate authorizations
⚠️ Advantage: No SAP RFC SDK installation required! Uses standard HTTP/REST APIs.
Installation
Quick Setup
- Create the project:
mkdir sap-odata-mcp-server
cd sap-odata-mcp-server
mkdir src
-
Copy the source files from the artifacts to your
src/directory:src/index.ts- Entry pointsrc/server.ts- MCP server setupsrc/handlers.ts- Request handlerssrc/odata-client.ts- SAP OData clientsrc/tool-definitions.ts- Tool definitionssrc/types.ts- TypeScript types
-
Copy configuration files:
package.json- Dependencies and scriptstsconfig.json- TypeScript configuration.env.example- Environment variables template
-
Install dependencies:
npm install
- Configure environment:
cp .env.example .env
# Edit .env with your SAP details
- Build the project:
npm run build
Configuration
Environment Variables
Create a .env file with your SAP system details:
# Required SAP OData Configuration
SAP_ODATA_BASE_URL=https://your-sap-host:8000/sap/opu/odata/sap/
SAP_USERNAME=your-sap-username
SAP_PASSWORD=your-sap-password
# Optional Configuration
SAP_CLIENT=100
SAP_TIMEOUT=30000
SAP_VALIDATE_SSL=false # for development with self-signed certificates
SAP_ENABLE_CSRF=true
Claude Desktop Integration
Add to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"sap-odata": {
"command": "node",
"args": ["/full/path/to/your/sap-odata-mcp-server/dist/index.js"],
"env": {
"SAP_ODATA_BASE_URL": "https://your-sap-host:8000/sap/opu/odata/sap/",
"SAP_USERNAME": "your-username",
"SAP_PASSWORD": "your-password",
"SAP_CLIENT": "100",
"SAP_VALIDATE_SSL": "false"
}
}
}
}
Available Tools
1. sap_connect
Connect to SAP OData service.
Parameters:
baseUrl(required): SAP OData service base URLusername(required): SAP usernamepassword(required): SAP passwordclient(optional): SAP client numbertimeout(optional): Request timeout in milliseconds (default: 30000)validateSSL(optional): Validate SSL certificates (default: true)enableCSRF(optional): Enable CSRF token handling (default: true)
2. sap_get_services
Get list of available OData services with intelligent discovery.
3. sap_get_service_metadata
Get metadata for a specific OData service.
Parameters:
serviceName(required): Name of the OData service
4. sap_query_entity_set
Query an OData entity set with filtering, sorting, and pagination.
Parameters:
serviceName(required): Name of the OData serviceentitySet(required): Name of the entity setselect(optional): Array of fields to selectfilter(optional): OData filter expressionorderby(optional): OData orderby expressiontop(optional): Number of records to returnskip(optional): Number of records to skipexpand(optional): Navigation properties to expand
5. sap_get_entity
Get a specific entity by its key values.
Parameters:
serviceName(required): Name of the OData serviceentitySet(required): Name of the entity setkeyValues(required): Object with key-value pairs for entity keys
6. sap_create_entity
Create a new entity in an entity set.
7. sap_update_entity
Update an existing entity.
8. sap_delete_entity
Delete an entity.
9. sap_call_function
Call an OData function import.
10. sap_connection_status
Check current SAP OData connection status.
11. sap_disconnect
Disconnect from SAP OData service.
Usage Examples
Getting Started with Claude
Once configured, you can interact with SAP using natural language in Claude:
Connect to SAP:
Connect to SAP OData service at https://sap-host:8000/sap/opu/odata/sap/ using username DEVELOPER and password mypassword
Discover Available Services:
Get list of available OData services
Get Service Information:
Get metadata for service GWSAMPLE_BASIC
Query Data:
Query BusinessPartnerSet from GWSAMPLE_BASIC, select BusinessPartnerID and CompanyName, top 10
Advanced Filtering:
Query SalesOrderSet from ZSD_SALES_SRV, filter by CreationDate ge datetime'2024-01-01T00:00:00', order by CreationDate desc, top 20
Get Specific Records:
Get entity from MaterialSet in ZMM_MATERIAL_SRV with key Material = '000000000000000001'
Create New Records:
Create entity in CustomerSet with data: {"CustomerNumber": "1000", "CustomerName": "Test Customer", "Country": "US"}
OData Query Examples
Filtering:
$filter=MaterialType eq 'FERT' and CreationDate ge datetime'2024-01-01T00:00:00'
Selecting Fields:
$select=Material,MaterialDescription,MaterialType,BaseUnit
Sorting:
$orderby=CreationDate desc,Material asc
Pagination:
$top=50&$skip=100
Expanding Navigation Properties:
$expand=MaterialPlantData,MaterialSalesData
SAP System Requirements
Required SAP Components
- SAP NetWeaver 7.0 or higher
- SAP Gateway component activated
- OData services enabled and configured
Required SAP Authorizations
The SAP user needs these authorization objects:
- S_SERVICE: Service authorization for OData endpoints
- S_ICF: Internet Communication Framework authorization
- S_TCODE: Transaction authorization for BAPIs (if using function imports)
Activating OData Services
- Transaction SICF: Activate ICF services at
/sap/opu/odata - Transaction /IWFND/MAINT_SERVICE: Manage and activate OData services
- Transaction /IWFND/GW_CLIENT: Test OData service calls
Architecture
Modular Design
src/
├── index.ts # Entry point - starts the server
├── server.ts # MCP server setup and request routing
├── handlers.ts # Business logic for each tool
├── odata-client.ts # SAP OData HTTP client
├── tool-definitions.ts # MCP tool schemas
└── types.ts # TypeScript type definitions
Key Features
- Smart Connection Testing: Handles SAP's URL structure where base URLs return 404
- Service Discovery: Multiple methods to find available OData services
- Error Handling: Comprehensive error handling with helpful messages
- Type Safety: Full TypeScript support with proper interfaces
- CSRF Protection: Automatic CSRF token management for write operations
Troubleshooting
Common Issues
Connection Refused (Network Error)
- Verify SAP system is running and accessible
- Check hostname/port in SAP_ODATA_BASE_URL
- Verify firewall settings allow HTTP/HTTPS traffic
401 Unauthorized
- Check SAP_USERNAME and SAP_PASSWORD
- Verify user account is not locked
- Ensure user has S_SERVICE authorization
403 Forbidden
- Check user has required SAP authorizations
- Verify S_ICF authorization for OData paths
- Contact SAP administrator for permission review
404 Not Found
- This is normal for SAP OData base URLs without service names
- Verify OData services are activated (SICF transaction)
- Use service discovery to find available services
SSL Certificate Errors
- Set
SAP_VALIDATE_SSL=falsefor development - Install proper certificates for production
- Check certificate chain and expiration
Debug Mode
Enable detailed logging:
DEBUG=axios npm start
SAP System Verification
- Test OData URL in browser: Navigate to your SAP OData URL
- Check service activation: Transaction SICF →
/sap/opu/odata - Verify gateway services: Transaction /IWFND/MAINT_SERVICE
- Test with gateway client: Transaction /IWFND/GW_CLIENT
Security Best Practices
Production Deployment
- Use HTTPS for all SAP OData connections
- Store credentials securely - never hardcode passwords
- Create dedicated service users with minimal required permissions
- Enable CSRF protection for write operations
- Implement proper authorization in SAP for OData services
- Monitor access logs and set up alerting
- Regular security audits of user permissions
Network Security
- Use VPN or private networks for SAP access
- Implement IP restrictions where possible
- Enable SAP Gateway security features
- Use proper certificate management
Common SAP OData Services
Standard SAP Services
- GWSAMPLE_BASIC - Basic sample service for testing
- GWDEMO - Comprehensive demo service
- RMTSAMPLEFLIGHT - Flight booking demo
Business Services
- API_MATERIAL_SRV - Material Management
- API_BUSINESS_PARTNER - Business Partner Management
- API_SALES_ORDER_SRV - Sales Order Management
- API_PURCHASEORDER_PROCESS_SRV - Purchase Order Processing
Entity Sets by Module
- MM (Materials Management): MaterialSet, MaterialPlantDataSet
- SD (Sales & Distribution): SalesOrderSet, CustomerSet, PricingConditionSet
- FI (Financial Accounting): GeneralLedgerEntrySet, AccountingDocumentSet
- HR (Human Resources): EmployeeSet, OrganizationalUnitSet
Development
Available Scripts
# Build TypeScript
npm run build
# Start production server
npm start
# Development mode with auto-reload
npm run dev
# Code quality
npm run lint
npm run format
Adding New Features
- Add tool definition in
tool-definitions.ts - Implement handler in
handlers.ts - Add route in
server.tsswitch statement - Update types in
types.tsif needed - Build and test
Contributing
- Fork the repository
- Create a feature branch
- Make your changes with proper TypeScript types
- Test with a real SAP system
- Submit a pull request
License
MIT License - see LICENSE file for details.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。