npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mcp-abap-adt/connection

v25.2.2

Published

ABAP connection layer for MCP ABAP ADT server

Readme

@mcp-abap-adt/connection

Stand With Ukraine

ABAP connection layer for MCP ABAP ADT server. Provides a unified interface for connecting to SAP ABAP systems via ADT (ABAP Development Tools) protocol, supporting both on-premise (Basic Auth) and cloud (JWT/OAuth2) authentication methods.

Key Features

  • 🔐 Multiple Authentication Methods:
    • Basic Auth for on-premise SAP systems
    • JWT/OAuth2 for SAP BTP ABAP Environment
    • SAML session cookies for pre-authenticated enterprise flows
  • 🔄 Token Management:
    • Token refresh is handled by @mcp-abap-adt/auth-broker package
    • Connection package focuses on HTTP communication only
  • 💾 Session Management:
    • Session headers management (cookies, CSRF tokens)
    • Session state persistence is handled by @mcp-abap-adt/auth-broker package
  • 🏗️ Clean Architecture:
    • One connector per SYSTEM (AdtOnPremConnector, AdtCloudConnector), handed an auth provider
    • Authentication is a parameter, not a subclass — nothing about the system is inferred from it
    • Proper separation of concerns - no JWT logic in base class
  • 🔌 Realtime Transport Scaffold:
    • Generic GenericWebSocketTransport with pluggable WS factory
    • Reusable for debugger/traces and other event-driven flows
  • 📝 Custom Logging: Pluggable logger interface for integration with any logging system
  • 📦 TypeScript: Full TypeScript support with type definitions included
  • ⏱️ No built-in deadline: a request carries the caller's own timeout and nothing else — inside a critical section, none at all

Architecture

The package uses a clean separation of concerns:

  • AbstractAbapConnection (abstract, internal only):

    • Common HTTP request logic
    • Session lifecycle: connect() / disconnect() / flushGoodbye(), admission, lock windows, teardown draining
    • Capability atoms a consumer narrows to, rather than casting to a connector class: ISessionLifecycleAware, ICriticalSection, IRequestProfiling
    • Session management (cookies, CSRF tokens)
    • CSRF token fetching with retry
    • Auth-agnostic - knows nothing about Basic or JWT
  • AdtOnPremConnector (concrete, exported):

    • An on-prem system: the session arrives with the establishing call, and the platform's ICF logoff is how it is given back
    • Takes an auth provider — basic, SAML, certificate, a bearer token, whatever you hold
  • AdtCloudConnector (concrete, exported):

    • An ABAP Cloud system: a session is a resource, opened at /sap/bc/adt/core/http/sessions and given back through the logoff resource its answer links to, or the platform's ICF logoff when it links none (a DELETE on the session's own address answers 200 and ends nothing)
    • Takes an auth provider, same as above

    Which one you take is how you say where you are dialling. Nothing is probed: the session resource answers on on-prem too, so its answer says nothing about which system this is.

  • Auth providers (an IAuthProvider from @mcp-abap-adt/interfaces-auth; the ready-made ones — BasicAuthProvider, TokenAuthProvider, SamlAuthProvider, CertificateAuthProvider — are in @mcp-abap-adt/auth-providers 6.0.0, not here):

    • What a connection authenticates with, passed in. The connection never asks what kind of provider it was given; it calls the same four methods on all of them: prepare once before the wire opens, establish at each logon, authorize before every attempt, rejected when the system refused
    • A 401 that survives the wire's own CSRF recovery, or a refused logon, is put to the provider through rejected. If it answers Ok (a renewed token, say) the request gets exactly one more attempt; if it says no, or the retry is refused too, you get an AuthRefusedError carrying the provider's refusal — an IAuthProviderError minted by @mcp-abap-adt/auth-errors, with a kind to decide on and the reason / hint words to show
    • Every answer is re-checked: a refusal that is not a minted error (a plain { reason } from a JavaScript provider) becomes "the credential provider failed" (connection / provider-threw), and its text reaches no message
  • Transports (OnPremHttpTransport, CloudHttpTransport, RfcTransport):

    • What a request travels over, and everything that is true of that wire. HttpTransport keeps the cookie jar, the CSRF token and the affinity headers; RfcTransport translates into SADT_REST_RFC_ENDPOINT and keeps a conversation that IS the session
    • On-prem is where this is a real choice; ABAP Cloud has one wire and its connector takes no such parameter
    • rfcConversationFrom(config) builds what RfcTransport needs from an RFC config's stated address, client and language — nothing derived, no URL — and loads the SDK only when a conversation opens. It reads no user or password: the provider writes the logon parameters
  • GenericWebSocketTransport (concrete, exported):

    • Transport abstraction for realtime WS message flows
    • Pluggable factory, envelope-based send/receive
    • Intended for higher-level debugger/trace session orchestration

Responsibilities and Design Principles

Core Development Principle

Interface-Only Communication: This package follows a fundamental development principle: all interactions with external dependencies happen ONLY through interfaces. The code knows NOTHING beyond what is defined in the interfaces.

This means:

  • Does not know about concrete implementation classes from other packages
  • Does not know about internal data structures or methods not defined in interfaces
  • Does not make assumptions about implementation behavior beyond interface contracts
  • Does not access properties or methods not explicitly defined in interfaces

This principle ensures:

  • Loose coupling: Connection classes are decoupled from concrete implementations in other packages
  • Flexibility: New implementations can be added without modifying connection classes
  • Testability: Easy to mock dependencies for testing
  • Maintainability: Changes to implementations don't affect connection classes

Package Responsibilities

This package is responsible for:

  1. HTTP communication with SAP systems: Makes HTTP requests to SAP ABAP systems via ADT protocol
  2. Authentication handling: Supports Basic Auth and JWT/OAuth2 authentication methods
  3. Session management: Manages cookies, CSRF tokens, and session state
  4. Error handling: Handles HTTP errors and connection issues

What This Package Does

  • Provides connection abstraction: AbapConnection interface for interacting with SAP systems
  • Handles HTTP requests: Makes requests to SAP ADT endpoints with proper headers and authentication
  • Manages sessions: Handles cookies, CSRF tokens, and session state persistence

What This Package Does NOT Do

  • Does NOT obtain tokens: Token acquisition is handled by @mcp-abap-adt/auth-providers and @mcp-abap-adt/auth-broker
  • Does NOT store tokens: Token storage is handled by @mcp-abap-adt/auth-stores
  • Does NOT refresh tokens: Token refresh is handled by @mcp-abap-adt/auth-broker
  • Does NOT orchestrate authentication: Token lifecycle management is handled by @mcp-abap-adt/auth-broker
  • Does NOT know about destinations: Destination-based authentication is handled by consumers
  • Does NOT handle OAuth2 flows: OAuth2 flows are handled by token providers

External Dependencies

This package interacts with external packages ONLY through interfaces:

  • Logger interface: Uses ILogger interface for logging - does not know about concrete logger implementation
  • No direct dependencies on auth packages: All token-related operations are handled through configuration (SapConfig) passed by consumers

The contracts themselves come from five packages, and with @mcp-abap-adt/auth-errors — the runtime that mints and classifies the auth errors — are the only runtime dependencies of this one besides axios:

