Skip to content

BTP CloudFoundry Node.js MCP server for SAP OData services integration

License

lemaiwo/btp-sap-odata-to-mcp-server

Repository files navigation

SAP OData to MCP Server for BTPπŸš€

🎯 Project Goal

Transform your SAP S/4HANA or ECC system into a conversational AI interface by exposing all OData services as dynamic MCP tools. This enables natural language interactions with your ERP data:

  • "Show me 10 banks" β†’ Automatically queries the Bank entity with $top=10
  • "Update bank with ID 1 to have street number 5" β†’ Executes PATCH operation on Bank entity
  • "Create a new customer with name John Doe" β†’ Performs POST to Customer entity
  • "List all purchase orders from this week" β†’ Applies $filter for date range on PurchaseOrder entity

πŸ—οΈ Architecture Overview

graph TB
    A[AI Agent/LLM] --> B[MCP Client]
    B --> C[SAP MCP Server]
    C --> D[SAP BTP Destination]
    D --> E[SAP SAP System]
    
    C --> F[Dynamic Service Discovery]
    F --> G[OData Catalog API]
    C --> H[CRUD Tool Generation]
    H --> I[Entity Metadata Parser]
    
    style A fill:#e1f5fe
    style C fill:#f3e5f5
    style E fill:#e8f5e8
Loading

Core Components:

  1. πŸ” Service Discovery Engine: Automatically discovers all available OData services from SAP
  2. βš™οΈ Dynamic Tool Generator: Creates MCP tools for CRUD operations on each discovered entity
  3. πŸ”Œ MCP Protocol Layer: Full compliance with MCP 2025-06-18 specification
  4. 🌐 HTTP Transport: Session-based Streamable HTTP for web applications
  5. πŸ” BTP Integration: Seamless authentication via SAP BTP Destination service

✨ Key Features

🎨 Natural Language to OData

  • Smart Query Translation: Converts natural language to proper OData queries
  • Context-Aware Operations: Understands entity relationships and constraints
  • Parameter Inference: Automatically maps user intent to tool parameters

πŸ”„ Dynamic CRUD Operations

  • Read Operations: Entity sets with filtering, sorting, pagination
  • Create Operations: New entity creation with validation
  • Update Operations: Partial and full entity updates
  • Delete Operations: Safe entity deletion with confirmation

πŸš€ Production-Ready

  • Session Management: Automatic session creation and cleanup
  • Error Handling: Comprehensive error handling with user-friendly messages
  • Logging: Detailed logging for debugging and monitoring
  • Security: DNS rebinding protection, CORS, Helmet security

πŸ“Š Real-Time Metadata

  • Service Catalog: Live discovery of available services
  • Entity Schemas: Dynamic schema generation from OData metadata
  • Capability Detection: Automatic detection of CRUD capabilities per entity

πŸ›οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     β”‚    β”‚                           β”‚    β”‚                     β”‚
β”‚   πŸ€– AI Agent       β”‚    β”‚   πŸ–₯️  SAP MCP Server     β”‚    β”‚   🏒 SAP            β”‚
β”‚   - Claude          │◄──►│   - Service Discovery     │◄──►│   - OData Services  β”‚
β”‚   - GPT-4           β”‚    β”‚   - CRUD Tool Registry    β”‚    β”‚   - Business Logic  β”‚
β”‚   - Local LLMs      β”‚    β”‚   - Session Management    β”‚    β”‚   - Master Data     β”‚
β”‚                     β”‚    β”‚   - BTP Authentication    β”‚    β”‚                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                           β”‚                                       
                                           β–Ό                                       
                           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                          
                           β”‚                           β”‚                          
                           β”‚   ☁️  SAP BTP Platform    β”‚                          
                           β”‚   - Destination Service   β”‚                          
                           β”‚   - Connectivity Service  β”‚                          
                           β”‚   - XSUAA Security        β”‚                          
                           β”‚                           β”‚                          
                           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                          

🎯 Use Cases

πŸ“ˆ Business Intelligence Queries

User: "Show me top 10 customers by revenue this quarter"
β†’ Tool: r-CustomerService-Customer
β†’ Parameters: $filter, $orderby, $top

