@mcp-abap-adt/proxy

@mcp-abap-adt/proxy

MCP proxy server for SAP ABAP ADT that adds JWT authentication and forwards requests to target MCP servers.

Category
访问服务器

README

@mcp-abap-adt/proxy

Stand With Ukraine

MCP proxy server for SAP ABAP ADT - proxies local requests to MCP servers with JWT authentication.

Overview

This package acts as a simple proxy between local MCP clients (like Cline) and any MCP server. It intercepts MCP requests, adds JWT authentication tokens, and forwards them to the target MCP server. The MCP server URL is obtained from the service key for the BTP destination.

Purpose

Enable local MCP clients to connect to remote MCP servers with automatic JWT token management via @mcp-abap-adt/auth-broker. The proxy adds authentication headers and forwards requests transparently.

Features

  • ✅ JWT Token Management - Automatic token retrieval, caching, and refresh via auth-broker
  • ✅ Service Key Based - MCP server URL is obtained from service key for BTP destination
  • ✅ Error Handling - Retry logic, circuit breaker, and comprehensive error handling
  • ✅ Multiple Transport Modes - HTTP, SSE, and stdio support
  • ✅ Configuration Flexibility - Environment variables, config files, or defaults

Quick Start

Installation

npm install -g @mcp-abap-adt/proxy

Basic Usage

# Start proxy server (in-memory session storage, secure)
mcp-abap-adt-proxy

# With BTP destination
mcp-abap-adt-proxy --btp=ai

# Enable file-based session storage (persists tokens to disk)
mcp-abap-adt-proxy --btp=ai --unsafe

Configuration

The proxy supports multiple configuration methods:

  • Command-line parameters (highest priority)
  • YAML/JSON configuration files - See YAML Configuration Guide
  • Environment variables
  • Default values (lowest priority)

Quick Example (YAML config):

# Copy example config from documentation
cp docs/mcp-proxy-config.example.yaml mcp-proxy-config.yaml

# Edit mcp-proxy-config.yaml with your settings

# Run with config file
mcp-abap-adt-proxy --config=mcp-proxy-config.yaml
# Or short form:
mcp-abap-adt-proxy -c mcp-proxy-config.yaml

Client Configuration

For detailed setup instructions for Cline and GitHub Copilot, see the Client Setup Guide.

Quick Example (Cline):

{
  "mcpServers": {
    "mcp-abap-adt-proxy": {
      "disabled": false,
      "timeout": 60,
      "type": "streamableHttp",
      "url": "http://localhost:3001/mcp/stream/http",
      "headers": {
        "x-sap-destination": "btp-cloud"
      }
    }
  }
}

Required Headers:

  • x-sap-destination - Destination name for BTP Cloud authorization token and MCP server URL

Command Line Overrides:

  • --btp=<destination> - Overrides x-sap-destination header (takes precedence)
  • --url=<url> - Overrides MCP server URL (required if service key lacks URL)
  • --browser=<browser> - Browser to use: system (default), chrome, edge, firefox, headless
  • --browser-auth-port=<port> - Port for OAuth2 callback (default: 3333)
  • --unsafe - Enables file-based session storage (persists tokens to disk). By default, sessions are stored in-memory (secure, lost on restart)

Default Headers:

MCP clients like Cline and Claude Code cannot set arbitrary request headers. Use default headers to inject SAP-specific headers (e.g. x-sap-destination, x-sap-client) that the target MCP server requires.

Precedence: client-supplied request headers always win over defaultHeaders. Authorization is the exception — it is always managed by the proxy (replaced with the destination JWT) and cannot be set via defaultHeaders.

Via YAML config (defaultHeaders map):

btpDestination: mcp
targetUrl: https://example.com
defaultHeaders:
  x-sap-destination: S4HANA_E19
  x-sap-client: "100"

Per-user ABAP credentials. defaultHeaders is the supported place to supply your own SAP login/password for on-premise / NoAuthentication destinations. The upstream cloud-llm-hub is a shared server with no default service user, so it expects each caller's own x-sap-login / x-sap-password on every request. Because the proxy runs locally on each user's machine, it carries your identity.

Do not hardcode secrets. Reference environment variables with ${VAR} (or ${VAR:-default}); values are resolved from process.env or an explicitly-pointed .env file:

btpDestination: mcp
envFile: secrets.env            # resolved relative to this config file's dir
defaultHeaders:
  x-sap-destination: S4HANA_E19
  x-sap-login: ${SAP_USER}
  x-sap-password: ${SAP_PASSWORD}

secrets.env (user-local, chmod 600, never committed):

SAP_USER=MY_SAP_USER
SAP_PASSWORD=my-sap-password