| Package | What this package takes from it | |---|---| | @mcp-abap-adt/interfaces-adt-connection | IAbapConnection, IAbapRequestOptions, IAdtWireResponse, ITimeoutConfig, the capability atoms, ADT_SESSION_ERROR | | @mcp-abap-adt/interfaces-auth (7.x) | IAuthProvider, AuthOutcome, IAuthRefusal (= IAuthProviderError), IAuthRejection, ILogonTarget, IRequestTarget, ICertificateMaterial, ITokenRefresher, ITokenRefreshResult | | @mcp-abap-adt/interfaces-auth-sap | ISapConfig, SapAuthType, SapConnectionType, ICertificateMaterialLoader | | @mcp-abap-adt/interfaces-network | NETWORK_ERROR_CODES, the WebSocket contracts | | @mcp-abap-adt/interfaces-utils | ILogger | | @mcp-abap-adt/auth-errors | authError (the builders: every refusal is minted here), classifyOutcome |

Not @mcp-abap-adt/interfaces. That package is deleted as of its 52.0.0, which was never published: npm still serves 51.0.0 — every symbol re-exported and deprecated — to whoever is pinned to it, and nothing further ships there. This package stopped depending on it in 9.0.0; there is nothing left to move to but the packages above. See Migration to 9.0.0.

Documentation

  • 📦 Installation Guide - Setup and installation instructions
  • 📚 Usage Guide - Detailed usage examples and API documentation
  • 🚚 Migration to 25.0.0 - security: an error and a log line carry the failure's typed facts (code, status, rfc, SAP's answer as response), never a thrown value's text or a request config; the HTTP failure is not the axios error (no config, request, isAxiosError); AuthRefusedError.cause is a WireFailure copy
  • 🚚 Migration to 24.0.0 - on @mcp-abap-adt/interfaces-adt-connection ^5.0.0: IAbapConnection / AbapConnection's makeAdtRequest takes no type argument; drop it and narrow data from unknown; the connectors are unchanged
  • 🚚 Migration to 23.0.0 - a stateless request whose answer shows the SAP session replaced keeps that answer, marked sessionLost, and the instance is spent; a stateful request still rejects ADT_SESSION_REPLACED; nothing is resent; @mcp-abap-adt/interfaces-adt-connection ^4.2.0
  • 🚚 Migration to 22.0.0 - over RFC: a connection-ending RFC error on the stateful conversation is ADT_SESSION_REPLACED and spends the instance (no silent reconnect); a failed RFC call carries rfc: { key, group, code, codeString }; the SAP-PASSPORT header becomes the RFC call's passport; @mcp-abap-adt/sap-rfc-lite ^0.4.0
  • 🚚 Migration to 21.0.0 - the CSRF token fetch asks once: no retry, no delay; CSRF_CONFIG.RETRY_COUNT / RETRY_DELAY, the establish context's retries / retryDelayMs / isFatal, fetchCsrfToken's retry parameters and endsTheExchange are removed
  • 🚚 Migration to 20.0.0 - an RFC config is an ISapRfcConfig that states its address (ashost + sysnr, or mshost + msserv / sysid + group), client and language: no URL, no defaults, no SAP_SYSNR; getBaseUrl() may answer undefined; hand-built HTTP transports take baseUrl; IAdtSessionContext has no baseUrl
  • 🚚 Migration to 19.0.0 - @mcp-abap-adt/sap-rfc-lite ^0.3.2: no compile on install; prebuilt RFC bindings for linux-x64, win32-x64, darwin-arm64; elsewhere build sap-rfc-lite's binding from its repository; the API is unchanged
  • 🚚 Migration to 18.0.0 - rfcParamsFrom returns RfcAddress (application server or message server): narrow before reading .ashost / .sysnr; RFC through a message server and a logon group (mshost, msserv | sysid, group, saprouter)
  • 🚚 Migration to 17.0.0 - no deadline of the package's own: getTimeout, getTimeoutConfig and SAP_TIMEOUT_* are gone, and a request inside a critical section carries none at all; an instance can be built on an existing session (session, sessionCookies())
  • 🚚 Migration to 16.0.0 - the per-request signal (15.1.0) and ADT_REQUEST_ABORTED are removed; disconnect() resolves once the logoff is written, not answered — a process about to exit awaits it; flushGoodbye() when the answer matters
  • 🚚 Migration to 15.0.0 - on @mcp-abap-adt/interfaces-adt-connection 2: makeAdtRequest's answer is unknown unless its type is named; nothing changes at run time
  • 🚚 Migration to 14.0.0 - the sap-abap-auth CLI is removed, with its open and commander dependencies; use @mcp-abap-adt/auth-broker-cli; the library's API is unchanged
  • 🚚 Migration to 13.0.0 - interfaces-auth 7 and auth-errors 2, and the providers from auth-providers 6.0.0; no behaviour change, one interfaces-auth major per process
  • 🚚 Migration to 12.0.0 - refusals follow the auth error contract (interfaces-auth 6, auth-errors): AuthRefusedError.refusal is an IAuthProviderError — read its kind; a custom ILogonTarget mints its refusal; no auth-providers release fits 12.x — take 13.0.0 with auth-providers 6.0.0
  • 🚚 Migration to 11.0.0 - the server certificate is verified by default; trust a self-signed system with agentOptions.ca, or opt out explicitly
  • 🚚 Migration to 10.0.0 - the credential providers moved to @mcp-abap-adt/auth-providers; the connection speaks IAuthProvider 3.0; AuthRefusedError; the RFC factory takes the logon parameters
  • 🚚 Migration to 9.0.0 - the contracts split out of @mcp-abap-adt/interfaces; which package each one moved to
  • 🚚 Migration to 7.0.0 and 8.0.0 - request headers leave the stateful branch, the contracts floor moves, and flushGoodbye()
  • 🚚 Migration to 6.0.0 - the factory and the per-credential classes are removed; RFC is a transport, not a class
  • 🚚 Migration to 4.0.0 - a 401 refreshes the token, a 403 reaches you with the server's message; the synthesised "JWT token has expired" is gone
  • 🚚 Migration: the explicit session lifecycle - connect() is now required; start here if you are coming from 1.x
  • 💡 Examples - Working code examples

Features

  • 🔐 Multiple Authentication Methods: Basic Auth for on-premise systems, JWT/OAuth2 for SAP BTP ABAP Environment
  • 💾 Session Management: Session headers management (cookies, CSRF tokens) for HTTP communication
  • 📝 Custom Logging: Pluggable logger interface for integration with any logging system (optional)
  • 📦 TypeScript: Full TypeScript support with type definitions included
  • ⏱️ No built-in deadline: a request carries the caller's own timeout and nothing else — inside a critical section, none at all
  • 🌐 Network Error Detection: Automatic detection and proper handling of network-level errors (connection refused, timeout, DNS failures)

Installation

npm install @mcp-abap-adt/connection

That is everything you need to use the connectors. If your own code names a contract type — IAuthProvider for a credential you write, ISapConfig for a config you build — install the package it lives in as well, because this one no longer brings them along:

npm install @mcp-abap-adt/interfaces-adt-connection @mcp-abap-adt/interfaces-auth @mcp-abap-adt/interfaces-auth-sap

