Labsco
GutjahrAI logo

SAP OData MCP Server

โ˜… 12

from GutjahrAI

An MCP server for integrating with SAP OData services, configured via environment variables.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedPaid serviceNeeds API keys

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

Available Tools

1. sap_connect

Connect to SAP OData service.

Parameters:

  • baseUrl (required): SAP OData service base URL
  • username (required): SAP username
  • password (required): SAP password
  • client (optional): SAP client number
  • timeout (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 service
  • entitySet (required): Name of the entity set
  • select (optional): Array of fields to select
  • filter (optional): OData filter expression
  • orderby (optional): OData orderby expression
  • top (optional): Number of records to return
  • skip (optional): Number of records to skip
  • expand (optional): Navigation properties to expand

5. sap_get_entity

Get a specific entity by its key values.

Parameters:

  • serviceName (required): Name of the OData service
  • entitySet (required): Name of the entity set
  • keyValues (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.

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

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

  1. Add tool definition in tool-definitions.ts
  2. Implement handler in handlers.ts
  3. Add route in server.ts switch statement
  4. Update types in types.ts if needed
  5. Build and test