sap-rfc-mcp-server

thupalo/sap-rfc-mcp-server

3.2

If you are the rightful owner of sap-rfc-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

A Model Context Protocol (MCP) server that integrates with SAP systems using RFC connections, enabling AI assistants and applications to interact with SAP functions.

Tools
2
Resources
0
Prompts
0

SAP RFC MCP Server

Python 3.9+ License: MIT Code style: black

A Model Context Protocol (MCP) server that provides seamless integration with SAP systems through RFC (Remote Function Call) connections. This server enables AI assistants and applications to interact with SAP functions, retrieve metadata, and perform operations with enhanced caching and version compatibility.

๐Ÿš€ Features

Core Functionality

  • SAP RFC Integration: Direct connection to SAP systems using pyrfc
  • MCP Server: Full Model Context Protocol implementation for AI assistant integration
  • HTTP Server: RESTful API for web-based integrations
  • Version-Aware: Automatic detection and compatibility with SAP R/3 4.5B through S/4HANA

Enhanced Metadata Management

  • Intelligent Caching: Persistent file-based cache with TTL and compression
  • Metadata Search: Fast text-based search through cached RFC function metadata
  • Bulk Operations: Parallel loading and processing of multiple functions
  • RAG Optimization: Export metadata in formats optimized for Retrieval-Augmented Generation

Advanced Development Tools

  • Port Management: Automatic port conflict detection and resolution
  • Smart Startup: Intelligent server startup with process management
  • VS Code Integration: Complete development environment with tasks and snippets
  • Table Access Tools: Enhanced SAP table operations with comprehensive error handling

Language Support

  • Multi-Language: Support for English, Polish, German, French, Spanish descriptions
  • Version-Aware Language Handling: Automatic detection of SAP version and appropriate language code mapping
  • Legacy Compatibility: Proper handling of single-letter language codes for older SAP systems (R/3 4.5B)

Security & Configuration

  • Interactive Security Manager: Secure credential setup with multiple storage methods (encrypted files, system keyring, environment variables)
  • Secure Configuration: Encrypted storage of SAP connection parameters with automatic method detection
  • Environment Variables: Support for secure credential management
  • Connection Pooling: Efficient connection management and reuse

๐Ÿ“‹ Requirements

System Requirements

  • Python 3.9 or higher
  • SAP NetWeaver RFC SDK (for pyrfc)
  • Access to SAP system with RFC connectivity

SAP System Compatibility

  • โœ… SAP R/3 4.5B and higher
  • โœ… SAP ECC 6.0/6.1
  • โœ… SAP ECC with Enhancement Packages
  • โœ… SAP S/4HANA (all versions)

๐Ÿ›  Installation

Automated Setup (Recommended)

# Clone the repository
git clone https://github.com/thupalo/sap-rfc-mcp-server.git
cd sap-rfc-mcp-server

# Automated development environment setup (includes SAP NetWeaver RFC SDK validation)
python tools/setup_dev.py

๐Ÿ” Enhanced Setup: The automated setup now includes comprehensive SAP NetWeaver RFC SDK validation and provides detailed troubleshooting guidance if prerequisites are not met.

Manual Installation

1. Install SAP NetWeaver RFC SDK

Download and install the SAP NetWeaver RFC SDK from SAP Service Marketplace:

2. Install Python Package
# Clone the repository
git clone https://github.com/thupalo/sap-rfc-mcp-server.git
cd sap-rfc-mcp-server

# Install dependencies
pip install -e .

# For development
pip install -e ".[dev]"
3. Configure SAP Connection

๐Ÿ” Recommended: Interactive Security Manager (Preferred Method)

The SAP Security Manager provides secure, interactive configuration with multiple storage options:

# Interactive setup with secure credential management
python -m sap_rfc_mcp_server.sap_security_manager setup

# Test your configuration with connection validation
python -m sap_rfc_mcp_server.sap_security_manager test

# View your security configuration status
python -m sap_rfc_mcp_server.sap_security_manager info

Available Security Methods:

  • Environment Variables: Direct system environment (always available)
  • .env Files: File-based configuration (requires python-dotenv)
  • System Keyring: OS credential manager (requires keyring package)
  • Encrypted Files: Password-protected encrypted storage (requires cryptography package)

๐Ÿ“„ Alternative: Manual .env Configuration

For quick setup or CI/CD environments, create a .env file in the project root:

# SAP Connection Parameters
SAP_ASHOST=your-sap-hostname
SAP_SYSNR=00
SAP_CLIENT=100
SAP_USER=your-username
SAP_PASSWD=your-password
SAP_LANG=EN

