@mcp-abap-adt/connection
Version:
ABAP connection layer for MCP ABAP ADT server
66 lines (65 loc) • 2.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SamlAbapConnection = void 0;
const axios_1 = require("axios");
const AbstractAbapConnection_js_1 = require("./AbstractAbapConnection.js");
/**
* SAML session cookie authentication for SAP systems
*/
class SamlAbapConnection extends AbstractAbapConnection_js_1.AbstractAbapConnection {
sessionCookies;
constructor(config, logger, sessionId, options) {
SamlAbapConnection.validateConfig(config);
super(config, logger || null, sessionId, options);
this.sessionCookies = config.sessionCookies || '';
if (this.sessionCookies) {
this.setInitialCookies(this.sessionCookies);
}
}
/**
* Connect to SAP system using existing session cookies
* Fetches CSRF token to establish session context
*/
async connect() {
const baseUrl = await this.getBaseUrl();
const discoveryUrl = `${baseUrl}/sap/bc/adt/discovery`;
this.logger?.debug(`[DEBUG] SamlAbapConnection - Connecting to SAP system: ${discoveryUrl}`);
try {
const token = await this.fetchCsrfToken(discoveryUrl, 3, 1000);
this.setCsrfToken(token);
this.logger?.debug('Successfully connected to SAP system', {
hasCsrfToken: !!this.getCsrfToken(),
hasCookies: !!this.getCookies(),
cookieLength: this.getCookies()?.length || 0,
});
}
catch (error) {
const errorMsg = error instanceof Error ? error.message : String(error);
this.logger?.warn(`[WARN] SamlAbapConnection - Could not connect to SAP system upfront: ${errorMsg}. Will retry on first request.`);
if (error instanceof axios_1.AxiosError && error.response?.headers) {
if (this.getCookies()) {
this.logger?.debug(`[DEBUG] SamlAbapConnection - Cookies extracted from error response during connect (first 100 chars): ${this.getCookies()?.substring(0, 100)}...`);
}
}
}
}
buildAuthorizationHeader() {
return '';
}
async getAuthHeaders() {
const headers = await super.getAuthHeaders();
if (this.sessionCookies) {
headers.Cookie = this.sessionCookies;
}
return headers;
}
static validateConfig(config) {
if (config.authType !== 'saml') {
throw new Error(`SAML connection expects authType "saml", got "${config.authType}"`);
}
if (!config.sessionCookies) {
throw new Error('SAML authentication requires sessionCookies');
}
}
}
exports.SamlAbapConnection = SamlAbapConnection;