A provider or a logon target of your own answers refusals minted by @mcp-abap-adt/auth-errors (authError[kind](facts)); install it too. Keep one @mcp-abap-adt/interfaces-auth major in the process (npm ls @mcp-abap-adt/interfaces-auth).

The credential providers (BasicAuthProvider, TokenAuthProvider, SamlAuthProvider, CertificateAuthProvider) are not part of this package since 10.0.0. Install them from where they live:

npm install @mcp-abap-adt/auth-providers@^6

connection 13.x to 15.x work with auth-providers 6.0.0 (^6.0.0), the release built on interfaces-auth 7 and auth-errors 2, and are tested with it: the 5.x providers answer unbranded refusals and do not fit. See Migration to 13.0.0 and Migration to 12.0.0.

For detailed installation instructions, see Installation Guide.

Quick Start

The recommended way: createConnection

import { createConnection } from "@mcp-abap-adt/connection";
import type { SapConfig } from "@mcp-abap-adt/connection";
import { BasicAuthProvider } from "@mcp-abap-adt/auth-providers";

const config: SapConfig = {
  url: "https://your-sap-system.com",
  client: "100",
  authType: "basic",
  username: "your-username",
  password: "your-password",
};

// Which system, and which wire: both stated, never inferred.
//   cloud  + http          → AdtCloudConnector  + CloudHttpTransport
//   onprem + http          → AdtOnPremConnector + OnPremHttpTransport
//   onprem + legacy-http   → AdtOnPremConnector + LegacyOnPremHttpTransport (BASIS 7.40)
//   onprem + rfc           → AdtOnPremConnector + RfcTransport
const connection = createConnection({
  system: "onprem",
  transport: "http",
  config,
  credential: new BasicAuthProvider(config.username!, config.password!),
});

await connection.connect();
try {
  await connection.makeAdtRequest({
    method: "GET",
    url: "/sap/bc/adt/discovery",
    timeout: 0,
  });
} finally {
  await connection.disconnect(); // resolves once the logoff is written
}
// One instance is one SAP session: a new session is a new createConnection().

For modern HTTP connections, createConnection can retry a stateless ADT syntax check once on a temporary session when SAP rejects the CSRF token and the connection detects session replacement. The caller receives the retry result or the new logon's error. See Session Lifecycle.

createConnection returns a new instance on every call. Any other combination of system and wire (cloud over RFC, say) is refused at construction. The transport options are passed through as you give them: agentOptions and httpClient for the HTTP wires, rfc for the RFC wire, wireLogger for what the wire logs about itself, logger and sessionId for the connection. The constructors below remain available; the factory only names the four combinations that exist.

No deadline but yours. A request carries the timeout you pass and nothing else: no wire sets one of its own, because a client deadline closes the socket and SAP then ends the request running on it — a write in it lost. IAbapRequestOptions still requires the field; 0 is none over HTTP. Inside a critical section (beginCriticalSection()) a request carries none at all, not even yours.

Kept-alive connections, and the one resend (19.0.1). The HTTP wires pool their sockets over http: and https: alike (Node.js's global-agent options: keepAlive, lifo, an idle socket closed after 5 s; your agentOptions win over https:, so keepAlive: false there turns the pool off). A server may close an idle kept-alive connection just as a request is written onto it; that request is lost unread. So, as a named exception to "no retries": a request that went out on a socket taken from the pool, and whose socket ended with no byte of an answer read (ECONNRESET — "socket hang up" — or EPIPE), is sent once more, on a new connection, with the same cookies, session headers, CSRF token and body — the ABAP session and its locks are the cookies', not the socket's (measured on-premise, 2026-10-23). Nothing else is resent: not a request on a socket opened for it, not one that read any byte of an answer, not one after a redirect, not a stream body, not the logoff, and never a second time. The resend is visible only as a debug line in fixed words. The risk, stated: a server that read the request and died before writing a byte of its answer would run it twice; for a socket the server closed while it was idle, that does not happen. Without the resend, a cleanup UNLOCK died so and the enqueue lock stayed until SM12 (mcp-abap-adt#314).

Two more named resends (named in 21.0.0; the behaviour is older). Beside the one above, a request is sent once more in exactly two cases — each at most once for a request, never a second time:

  • The CSRF recovery. SAP refused the request over its CSRF token — a 403 "CSRF token validation failed", or an answer whose body names the CSRF token — or answered 401 to a POST, PUT or DELETE sent while the wire held no token. The wire fetches a token in the same session (its cookies kept; one fetch, no retry) and sends the request once more, authorized anew. Not a plain retry: the request was refused for what it carried — a stale or missing token — and goes again carrying something different, the fresh token; sent as it was, it would only be refused again. A resend that fails ends the request: a session verdict or the credential's refusal is thrown, anything else rethrows the error the recovery started from.
  • The credential's renewal. A 401, or a logon the system refused, goes to the provider (rejected()); when it answers Ok, the request — or the logon — is authorized again and sent once more, in the same session. Not a plain retry either: the provider renewed what the attempt carries, and the attempt carries the new credential. One per request: a second refusal is AuthRefusedError (refused again), and the provider is not asked twice. A 403 never goes to the provider.

Nothing else is sent again: a failed request — the CSRF token fetch included (21.0.0) — is its own error. A request with noResend: true (25.1.0) gets none of these three resends: see the request options below.

Request options: noResend, noLog, stateless

Since 25.1.0, optional flags of IAbapRequestOptions change one request and nothing else: noResend, noLog and stateless (@mcp-abap-adt/interfaces-adt-connection 5.2.0), since 25.2.0 rawText (5.3.0), and since 25.2.2 admitNotModified (5.3.1). A request without them behaves as before.

await connection.makeAdtRequest({
  method: "POST",
  url: "/sap/bc/adt/abapgit/repos",
  timeout: 0,
  data: "<repository/>",
  noResend: true, // the first failure is the answer
  noLog: true, // nothing of the request or its answer in a log
  stateless: true, // stateless whatever the session mode
});

// An abapGit file as the exact text SAP sent:
const file = await connection.makeAdtRequest({
  method: "GET",
  url: "/sap/bc/adt/abapgit/repos/R1/files/package.json",
  timeout: 0,
  rawText: true, // the body is the text, not parsed
});

// A conditional read: a 304 is the answer, not a refusal.
const etag = "<the ETag of the answer you hold>";
const source = await connection.makeAdtRequest({
  method: "GET",
  url: "/sap/bc/adt/oo/classes/zcl_x/source/main",
  timeout: 0,
  headers: { "If-None-Match": etag },
  admitNotModified: true, // 304: its headers, an empty body
});
  • noResend: true — the request is sent once. It gates every replay: the CSRF recovery, the resend after the credential's renewal (the provider is not asked), the resend on a dead pooled socket (the named exception above), and createConnection's replay of a syntax check on a temporary session. The CSRF token fetch before a mutation still happens, and goes once too: no renewal after a 401, no pooled-socket resend, no redirect followed, no fallback to /sap/bc/adt/discovery after a 404/501, and only a 2xx yields a token (a refusal carrying one does not). Its failure is the answer, and the request is then not sent. A redirect from SAP's ADT endpoint is not followed (maxRedirects: 0): a 3xx resolves as the answer, and every other status is refused as before. Use it for a request that may already have run when a resend would start: SAP refuses a bad CSRF token before any ADT resource handler runs, but the recovery also resends on any answer whose text holds CSRF token, which a handler's own 500 may carry after it ran.
  • noLog: true — no line holds the request's query, headers or body, or the answer's headers, status text or body: not the connection's request and refusal lines (no preview), not the CSRF-fetch and fence lines, not the HTTP wire's resend and application-server lines, not the RFC wire's URI, logWire headers and bodies, status text, conversation and cleanup lines. Exactly one line is written per request, by the connection: METHOD /path → STATUS (N bytes) for its answer or refusal — or METHOD /path → no answer — with the fields { method, path, status, bytes } — whatever path the request takes: a CSRF fetch that ends it before it is sent, a recovery, a session the answer shows lost (the loss reaches you as the error's sessionLost / SESSION_REPLACED, not as a warning, and the logoff it causes writes no line). The path is the URL's pathname for an absolute URL (no user, password or host), the path without its query or fragment for a relative one, and <unparsable url> for one that does not parse; in the path and the method, every code point that can break a line (C0, DEL, C1 with NEL, U+2028, U+2029) is written as \xNN or \uNNNN, so neither can forge a line. A syntax check createConnection replays on a temporary session writes nothing of its own: its logon, the replay and its logoff go unlogged. The wires write no line of their own about it, the application server an answer names included. Two fixed-word lines that name nothing of the request are the documented exceptions: the wire's CSRF token obtained, when a token is fetched for the request, and the cloud wire's The server published no logoff resource; sending the platform logoff, when an answer that replaced the session leads to its logoff. The error thrown keeps SAP's answer (response, status) for the caller.
  • stateless: true — the request goes stateless on HTTP and RFC whatever the session mode (setSessionType('stateful') included), and wins over the caller's own x-sap-adt-sessiontype: stateful header in any letter case: the wire strips that header and the sap-contextid cookie from the request (over RFC, the call goes on a conversation other than the stateful one). The session mode is not changed: the next ordinary request follows it.
  • rawText: true (25.2.0) — changes only the body you receive as the final answer: a success's data, or the response.data of the error you get, is the exact text SAP sent, a string — a JSON-object file is not an object, a JSON-string file keeps its quotes and its trailing newline, and a leading byte-order mark stays. Nothing inside the connection changes: the CSRF recovery, the session verdicts (a replacement cookie included), the replays, the credential provider (IAuthRejection.error), the log lines and the error's shape all read what the request without the flag reads, so the same answer gets the same handling either way. That guarantee is for the shipped HTTP client: a consumer that injects an httpClient configured with defaults of its own — transitional.forcedJSONParsing, responseType — owns how its bodies look, and with them what those consumers read. Over HTTP the body is received as bytes; the text is decoded in the charset the Content-Type declares when TextDecoder knows it, else UTF-8, the BOM kept, and non-fatally: a byte that is not text in that charset reads as U+FFFD — no error is raised for it. (SAP's abapGit file resource answers text/plain; charset=utf-8, already UTF-8 on SAP's side.) It applies on every send the request takes — the ordinary one, noResend, the CSRF recovery's resend, the dead-pooled-socket resend, createConnection's check replay — and to the refusal of the CSRF fetch made for a noResend request when that is the answer. A noLog line counts the bytes that arrived; nothing else of it changes. Over RFC the body is already the UTF-8 text of MESSAGE_BODY, never parsed, with or without the flag.
  • admitNotModified: true (25.2.2) — a 304 Not Modified is your answer, with its headers and an empty body, instead of a refusal: SAP's answer to a conditional read (If-None-Match), not a failure. It is logged as an answer, not as an error. Every other status keeps the verdict it has without the flag (a 401 still goes to the provider, a redirect is still followed over HTTP, a 404 or 500 is still refused), and every resend stays as it is — the CSRF recovery, the resend after the credential's renewal and the dead-pooled-socket resend send the same request, so a 304 to one of them is admitted too. Over HTTP and RFC alike. With noResend as well, noResend's admission (2xx and 3xx) already holds a 304.