Resolution order is process.env → .env → ${VAR:-default}. process.env wins; an unresolved ${VAR} without a default fails the proxy at startup. Override the .env path at launch with --env-file <path>. This closes both auth layers from one local config: the service layer (Authorization: Bearer <JWT>, from the destination service key) and the ABAP layer (x-sap-login / x-sap-password).

Via CLI (--header, repeatable):

mcp-abap-adt-proxy --btp=mcp --url=https://example.com \
  --header x-sap-destination=S4HANA_E19 \
  --header x-sap-client=100

How It Works:

The proxy uses BTP/XSUAA authentication:

  1. BTP Authentication (if --btp or x-sap-destination is present):
    • Uses AuthorizationCodeProvider (browser-based OAuth2 flow)
    • Eager Authentication: Opens browser immediately on startup to get token
    • Injects/overwrites Authorization: Bearer <token> header
    • MCP server URL obtained from BTP destination service key OR injected via --url
    • Service key format: contains uaa (url, clientid, clientsecret)

BTP Authentication Mode (with --btp):

  1. Proxy starts → Opens browser for login (Eager Auth) → Gets/Refreshes JWT token
  2. x-sap-destination (or --btp) → Adds Authorization: Bearer <token> header
  3. MCP server URL obtained from service key OR --url parameter

Documentation

How It Works

The proxy performs the following steps for each request:

  1. Extract Headers: Reads x-sap-destination header
  2. Apply Command Line Overrides: --btp parameter overrides header (if provided)
  3. Validate Routing Requirements: Requires x-sap-destination/--btp
  4. BTP Authentication (if x-sap-destination or --btp is provided):
    • Uses AuthorizationCodeProvider (browser-based login)
    • Eagerly obtains token on startup (if configured via --btp)
    • Retrieves JWT token using cached refresh token or opens browser
    • Injects/overwrites Authorization: Bearer <token> header
  5. Get MCP Server URL:
    • From service key for x-sap-destination
  6. Forward Request: Sends request to MCP server URL with all injected headers
  7. Return Response: Forwards the response back to the client

Example Request Flow

Cline → Proxy (adds BTP token) → Target MCP Server → Proxy → Cline

The proxy is transparent - it only adds authentication headers and forwards requests.

Configuration

Configuration

Environment Variables

export MCP_HTTP_PORT=3001
export LOG_LEVEL=info
export MCP_PROXY_UNSAFE=true  # Enable file-based session storage (optional)
export AUTH_BROKER_PATH=~/.config/mcp-abap-adt  # Optional base path for service-keys/sessions

AUTH_BROKER_PATH is treated as a base directory. The proxy resolves:

  • service-keys from <AUTH_BROKER_PATH>/service-keys
  • sessions from <AUTH_BROKER_PATH>/sessions

Defaults when AUTH_BROKER_PATH is not set:

  • Unix/Linux/macOS: ~/.config/mcp-abap-adt/service-keys and ~/.config/mcp-abap-adt/sessions
  • Windows: %USERPROFILE%\\Documents\\mcp-abap-adt\\service-keys and %USERPROFILE%\\Documents\\mcp-abap-adt\\sessions

Configuration File

Create mcp-proxy-config.json:

{
  "httpPort": 3001,
  "logLevel": "info",
  "maxRetries": 3,
  "circuitBreakerThreshold": 5,
  "unsafe": false
}

Session Storage:

  • unsafe: false (default) - Session data stored in-memory (secure, lost on restart)
  • unsafe: true - Session data persisted to disk (tokens saved under the session store path)

See Configuration Guide for complete options.

Error Handling & Resilience

  • Retry Logic - Exponential backoff for failed requests
  • Circuit Breaker - Prevents cascading failures
  • Token Refresh - Automatic token refresh on expiration
  • Connection Pooling - Efficient resource management
  • Request Timeouts - Configurable timeout handling

Requirements

  • Node.js >= 18.0.0
  • npm >= 9.0.0

Testing Tools

Verify a BTP destination's service key and token retrieval:

npm run test-destination

See tools/README.md for the available scripts.

Development Status

✅ Core Features Complete

  • ✅ Project Setup & Foundation
  • ✅ Request Interception & Analysis
  • ✅ JWT Token Management & Proxy Forwarding
  • ✅ Configuration & Environment
  • ✅ Error Handling & Resilience
  • ✅ Testing Tools (tools/)
  • ✅ Documentation

🚧 Future Work

  • ⏳ Unit Tests
  • ⏳ Performance & Optimization
  • ⏳ Deployment & Publishing

See ROADMAP.md for details.

License

MIT

Links

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选