# Optional: Advanced Connection Settings
SAP_SAPROUTER=your-saprouter
SAP_POOL_SIZE=10
SAP_TRACE=0

๐Ÿ”„ Migration Between Methods

# Migrate from .env to encrypted storage
python -m sap_rfc_mcp_server.sap_security_manager migrate

๐Ÿš€ Quick Start

๐Ÿ” Secure Configuration Setup (Recommended)

# Interactive secure configuration with the Security Manager
python -m sap_rfc_mcp_server.sap_security_manager setup

# Test your SAP connection
python -m sap_rfc_mcp_server.sap_security_manager test

Smart Server Startup (Recommended)

# Intelligent startup with automatic port management
python tools/start_mcp_smart.py

# Alternative PowerShell startup
.\tools\start_sap_mcp_server.ps1 -Mode http -Port 8000

Manual Server Startup

MCP Server (for AI Assistants)
# Start the MCP server
python -m sap_rfc_mcp_server.server

# The server will be available via stdio for MCP clients
HTTP Server (for Web Applications)
# Start the HTTP server
python -m sap_rfc_mcp_server.http_server 127.0.0.1 8000

# Server will be available at http://localhost:8000
# API documentation at http://localhost:8000/docs

Port Management

# Check port availability
python tools/port_manager.py --suggest

# Check specific port
python tools/port_manager.py --check 8000

# Release MCP processes
python tools/port_manager.py --release-mcp 8000 8020

Python API Usage

from sap_rfc_mcp_server import SAPRFCManager, RFCMetadataManager

# Initialize SAP client
sap_client = SAPRFCManager()

# Call RFC function
result = sap_client.call_rfc_function(
    function_name="RFC_READ_TABLE",
    parameters={
        "QUERY_TABLE": "T001",
        "DELIMITER": "|",
        "ROWCOUNT": 10
    }
)

# Initialize metadata manager for enhanced capabilities
metadata_manager = RFCMetadataManager(
    connection_params=sap_client.config.to_connection_params()
)

# Get function metadata with caching
metadata = metadata_manager.get_function_metadata(
    "RFC_READ_TABLE",
    language="EN"
)

# Search for functions
search_results = metadata_manager.search_functions("table")

# Bulk load metadata
functions = ["RFC_READ_TABLE", "DDIF_FIELDINFO_GET", "RFC_GET_FUNCTION_INTERFACE_US"]
bulk_metadata = metadata_manager.bulk_load_metadata(functions, language="EN")

๐Ÿ“– Documentation

๐Ÿ“ Project Structure

sap-rfc-mcp-server/
โ”œโ”€โ”€ sap_rfc_mcp_server/     # Main application package
โ”œโ”€โ”€ tools/                  # Development tools and utilities
โ”‚   โ”œโ”€โ”€ start_mcp_smart.py         # Smart server startup
โ”‚   โ”œโ”€โ”€ port_manager.py            # Port management utility
โ”‚   โ”œโ”€โ”€ sap_dev_helper.py          # Development helper tools
โ”‚   โ”œโ”€โ”€ setup_dev.py               # Environment setup
โ”‚   โ””โ”€โ”€ README.md                  # Tools documentation
โ”œโ”€โ”€ docs/                   # Technical documentation
โ”‚   โ”œโ”€โ”€ VSCODE_INTEGRATION_GUIDE.md
โ”‚   โ”œโ”€โ”€ PORT_MANAGEMENT_GUIDE.md
โ”‚   โ”œโ”€โ”€ TABLE_ACCESS_REPAIR_SUMMARY.md
โ”‚   โ””โ”€โ”€ README.md                  # Documentation index
โ”œโ”€โ”€ tests/                  # Unit and integration tests
โ”œโ”€โ”€ examples/               # Usage examples
โ””โ”€โ”€ README.md              # This file

๐Ÿ› ๏ธ Development Tools

  • - Complete guide to development utilities
  • - Server and port management
  • - Development environment setup

๐Ÿ“š Technical Documentation

  • - Complete documentation overview
  • - SAP table operations
  • - Project achievements

๐Ÿงช Testing

Automated Testing

# Test development tools
python tools/sap_dev_helper.py --system-info
python tools/sap_dev_helper.py --test-table T000

# Run unit tests
pytest tests/

# Run with coverage
pytest --cov=sap_rfc_mcp_server

Development Environment Testing

# Test VS Code integration
python tools/test_vscode_integration.py

# Verify SAP connection
python tools/test_direct_sap.py

# Test MCP server functionality
python tools/test_metadata_stdio.py

๏ฟฝ๏ธ VS Code Integration (MCP 2025)