An instance on an existing session

An instance may be built on a session that already exists, instead of logging on: session takes the cookies an earlier instance's sessionCookies() returned. connect() then sends no logon. It makes one request in that session without the credential — so a session that is gone cannot quietly become a new one — and SAP's answer says whether the session is alive: if it is, the instance is on it (a stateful request reaches the same ABAP context, and disconnect() logs it off); if not, connect() rejects with SAP's answer as it is (a 401), nothing is logged off, and the instance is spent. HTTP wires only; over RFC session is refused at construction.

import { createConnection } from "@mcp-abap-adt/connection";
import type { SapConfig } from "@mcp-abap-adt/connection";
import { BasicAuthProvider } from "@mcp-abap-adt/auth-providers";

const system: SapConfig = {
  url: "https://your-sap-system.com",
  client: "100",
  authType: "basic",
  username: "your-username",
  password: "your-password",
};
const credential = new BasicAuthProvider(system.username!, system.password!);

const first = createConnection({ system: "onprem", transport: "http", config: system, credential });
await first.connect();
// The session's cookies, for you to keep — they act as the user while the
// session lives, so keep them as a secret. null before a session, and over RFC.
const kept = first.sessionCookies();

// Later — another process, say: the same SAP session, no new logon.
if (kept !== null) {
  const resumed = createConnection({
    system: "onprem",
    transport: "http",
    config: system,
    credential,
    session: kept,
  });
  await resumed.connect(); // rejects with SAP's 401 when the session is gone
  try {
    await resumed.makeAdtRequest({ method: "GET", url: "/sap/bc/adt/discovery", timeout: 0 });
  } finally {
    await resumed.disconnect(); // logs the session off, as for any instance
  }
}

Basic Usage (On-Premise), with the constructors

import {
  AdtOnPremConnector,
  OnPremHttpTransport,
  SapConfig,
} from "@mcp-abap-adt/connection";
import { BasicAuthProvider } from "@mcp-abap-adt/auth-providers";

const config: SapConfig = {
  url: "https://your-sap-system.com",
  client: "100",
  authType: "basic",
  username: "your-username",
  password: "your-password",
};

// Create a simple logger
const logger = {
  info: (msg: string, meta?: any) => console.log(msg, meta),
  error: (msg: string, meta?: any) => console.error(msg, meta),
  warn: (msg: string, meta?: any) => console.warn(msg, meta),
  debug: (msg: string, meta?: any) => console.debug(msg, meta),
};

// Which system you are dialling is the class you take; which credential it
// authenticates with is the object you hand it. Neither is detected.
const connection = new AdtOnPremConnector(
  config,
  new BasicAuthProvider(config.username!, config.password!),
  new OnPremHttpTransport(() => ({}), logger, {
    client: config.client,
    baseUrl: config.url,
  }),
  logger,
);
await connection.connect();   // required before any request

// Make ADT request
const response = await connection.makeAdtRequest({
  method: "GET",
  url: "/sap/bc/adt/programs/programs/your-program",
  timeout: 0,
});