πŸ“ Data Maintenance

User: "Update supplier ABC123 to have status 'Active'"
β†’ Tool: u-SupplierService-Supplier
β†’ Parameters: SupplierId="ABC123", Status="Active"

πŸ“Š Analytical Insights

User: "How many open purchase orders are there?"
β†’ Tool: r-PurchaseOrderService-PurchaseOrder
β†’ Parameters: $filter=Status eq 'Open'&$count=true

πŸ”§ System Administration

User: "List all inactive users in the system"
β†’ Tool: r-UserService-User
β†’ Parameters: $filter=Status eq 'Inactive'

πŸ› οΈ Installation & Setup

Prerequisites

  • Node.js 18.x or higher
  • SAP S/4HANA or ECC system with OData services enabled
  • SAP BTP account with Destination and Connectivity services
  • TypeScript knowledge for customization

πŸš€ Usage Examples

Natural Language Queries

The MCP server automatically translates these natural language commands to the appropriate tool calls:

Natural Language Generated Tool Call OData Query
"Show me 10 banks" r-BankService-Bank GET /BankSet?$top=10
"Find banks in Germany" r-BankService-Bank GET /BankSet?$filter=Country eq 'DE'
"Update bank 123 name to ABC Corp" u-BankService-Bank PATCH /BankSet('123')
"Create a new customer John Doe" c-CustomerService-Customer POST /CustomerSet
"Delete order 456" d-OrderService-Order DELETE /OrderSet('456')

πŸ“‹ Available Tools

Tool Naming Convention

{operationAbbreviation}-{serviceId}-{entityName}

Where operationAbbreviation is:

  • r: read (query entities or get single entity)
  • c: create (create new entity)
  • u: update (update existing entity)
  • d: delete (delete entity)

Examples:

  • r-API_BUSINESS_PARTNER-BusinessPartner
  • c-API_CUSTOMER_MATERIAL_SRV-CustomerMaterial
  • u-API_SALES_ORDER_SRV-SalesOrder
  • d-API_SALES_ORDER_SRV-SalesOrder

CRUD Operations

Protocol Version: 2025-06-18

Supported Capabilities:

  • βœ… Tools with listChanged notifications
  • βœ… Resources with listChanged notifications
  • βœ… Logging with level control
  • βœ… Session Management for HTTP transport
  • βœ… Error Handling with proper error codes

Transport Support

  • βœ… Streamable HTTP (recommended)
  • βœ… Stdio for command line usage
  • βœ… Session-based with automatic cleanup
  • βœ… DNS Rebinding Protection

πŸ”’ Security & Authentication

SAP BTP Integration

  • Uses BTP Destination service for S/4HANA or ECC authentication
  • Supports Principal Propagation and OAuth2
  • Automatic token refresh and session management
  • Secure credential storage in BTP

HTTP Security

  • Helmet.js security headers
  • CORS protection with configurable origins
  • DNS rebinding attack prevention
  • Request rate limiting (configurable)

Session Security

  • Automatic session expiration (24h default)
  • Secure session ID generation
  • Session cleanup on server restart
  • Memory leak prevention

πŸ“š API Reference

Health Check

GET /health
{
  "status": "healthy",
  "activeSessions": 3,
  "discoveredServices": 25,
  "version": "2.0.0"
}

Server Info

GET /mcp
{
  "name": "btp-sap-odata-to-mcp-server",
  "protocol": { "version": "2025-06-18" },
  "capabilities": { "tools": {}, "resources": {} },
  "features": ["Dynamic service discovery", "CRUD operations"],
  "activeSessions": 3
}

Documentation

GET /docs
{
  "title": "SAP MCP Server API",
  "endpoints": {...},
  "mcpCapabilities": {...},
  "usage": {...}
}

🎬 Demo

See the MCP server in action:

MCP Demo

βš™οΈ Environment Variable: Disable ReadEntity Tool Registration

To disable registration of the ReadEntity tool for all entities in all services, set the following in your .env file:

DISABLE_READ_ENTITY_TOOL=true

This will prevent registration of the ReadEntity tool for all entities and services.

⚑ Quick Start

About

BTP CloudFoundry Node.js MCP server for SAP OData services integration

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published