The SAP RFC MCP server integrates natively with VS Code through the Model Context Protocol for enhanced AI-assisted development.

Quick VS Code Setup

# Automated setup creates .vscode/mcp.json configuration
python tools/setup_dev.py

Manual VS Code MCP Configuration

Create .vscode/mcp.json in your workspace:

{
  "servers": {
    "sap-rfc-server": {
      "command": "./venv/Scripts/python.exe",
      "args": ["-m", "sap_rfc_mcp_server.server"],
      "cwd": "./",
      "env": {
        "SAP_RFC_MCP_CONFIG": "./.env"
      }
    }
  }
}

Features Available in VS Code

  • ๐Ÿค– Agent Mode Integration: SAP tools available to VS Code's built-in agent
  • ๐Ÿง  GitHub Copilot Enhancement: Copilot can access SAP data and metadata
  • ๐Ÿ“ Workspace-Specific: MCP configuration isolated per workspace
  • ๐Ÿ” Auto-Discovery: VS Code automatically loads MCP servers on workspace open

Usage in VS Code

  1. Open workspace with .vscode/mcp.json configuration
  2. Enable GitHub Copilot agent mode (if using Copilot)
  3. Ask questions like:
    • "Get SAP system information"
    • "Search for SAP functions containing 'USER'"
    • "Show metadata for RFC_READ_TABLE function"
    • "List SAP tables starting with 'T0'"

๐Ÿ“– Complete Guide: See for detailed setup instructions.

๏ฟฝ๐Ÿ”ง Development

Quick Development Setup

# Automated setup (recommended)
python tools/setup_dev.py

# Manual VS Code setup
code .  # Open in VS Code
# Select Python interpreter: ./venv/Scripts/python.exe

Development Tools Usage

# Security configuration management
python -m sap_rfc_mcp_server.sap_security_manager --help

# Port management
python tools/port_manager.py --help

# Development helpers
python tools/sap_dev_helper.py --help

# Smart server startup
python tools/start_mcp_smart.py

Code Quality

# Install development dependencies
pip install -e ".[dev]"

# Run code formatting
black sap_rfc_mcp_server tests
isort sap_rfc_mcp_server tests

# Type checking
mypy sap_rfc_mcp_server

Project Structure

sap-rfc-mcp-server/
โ”œโ”€โ”€ sap_rfc_mcp_server/         # Main package
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ server.py               # MCP server implementation
โ”‚   โ”œโ”€โ”€ http_server.py          # HTTP server implementation
โ”‚   โ”œโ”€โ”€ sap_client.py           # SAP RFC client
โ”‚   โ”œโ”€โ”€ metadata_manager.py     # Enhanced metadata management
โ”‚   โ”œโ”€โ”€ metadata_cache.py       # Persistent caching system
โ”‚   โ”œโ”€โ”€ config.py               # Configuration management
โ”‚   โ”œโ”€โ”€ secure_config.py        # Secure configuration handling
โ”‚   โ””โ”€โ”€ sap_security_manager.py # Interactive security manager with multiple storage methods
โ”œโ”€โ”€ tests/                      # Test suite
โ”œโ”€โ”€ examples/                   # Usage examples
โ”œโ”€โ”€ docs/                       # Documentation
โ”œโ”€โ”€ cache/                      # Default cache directory
โ”œโ”€โ”€ pyproject.toml             # Project configuration
โ”œโ”€โ”€ README.md                  # This file
โ”œโ”€โ”€ LICENSE                    # MIT License
โ””โ”€โ”€ CHANGELOG.md              # Version history

๐Ÿ“Š Performance

Caching Benefits

  • First Call: Direct SAP RFC call (~200-500ms)
  • Cached Call: File-based cache retrieval (~1-5ms)
  • Search: Indexed text search (~1-10ms)
  • Bulk Operations: Parallel processing with connection pooling

Memory Usage

  • Base Server: ~50MB
  • With Cache: +10-50MB (depending on cached functions)
  • Connection Pool: +5-20MB per connection

๐Ÿค Contributing

We welcome contributions! Please see our for details.

Development Workflow

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite (pytest)
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the file for details.

๐Ÿ†˜ Support

Common Issues

Getting Help

๐Ÿ”„ Changelog

See for a list of changes and version history.

๐Ÿ† Acknowledgments

  • SAP AG for the RFC SDK and documentation
  • The pyrfc project for Python RFC connectivity
  • The Model Context Protocol community
  • All contributors who have helped improve this project

Note: This is not an official SAP product. SAP and other SAP products mentioned herein are trademarks or registered trademarks of SAP SE in Germany and other countries.