The client is the wire's. The transport's client option is what addresses the SAP client (mandant): an HTTP wire sends it as the sap-client header and the sap-usercontext=sap-client=<n> cookie on every request, the first one — which opens the session and earns the CSRF token — included. config.client alone does not reach the system over HTTP; pass the same value to the transport, as above. X-SAP-Client is not sent: ABAP ignores it. A request cannot name another client: a sap-client header, query parameter, params entry or sap-usercontext cookie (in any case) that differs from the connection's — or names one when the connection was given none — is refused before anything is sent. Another client is another logon, with its own user, password, session and CSRF token, so it is another connection.

Cloud Usage (JWT/OAuth2)

import {
  AdtCloudConnector,
  CloudHttpTransport,
  SapConfig,
} from "@mcp-abap-adt/connection";
import { TokenAuthProvider } from "@mcp-abap-adt/auth-providers";

// JWT configuration
const config: SapConfig = {
  url: "https://your-instance.abap.cloud.sap",
  client: "100", // Optional
  authType: "jwt",
  jwtToken: "your-jwt-token-here", // Obtained via OAuth2 flow
};

const logger = {
  info: (msg: string, meta?: any) => console.log(msg, meta),
  error: (msg: string, meta?: any) => console.error(msg, meta),
  warn: (msg: string, meta?: any) => console.warn(msg, meta),
  debug: (msg: string, meta?: any) => console.debug(msg, meta),
};

// Logger is optional - if not provided, no logging output.
// `.fixed` is a token with nothing behind it. `TokenAuthProvider.from` takes an
// `ITokenRefresher` instead and renews when the system refuses the token, which
// is what you want in anything long-lived.
const connection = new AdtCloudConnector(
  config,
  TokenAuthProvider.fixed(config.jwtToken!),
  new CloudHttpTransport(() => ({}), logger, {
    client: config.client,
    baseUrl: config.url,
  }),
  logger,
);
await connection.connect();

// Note: obtaining and refreshing tokens is @mcp-abap-adt/auth-broker's job
const response = await connection.makeAdtRequest({
  method: "GET",
  url: "/sap/bc/adt/programs/programs/your-program",
  timeout: 0,
});

On-Premise over RFC

The same ADT calls, over SADT_REST_RFC_ENDPOINT — the function module Eclipse ADT itself uses through JCo — instead of over HTTP. Worth taking on a system where stateful HTTP sessions are not usable: an RFC conversation is one ABAP session for its whole lifetime, which is the way past 423 invalid lock handle on BASIS < 7.50.

Since 9.3.2, LOCK and UNLOCK in stateful mode share the persistent RFC conversation; stateless requests use a separate ABAP context. With sap-rfc-lite 0.2.1 or newer (required since 9.4.2), that context is reset between calls on a kept conversation; older clients open one conversation per call. 0.2.0 on npm lacks the reset in its JS client and behaves like an older one. This prevents stale package state from causing PAK/058 on later writes or SADT_RESOURCE/007 on a read after create. Concurrent calls use a separate conversation. See RFC conversation isolation.

Needs npm install @mcp-abap-adt/sap-rfc-lite (0.4.1 or newer: it installs with no install script and carries prebuilt bindings for linux-x64 glibc, win32-x64 and darwin-arm64; elsewhere, build one from its repository) and the SAP NetWeaver RFC library at run time: on Windows, the 64-bit sapnwrfc.dll SAP GUI installs into System32 is enough; otherwise the SAP NW RFC SDK, its lib directory on the library search path (see sap-rfc-lite's README, "Runtime library loading").

import {
  AdtOnPremConnector,
  RfcTransport,
  rfcConversationFrom,
} from "@mcp-abap-adt/connection";
import type { SapRfcConfig } from "@mcp-abap-adt/connection";
import { BasicAuthProvider } from "@mcp-abap-adt/auth-providers";

// An RFC destination states its address — here one application server, its
// host and system number — and its client and logon language. No URL.
const rfcConfig: SapRfcConfig = {
  connectionType: "rfc",
  ashost: "your-sap-host",
  sysnr: "00",
  client: "100",
  language: "EN",
  authType: "basic",
  username: "your-username",
  password: "your-password",
};

const connection = new AdtOnPremConnector(
  rfcConfig,
  new BasicAuthProvider(rfcConfig.username!, rfcConfig.password!),
  new RfcTransport(rfcConversationFrom(rfcConfig), logger),
  logger,
);

await connection.connect();
// Everything above the wire is the same: makeAdtRequest, setSessionType,
// disconnect. What differs is where the session lives — see below.

The passport travels as the call's own (22.0.0). A request that carries a SAP-PASSPORT header (its name read without case) is sent over RFC with that passport as the RFC call's passport, for that call only — so an ABAP program started over RFC is caught by an external debugger listening in terminal mode for the passport's ids, as it is over HTTP. SADT_REST_RFC_ENDPOINT reads no passport from a header field, so the header is not sent as one. Its value must be the passport in hex (non-empty, even length, 0–9 / a–f / A–F); anything else, or the header named twice, is refused before anything is sent, the header named and its value never quoted. The passport's structure is sap-rfc-lite's to check. A request without the header carries no passport, as before: the wire invents, derives and keeps none. Over HTTP the header goes as it always went.

A caught session stays caught. sap-rfc-lite does not reset a stateful session: once a listener has caught a call on it, later calls on the same session are caught too, with or without a passport, until the session ends. The connection does not reset it either — that would drop its locks. A run meant to be caught belongs on a non-stateful request (the kept conversation is reset after every call), or on a connection of its own.

A failed RFC call names its error by fields (22.0.0). When the SDK reports the failure, the Error the caller receives carries it as rfc: { key, group, code, codeString } (IRfcErrorInfo, typed by IAbapConnectionError in @mcp-abap-adt/interfaces-adt-connection; codeString is one of RFC_RCS). Read the failure from those, never from the message: a call's failure says RFC call to SADT_REST_RFC_ENDPOINT failed: <codeString> (for example … failed: RFC_COMMUNICATION_FAILURE) and sets no top-level code; when the error ended the stateful conversation, the message is the session-lost one and code is ADT_SESSION_REPLACED (below). rfc is carried either way, on every conversation. A call's error the SDK did not name — the closed-connection error, a passport sap-rfc-lite refuses — carries no rfc, and its message ends … failed: the SDK did not name the failure. (A SAP-PASSPORT header that is not hex is refused before any call, in its own words.)

No text of the SDK's reaches a message or a log line (25.0.0). The NW RFC SDK's own text names the partner it dialled (host:port), the time and the kernel's source module; the connection never quotes it — not in a call's failure, not in its log lines (a failed call, close or reset), not in a WireLogonError's message (The logon failed), not when the conversation cannot be built (The RFC conversation could not be built: <codeString>), and not when sap-rfc-lite cannot be loaded. What the SDK said reaches you as rfc. The provider is handed the SDK's error as it arrived (IAuthRejection.error), for its own reading; the AuthRefusedError you get carries a copy of it ("What a failure carries", below).

import type { RfcReturnCodeName } from "@mcp-abap-adt/interfaces-adt-connection";

/** The RFC return code a caught value names in `rfc`, or undefined. */
function rfcCodeOf(error: unknown): string | undefined {
  if (typeof error !== "object" || error === null || !("rfc" in error)) {
    return undefined;
  }
  const { rfc } = error;
  return typeof rfc === "object" && rfc !== null && "codeString" in rfc &&
    typeof rfc.codeString === "string"
    ? rfc.codeString
    : undefined;
}

try {
  await connection.makeAdtRequest({ url: "/sap/bc/adt/discovery", method: "GET", timeout: 0 });
} catch (error) {
  const closed: RfcReturnCodeName = "RFC_CLOSED";
  if (rfcCodeOf(error) === closed) {
    // the other side closed the conversation
  }
}

An RFC error that ends the session ends the instance (22.0.0). When an RFC error ends the stateful conversation — the one that carries the instance's session and its locks (sap-rfc-lite releases it: alive is false) — the request rejects with code ADT_SESSION_REPLACED and the call's rfc; the instance is spent, and every later request and connect() reject ADT_NOT_CONNECTED with nothing sent. The connection does not open a new session on its own: a lock held in the old one is gone and is never presented as still held. A new session is a new connection, which only you create. (terminateDebugger on the debugger's stateful session ends it this way: RFC_CLOSED.) A non-stateful conversation an RFC error ends carries no session of the instance: it is replaced as a reset replaces it, and the request's error still carries its rfc. A wire of your own says the same with WireSessionLostError, exported beside WireLogonError.

Where to look for it. An HTTP session is an ICF session and appears in SM05. An RFC conversation is a gateway client: it appears in SMGW → Logged on Clients as NWRFC, and never in SM05, because there is no ICM in that path. Looking for one in the other monitor and finding nothing is not a fault.

There is no cloud equivalent: ABAP Cloud has one wire, and AdtCloudConnector takes no transport parameter at all.

SSO Usage (SAML Session Cookies)

import {
  AdtOnPremConnector,
  OnPremHttpTransport,
  SapConfig,
} from "@mcp-abap-adt/connection";
import { SamlAuthProvider } from "@mcp-abap-adt/auth-providers";

const config: SapConfig = {
  url: "https://your-sap-system.com",
  authType: "saml",
  sessionCookies: "MYSAPSSO2=...; SAP_SESSIONID=...",
};

// The cookies ARE the credential here — there is no Authorization header at all.
const connection = new AdtOnPremConnector(
  config,
  new SamlAuthProvider(config.sessionCookies!),
  new OnPremHttpTransport(() => ({}), logger, {
    client: config.client,
    baseUrl: config.url,
  }),
  logger,
);
await connection.connect();

const response = await connection.makeAdtRequest({
  method: "GET",
  url: "/sap/bc/adt/programs/programs/your-program",
  timeout: 0,
});

Cloud Usage with Automatic Token Refresh

Build TokenAuthProvider.from over an ITokenRefresher and the provider replaces a token the system refused: the connection puts the 401 to rejected, the provider fetches a new token, and the request is sent once more. A token the source still believes in and the server refuses again is the verdict, and that one surfaces as an AuthRefusedError:

import {
  AdtCloudConnector,
  CloudHttpTransport,
  SapConfig,
} from "@mcp-abap-adt/connection";
import { TokenAuthProvider } from "@mcp-abap-adt/auth-providers";
import type { ITokenRefresher } from "@mcp-abap-adt/interfaces-auth";

// Token refresher provides token acquisition and refresh
// (created by @mcp-abap-adt/auth-broker or custom implementation)
const currentAccessToken = 'the access token you already hold';
const exchangeRefreshToken = async () => 'a freshly exchanged access token';
const tokenRefresher: ITokenRefresher = {
  getToken: async () => currentAccessToken,      // the one you hold
  refreshToken: async () => exchangeRefreshToken(), // a new one, and cache it
};

const config: SapConfig = {
  url: "https://your-instance.abap.cloud.sap",
  authType: "jwt",
};

// The connector says which SYSTEM this is; the provider says how to
// authenticate. Neither decides the other.
const connection = new AdtCloudConnector(
  config,
  TokenAuthProvider.from(tokenRefresher),
  new CloudHttpTransport(() => ({}), logger, {
    client: config.client,
    baseUrl: config.url,
  }),
  logger,
);
await connection.connect();

// On a 401 the connection asks the provider (`rejected`); on Ok it sends the
// request once more with the renewed token, otherwise you get an
// AuthRefusedError. The resend always runs under the same lease and generation
// as the attempt it repeats, so stale-request fencing applies. After a rejection
// at 'request' it goes out on the same session; after one at 'logon' the wire
// logs on again first. No 401 opens a new session: the resend stays in this
// one. If SAP replaced it, a stateful request fails with ADT_SESSION_REPLACED
// and a stateless one gets SAP's answer marked `sessionLost`; the instance is
// spent either way. For a new session, create a new connection.
const response = await connection.makeAdtRequest({
  method: "GET",
  url: "/sap/bc/adt/programs/programs/your-program",
  timeout: 0,
});

A 403 is never treated as an expired token. It means the server authenticated the caller and refused the action anyway, so no credential can change the answer. It propagates unchanged — error.response.status and the server's message, which usually names the authorization object — rather than being reported as an expired token.

Earlier versions reported both 401 and 403 as JWT token has expired. Please re-authenticate. and discarded the original error. Code matching on that message must branch on error.response.status instead — which it can now do, since the status is no longer thrown away. See MIGRATION-4.0.md.

What a failure carries (25.0.0). An error the connection hands you says the failure by its typed facts and fixed words — never a thrown value's text, and never a request's config. A thrown value's text names hosts and ports (axios's connect ECONNREFUSED <host>:<port>, the RFC SDK's partner), and axios's error holds the request's config with its Authorization, Cookie and CSRF headers.

  • An HTTP failure is an Error with SAP's answer as response — status, statusText, headers, data, as SAP gave them — and status, axios's code, and the message Request failed with status code <n>. With no answer: code (ECONNREFUSED, ECONNABORTED, …) and The request failed: <code> — the code its own, else the first down its cause chain. It is not axios's error: no config, no request, no isAxiosError, no cause.
  • AuthRefusedError.cause is a copy of the wire's error (or of what the provider threw): an Error named WireFailure, its message The failure: <facts>, its facts as fields — code (its own, else one down its cause chain), status, rfc, and SAP's answer as response. The provider was handed the wire's error as it arrived — over HTTP the client's own rejection, over RFC the SDK's error.
  • A WireLogonError that leaves connect() carries such a copy as its cause.
  • The WebSocket transport hands its error handlers <words>: <code>, with code.
  • Log lines say a failure the same way: its facts, or no code was given.

A transport you write yourself (IAdtTransport) hands up what it throws: a failure that is not the credential's passes through the connection as your wire raised it, so its words are yours to choose.

Code that read error.config, error.request, error.isAxiosError, or tested axios.isAxiosError(error) / instanceof AxiosError on a connection's error reads error.response, error.status and error.code instead. See docs/MIGRATION-25.0.md.

When the credential is refused

Every request asks the provider first (authorize). A 401 that survives the wire's own CSRF recovery (in the same session), or a logon the system refused, is put to the provider (rejected); on Ok the request is sent once more, otherwise it fails with an AuthRefusedError carrying the provider's refusal. A 403 is never put to the provider. The refusal is an IAuthProviderError: decide on its kind and facts; reason and hint are the words to show, and the error's message is reason — hint. It is frozen — relay it, never copy it.

import { AuthRefusedError } from "@mcp-abap-adt/connection";

try {
  await connection.connect();
} catch (error) {
  if (error instanceof AuthRefusedError) {
    if (error.refusal.kind === "credential-refused") {
      // the credential itself was refused: renew it, or ask the user
    }
    console.error(error.refusal.reason, error.refusal.hint, error.at);
  }
  throw error;
}

See USAGE.md.

The server certificate

The HTTP wire verifies the server certificate, as Node does. For a system with a self-signed certificate or one from a company CA, trust that CA:

import { readFileSync } from "node:fs";
import { OnPremHttpTransport } from "@mcp-abap-adt/connection";

const ca = readFileSync("/path/to/sap-system-ca.pem", "utf8");
const transport = new OnPremHttpTransport(() => ({ ca }), logger, {
  client: config.client,
  baseUrl: config.url,
});

Verification is turned off only explicitly — agentOptions: { rejectUnauthorized: false }, or (when agentOptions leaves it unset) TLS_REJECT_UNAUTHORIZED=0 or NODE_TLS_REJECT_UNAUTHORIZED=0; any other value verifies. A last resort, never for production. Before 11.0.0 the certificate was not verified by default: see MIGRATION-11.0.md.

The HTTP client

An HTTP wire reaches the network through an HttpClientFactory, the httpClient option of its constructor (20.0.0). Left out, it is nodeHttpClient: axios over the wire's own pooled agents, and Node's http / https for the logoff — what the wire has always used. Hand your own to put something under the wire, a test double above all: everything the wire adds to its requests (cookies, CSRF token, affinity headers, sap-client) still runs, and only the exchange is yours.

import axios from "axios";
import {
  type HttpClientFactory,
  OnPremHttpTransport,
  nodeHttpClient,
} from "@mcp-abap-adt/connection";

const httpClient: HttpClientFactory = {
  ...nodeHttpClient,
  // Built from the wire's agents; built anew when a logon offers other TLS material.
  create: (agents) => axios.create({ ...agents }),
};
const transport = new OnPremHttpTransport(() => ({}), logger, {
  client: config.client,
  baseUrl: config.url,
  httpClient,
});

Stateful Sessions

Enable stateful mode for requests that need the ABAP context, such as LOCK and UNLOCK. Switch to stateless for GET and PUT between them: a lock handle does not require the write itself to run in the lock’s context. Authentication cookies and the CSRF token remain available in both modes. See the Stateful Session Guide for transport behavior.

import {
  AdtOnPremConnector,
  OnPremHttpTransport,
} from "@mcp-abap-adt/connection";
import { BasicAuthProvider } from "@mcp-abap-adt/auth-providers";

const connection = new AdtOnPremConnector(
  config,
  new BasicAuthProvider(config.username!, config.password!),
  new OnPremHttpTransport(() => ({}), logger, {
    client: config.client,
    baseUrl: config.url,
  }),
  logger,
);
await connection.connect();

// Enable the stateful HTTP context (session header and context cookie)
connection.setSessionType("stateful");

// Send the LOCK request here, then leave its context for GET / PUT.
connection.setSessionType("stateless");

// Send GET / PUT with the lock handle here.
// Return to the same context when sending UNLOCK.
connection.setSessionType("stateful");
// Send UNLOCK here, then restore the default mode.
connection.setSessionType("stateless");

When SAP replaced the session (an idle timeout, usually): a stateful request rejects ADT_SESSION_REPLACED; a stateless one gets SAP's answer as it came — a success resolves, a refusal rejects as itself — marked sessionLost: 'ADT_SESSION_REPLACED' (since 23.0.0). Either way the instance is spent. Create a new connection for later calls. The factory can finish a stateless syntax check on a temporary session after an explicit CSRF refusal. See When the session is lost.

Custom Logger

import { AdtOnPremConnector, ILogger, OnPremHttpTransport } from "@mcp-abap-adt/connection";
import { BasicAuthProvider } from "@mcp-abap-adt/auth-providers";

class MyLogger implements ILogger {
  info(message: string, meta?: any): void {
    // Your logging implementation
  }

  error(message: string, meta?: any): void {
    // Your logging implementation
  }

  warn(message: string, meta?: any): void {
    // Your logging implementation
  }

  debug(message: string, meta?: any): void {
    // Your logging implementation
  }
}

const logger = new MyLogger();
const connection = new AdtOnPremConnector(
  config,
  new BasicAuthProvider(config.username!, config.password!),
  new OnPremHttpTransport(() => ({}), logger, {
    client: config.client,
    baseUrl: config.url,
  }),
  logger,
);

API Reference

Types

SapConfig

Configuration for SAP ABAP connection.

type SapConfig = {
  url: string;
  client?: string;
  authType: "basic" | "jwt" | "saml";
  // For basic auth
  username?: string;
  password?: string;
  // For JWT auth
  jwtToken?: string;
  // For SAML session cookies
  sessionCookies?: string;
};

AbapConnection

Main interface for ABAP connections.

import type { AbapRequestOptions } from '@mcp-abap-adt/connection';
import type { IAdtWireResponse } from '@mcp-abap-adt/interfaces-adt-connection';
// The shared contract (IAbapConnection), what every connection provides:
interface AbapConnection {
  connect(): Promise<void>; // REQUIRED before any request; rejects on failure
  // The answer's `data` is `unknown`; the caller names no type for it
  // (interfaces-adt-connection 5).
  makeAdtRequest(options: AbapRequestOptions): Promise<IAdtWireResponse>;
  getBaseUrl(): Promise<string | undefined>; // undefined over RFC: no HTTP origin
  setSessionType(type: "stateless" | "stateful"): void; // Switch session type
  getSessionId(): string | null; // Client-side conversation id
}

The connectors carry the rest of the session lifecycle. It is on the shared contract as a capability atom in @mcp-abap-adt/interfaces-adt-connection rather than as methods on IAbapConnection, so a consumer that only carries requests is unaffected by its existence. Note that a connection over RFC has the whole of it — what an RFC conversation has none of is a session RESOURCE to open and close by address, which is an empty mechanism, not an absent lifecycle:

// ISessionLifecycleAware
disconnect(): Promise<void>;         // resolves once the logoff is written; call it once (a second call rejects)
isConnected(): boolean;
getSessionIdentity(): string | null; // WHICH SAP session; null is not "disconnected"

Import those names from @mcp-abap-adt/interfaces-adt-connection, not from this package: a contract type re-exported under a second name is a contract type that can drift.

The connection does not track locks. Deciding when to disconnect, and preparing for it, belongs to the caller; pairing every LOCK with its UNLOCK belongs to @mcp-abap-adt/adt-clients, which holds the handles. What this layer owns is not being interrupted by a deadline mid-operation: inside beginCriticalSection() a request carries none, not even the caller's.

See docs/USAGE.md — Session Lifecycle.

Session Management:

  • setSessionType(type): Programmatically switch between stateful and stateless modes (on the contract)
  • getSessionId(): Returns the client-side conversation id, an auto-generated UUID (on the contract)
  • getSessionMode(): Returns current session mode (HTTP classes only)
  • sessionCookies(): The cookies of the instance's SAP session, as createConnection({ …, session }) takes them — null before a session, after it ended, and over RFC. They act as the user while the session lives: keep them as a secret; the package never logs them (this package's connectors)

ILogger

Logger interface for custom logging implementations.

interface ILogger {
  info(message: string, meta?: any): void;
  error(message: string, meta?: any): void;
  warn(message: string, meta?: any): void;
  debug(message: string, meta?: any): void;
}

Functions

createConnection(spec)

Builds a NEW connection from what the caller states: system ('cloud' or 'onprem') and transport ('http', 'legacy-http' or 'rfc'), plus config, credential and, optionally, logger, wireLogger, sessionId, agentOptions, httpClient and session (HTTP) or rfc (IRfcTransportOptions). Nothing is inferred, not even from config.connectionType. A combination that does not exist is refused with a TypeError, and so is session over RFC. One instance is one SAP session: call it again for a new one — or pass session (the string an instance's sessionCookies() returned) to build it on an existing session, which connect() then takes over instead of logging on.

rfcConversationFrom(config)

What RfcTransport is constructed with, from an RFC config (SapRfcConfig, connectionType: 'rfc'). An RFC config has no URL: it states its address, its client and its logon language, and the SDK gets them as they are — nothing is derived, defaulted, trimmed or read from the environment. The address is one of two, and the config's type admits exactly one:

  • One application server: ashost and sysnr.
  • A message server and a logon group: mshost, its service as msserv, sysid or both, and group — the message server picks the application server.

saprouter goes with either. language reaches the SDK as lang. The provider's logon parameters are spread over the address at each open.

The SAP NW RFC SDK is loaded when a conversation opens, not when this is called, so a machine without it fails at connect() with a message saying what to install rather than at construction.

function rfcConversationFrom(
  config: SapRfcConfig,
): RfcConversationFactory & { readonly language: string };
// RfcConversationFactory = ((logon: Readonly<Record<string, string>>) => IRfcConversation)
//                          & { readonly language?: string }   // the logon language
function rfcParamsFrom(config: SapRfcConfig): RfcAddress; // the address only
// RfcAddress = RfcConnectionParams (ashost, sysnr) | RfcMessageServerParams (mshost, msserv and/or sysid, group)
import {
  AdtOnPremConnector,
  RfcTransport,
  rfcConversationFrom,
} from "@mcp-abap-adt/connection";
import { BasicAuthProvider } from "@mcp-abap-adt/auth-providers";

const connection = new AdtOnPremConnector(
  rfcConfig,
  new BasicAuthProvider(rfcConfig.username!, rfcConfig.password!),
  new RfcTransport(rfcConversationFrom(rfcConfig), logger),
  logger,
);

A third argument turns on the wire log, which is off by default:

new RfcTransport(rfcConversationFrom(rfcConfig), logger, { logWire: true });

It adds three debug lines per request — header fields, request body, response body — which is how you see that a payload was mis-serialised before it reached SADT_REST_RFC_ENDPOINT. Credential header values are replaced with [redacted] and bodies are clipped at maxLoggedBodyChars (2000). The bodies themselves are not redacted, so read a captured log before pasting it into an issue. HttpTransport never logs bodies, so this is the one wire whose debug channel can be asked for the payload.

A request's language over RFC

A request runs in the language its sap-language names — a header, or the sap-language query parameter in params or in the URL — on both wires. Over HTTP the ICF layer reads it. SADT_REST_RFC_ENDPOINT runs a request in its conversation's logon language and ignores sap-language, so RfcTransport compares the two (SAP language keys, without case) — the request's language with the logon language of the conversation that would carry it. A conversation's logon language is the lang its logon carries: the provider's, where it writes one among its logon parameters at that logon, else the one the factory states (rfcConversationFrom states the config's language):

  • None named: the request goes as any other.
  • A stateful request is compared with the stateful conversation's logon language.
  • A non-stateful request is compared with the kept stateless conversation's logon language — once it is open, the language it logged on in; before, the language the provider's logon parameters for it name. The same language: it goes on the kept conversation, as any other. Another: it goes on a conversation logged on in the request's language (lang as the request names it, over any lang the provider writes), opened for that one call and closed when it answers, whatever the answer. Nothing is kept: the next such call logs on again.
  • A stateful request in another language (a LOCK, an UNLOCK, anything in the lock's session): refused before anything is sent, with an error naming both languages — a session cannot change its language. Connect with the language the locked work needs.
  • Two different languages named on one request: refused before anything is sent.

A factory of your own that does not state language, with a provider that writes no lang, leaves the wire without a logon language to compare: every non-stateful request naming a sap-language then takes a conversation of its own in that language, and every stateful one naming it is refused.

CSRF_CONFIG and CSRF_ERROR_MESSAGES

New in 0.1.13+: Exported constants for consistent CSRF token handling across different connection implementations.

import { CSRF_CONFIG, CSRF_ERROR_MESSAGES } from '@mcp-abap-adt/connection';

// CSRF_CONFIG contains:
// - ENDPOINT: string (default: '/sap/bc/adt/core/discovery')
// - FALLBACK_ENDPOINT: string (default: '/sap/bc/adt/discovery', BASIS < 7.52)
// - REQUIRED_HEADERS: { 'x-csrf-token': 'fetch', 'Accept': 'application/atomsvc+xml' }

// CSRF_ERROR_MESSAGES contains:
// - FETCH_FAILED(attempts: number, cause: string): string
// - NOT_IN_HEADERS: string
// - REQUIRED_FOR_MUTATION: string

Use case: When implementing custom connection classes (e.g., Cloud SDK-based), you can use these constants to ensure consistent CSRF token handling:

import { CSRF_CONFIG, CSRF_ERROR_MESSAGES } from '@mcp-abap-adt/connection';

// Whatever HTTP client your own connection class is built on.
const yourHttpClient = {
  get: async (url: string, config: { headers: Record<string, string> }) =>
    ({ headers: {} as Record<string, string> }),
};

// One request, and the fallback endpoint only when the first answers 404 or 501 —
// the way this package fetches its own: no retry, no delay. A failed request
// is its own error, and the caller decides what to do about it.
async function fetchCsrfToken(baseUrl: string): Promise<string> {
  let response: { headers: Record<string, string> };
  try {
    response = await yourHttpClient.get(`${baseUrl}${CSRF_CONFIG.ENDPOINT}`, {
      headers: CSRF_CONFIG.REQUIRED_HEADERS,
    });
  } catch (error) {
    const status = (error as { response?: { status?: number } }).response
      ?.status;
    if (status !== 404 && status !== 501) throw error;
    response = await yourHttpClient.get(
      `${baseUrl}${CSRF_CONFIG.FALLBACK_ENDPOINT}`,
      { headers: CSRF_CONFIG.REQUIRED_HEADERS },
    );
  }

  const token = response.headers['x-csrf-token'];
  if (!token) throw new Error(CSRF_ERROR_MESSAGES.NOT_IN_HEADERS);
  return token;
}

Requirements

  • Node.js 22, 24 or 26 (engines: ^22 || ^24 || ^26)
  • Access to SAP ABAP system (on-premise or BTP)

Changelog

See CHANGELOG.md for detailed version history and breaking changes.

Version history: CHANGELOG.md

  • Removed token refresh functionality (handled by @mcp-abap-adt/auth-broker)
  • Removed session storage functionality (handled by @mcp-abap-adt/auth-broker)
  • Logger is now optional