@mcp-abap-adt/proxy 0.1.4 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -1
- package/README.md +73 -63
- package/bin/mcp-abap-adt-proxy.js +15 -42
- package/dist/index.d.ts +3 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +440 -273
- package/dist/lib/config.d.ts +13 -4
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +110 -92
- package/dist/lib/errorHandler.d.ts +3 -3
- package/dist/lib/errorHandler.d.ts.map +1 -1
- package/dist/lib/errorHandler.js +31 -28
- package/dist/lib/logger.d.ts.map +1 -1
- package/dist/lib/logger.js +15 -1
- package/dist/lib/stores.d.ts +7 -6
- package/dist/lib/stores.d.ts.map +1 -1
- package/dist/lib/stores.js +121 -8
- package/dist/lib/transportConfig.d.ts +1 -1
- package/dist/lib/transportConfig.d.ts.map +1 -1
- package/dist/lib/transportConfig.js +58 -38
- package/dist/proxy/btpProxy.d.ts +102 -0
- package/dist/proxy/btpProxy.d.ts.map +1 -0
- package/dist/proxy/btpProxy.js +833 -0
- package/dist/proxy/cloudLlmHubProxy.d.ts +1 -60
- package/dist/proxy/cloudLlmHubProxy.d.ts.map +1 -1
- package/dist/proxy/cloudLlmHubProxy.js +1 -378
- package/dist/router/headerAnalyzer.d.ts +14 -18
- package/dist/router/headerAnalyzer.d.ts.map +1 -1
- package/dist/router/headerAnalyzer.js +40 -67
- package/dist/router/requestInterceptor.d.ts +5 -11
- package/dist/router/requestInterceptor.d.ts.map +1 -1
- package/dist/router/requestInterceptor.js +33 -30
- package/package.json +33 -14
- package/dist/router/directCloudRouter.d.ts +0 -32
- package/dist/router/directCloudRouter.d.ts.map +0 -1
- package/dist/router/directCloudRouter.js +0 -179
- package/dist/router/localBasicRouter.d.ts +0 -23
- package/dist/router/localBasicRouter.d.ts.map +0 -1
- package/dist/router/localBasicRouter.js +0 -140
package/dist/lib/stores.js
CHANGED
|
@@ -1,22 +1,135 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Platform-specific stores for proxy
|
|
4
|
-
* Uses
|
|
4
|
+
* Uses XsuaaServiceKeyStore and either XsuaaSessionStore or SafeXsuaaSessionStore
|
|
5
5
|
* depending on the unsafe configuration parameter
|
|
6
6
|
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
7
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
41
|
exports.getPlatformStores = getPlatformStores;
|
|
9
|
-
const
|
|
42
|
+
const os = __importStar(require("node:os"));
|
|
43
|
+
const path = __importStar(require("node:path"));
|
|
44
|
+
const auth_stores_1 = require("@mcp-abap-adt/auth-stores");
|
|
45
|
+
/**
|
|
46
|
+
* Get platform-specific default paths for service keys and sessions
|
|
47
|
+
*
|
|
48
|
+
* Priority (matching mcp-abap-adt logic):
|
|
49
|
+
* 1. AUTH_BROKER_PATH environment variable
|
|
50
|
+
* 2. Platform-specific standard paths (only if no env paths were found):
|
|
51
|
+
* - Unix: ~/.config/mcp-abap-adt/{subfolder}
|
|
52
|
+
* - Windows: %USERPROFILE%\Documents\mcp-abap-adt\{subfolder}
|
|
53
|
+
* 3. Current working directory (process.cwd())
|
|
54
|
+
*
|
|
55
|
+
* @param subfolder Subfolder name ('service-keys' or 'sessions')
|
|
56
|
+
* @returns Array of resolved absolute paths
|
|
57
|
+
*/
|
|
58
|
+
function getPlatformPaths(subfolder) {
|
|
59
|
+
const paths = [];
|
|
60
|
+
const isWindows = process.platform === 'win32';
|
|
61
|
+
// Priority 1: AUTH_BROKER_PATH environment variable
|
|
62
|
+
const envPath = process.env.AUTH_BROKER_PATH;
|
|
63
|
+
if (envPath) {
|
|
64
|
+
// Support both colon (Unix) and semicolon (Windows) separators
|
|
65
|
+
const envPaths = envPath
|
|
66
|
+
.split(/[:;]/)
|
|
67
|
+
.map((p) => p.trim())
|
|
68
|
+
.filter((p) => p.length > 0);
|
|
69
|
+
paths.push(...envPaths.map((p) => path.resolve(p)));
|
|
70
|
+
}
|
|
71
|
+
// Priority 2: Platform-specific standard paths
|
|
72
|
+
// Only add platform-specific paths if no custom paths were provided (matching mcp-abap-adt logic)
|
|
73
|
+
if (paths.length === 0) {
|
|
74
|
+
const homeDir = os.homedir();
|
|
75
|
+
if (isWindows) {
|
|
76
|
+
// Windows: %USERPROFILE%\Documents\mcp-abap-adt\{subfolder}
|
|
77
|
+
const basePath = path.join(homeDir, 'Documents', 'mcp-abap-adt');
|
|
78
|
+
if (subfolder) {
|
|
79
|
+
paths.push(path.join(basePath, subfolder));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
paths.push(basePath);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// Unix (Linux/macOS): ~/.config/mcp-abap-adt/{subfolder}
|
|
87
|
+
const basePath = path.join(homeDir, '.config', 'mcp-abap-adt');
|
|
88
|
+
if (subfolder) {
|
|
89
|
+
paths.push(path.join(basePath, subfolder));
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
paths.push(basePath);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Priority 3: Current working directory (always added as fallback)
|
|
97
|
+
paths.push(process.cwd());
|
|
98
|
+
// Remove duplicates while preserving order
|
|
99
|
+
const uniquePaths = [];
|
|
100
|
+
const seen = new Set();
|
|
101
|
+
for (const p of paths) {
|
|
102
|
+
const normalized = path.normalize(p);
|
|
103
|
+
if (!seen.has(normalized)) {
|
|
104
|
+
seen.add(normalized);
|
|
105
|
+
uniquePaths.push(normalized);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return uniquePaths;
|
|
109
|
+
}
|
|
10
110
|
/**
|
|
11
111
|
* Get platform-specific stores
|
|
12
|
-
* Returns stores
|
|
13
|
-
* - If unsafe=true: uses
|
|
14
|
-
* - If unsafe=false: uses
|
|
15
|
-
*
|
|
112
|
+
* Returns XSUAA stores for BTP authentication:
|
|
113
|
+
* - If unsafe=true: uses XsuaaSessionStore (persists to disk)
|
|
114
|
+
* - If unsafe=false: uses SafeXsuaaSessionStore (in-memory, secure)
|
|
115
|
+
* - Service key store: XsuaaServiceKeyStore
|
|
116
|
+
* @param unsafe If true, use XsuaaSessionStore. If false, use SafeXsuaaSessionStore (default).
|
|
16
117
|
*/
|
|
17
118
|
async function getPlatformStores(unsafe = false) {
|
|
119
|
+
// Get platform-specific paths for service keys and sessions
|
|
120
|
+
const serviceKeyPaths = getPlatformPaths('service-keys');
|
|
121
|
+
const sessionPaths = getPlatformPaths('sessions');
|
|
122
|
+
// Stores only support a single directory, use the first path
|
|
123
|
+
const firstServiceKeyPath = serviceKeyPaths[0] || process.cwd();
|
|
124
|
+
const firstSessionPath = sessionPaths[0] || process.cwd();
|
|
125
|
+
const serviceKeyStore = new auth_stores_1.XsuaaServiceKeyStore(firstServiceKeyPath);
|
|
126
|
+
// Note: XSUAA stores require defaultServiceUrl (cannot be obtained from service key)
|
|
127
|
+
// For now, we use empty string as placeholder - it will be set when session is created
|
|
128
|
+
const sessionStore = unsafe
|
|
129
|
+
? new auth_stores_1.XsuaaSessionStore(firstSessionPath, '')
|
|
130
|
+
: new auth_stores_1.SafeXsuaaSessionStore('');
|
|
18
131
|
return {
|
|
19
|
-
serviceKeyStore
|
|
20
|
-
sessionStore
|
|
132
|
+
serviceKeyStore,
|
|
133
|
+
sessionStore,
|
|
21
134
|
};
|
|
22
135
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Transport Configuration - Parse and manage transport settings
|
|
3
3
|
*/
|
|
4
|
-
export type TransportType =
|
|
4
|
+
export type TransportType = 'stdio' | 'streamable-http' | 'sse';
|
|
5
5
|
export interface TransportConfig {
|
|
6
6
|
type: TransportType;
|
|
7
7
|
host?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transportConfig.d.ts","sourceRoot":"","sources":["../../src/lib/transportConfig.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,iBAAiB,GAAG,KAAK,CAAC;AAEhE,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,4BAA4B,CAAC,EAAE,OAAO,CAAC;CACxC;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,eAAe,
|
|
1
|
+
{"version":3,"file":"transportConfig.d.ts","sourceRoot":"","sources":["../../src/lib/transportConfig.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,iBAAiB,GAAG,KAAK,CAAC;AAEhE,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,4BAA4B,CAAC,EAAE,OAAO,CAAC;CACxC;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,eAAe,CAkItD"}
|
|
@@ -13,70 +13,84 @@ function parseTransportConfig() {
|
|
|
13
13
|
let transportType = null;
|
|
14
14
|
for (let i = 0; i < args.length; i++) {
|
|
15
15
|
const arg = args[i];
|
|
16
|
-
if (arg.startsWith(
|
|
17
|
-
const value = arg.split(
|
|
18
|
-
if (value ===
|
|
19
|
-
|
|
16
|
+
if (arg.startsWith('--transport=')) {
|
|
17
|
+
const value = arg.split('=')[1].toLowerCase();
|
|
18
|
+
if (value === 'stdio' ||
|
|
19
|
+
value === 'streamable-http' ||
|
|
20
|
+
value === 'http' ||
|
|
21
|
+
value === 'sse') {
|
|
22
|
+
transportType =
|
|
23
|
+
value === 'http' ? 'streamable-http' : value;
|
|
20
24
|
}
|
|
21
25
|
}
|
|
22
|
-
if (arg ===
|
|
26
|
+
if (arg === '--transport' && i + 1 < args.length) {
|
|
23
27
|
const value = args[i + 1].toLowerCase();
|
|
24
|
-
if (value ===
|
|
25
|
-
|
|
28
|
+
if (value === 'stdio' ||
|
|
29
|
+
value === 'streamable-http' ||
|
|
30
|
+
value === 'http' ||
|
|
31
|
+
value === 'sse') {
|
|
32
|
+
transportType =
|
|
33
|
+
value === 'http' ? 'streamable-http' : value;
|
|
26
34
|
}
|
|
27
35
|
}
|
|
28
|
-
if (arg ===
|
|
29
|
-
transportType =
|
|
30
|
-
if (arg ===
|
|
31
|
-
transportType =
|
|
32
|
-
if (arg ===
|
|
33
|
-
transportType =
|
|
36
|
+
if (arg === '--http')
|
|
37
|
+
transportType = 'streamable-http';
|
|
38
|
+
if (arg === '--stdio')
|
|
39
|
+
transportType = 'stdio';
|
|
40
|
+
if (arg === '--sse')
|
|
41
|
+
transportType = 'sse';
|
|
34
42
|
}
|
|
35
43
|
// Check environment variable
|
|
36
44
|
if (!transportType && process.env.MCP_TRANSPORT) {
|
|
37
45
|
const envTransport = process.env.MCP_TRANSPORT.toLowerCase();
|
|
38
|
-
if (envTransport ===
|
|
39
|
-
|
|
46
|
+
if (envTransport === 'stdio' ||
|
|
47
|
+
envTransport === 'streamable-http' ||
|
|
48
|
+
envTransport === 'http' ||
|
|
49
|
+
envTransport === 'sse') {
|
|
50
|
+
transportType =
|
|
51
|
+
envTransport === 'http'
|
|
52
|
+
? 'streamable-http'
|
|
53
|
+
: envTransport;
|
|
40
54
|
}
|
|
41
55
|
}
|
|
42
56
|
// Auto-detect stdio mode: if stdin is not a TTY, we're likely in stdio mode
|
|
43
57
|
if (!transportType && !process.stdin.isTTY) {
|
|
44
|
-
transportType =
|
|
58
|
+
transportType = 'stdio';
|
|
45
59
|
}
|
|
46
60
|
// Default to streamable-http if not specified
|
|
47
61
|
if (!transportType) {
|
|
48
|
-
transportType =
|
|
62
|
+
transportType = 'streamable-http';
|
|
49
63
|
}
|
|
50
64
|
// Parse SSE config
|
|
51
|
-
if (transportType ===
|
|
52
|
-
const port = parseInt(getArgValue(
|
|
53
|
-
const host = getArgValue(
|
|
65
|
+
if (transportType === 'sse') {
|
|
66
|
+
const port = parseInt(getArgValue('--sse-port') || process.env.MCP_SSE_PORT || '3002', 10);
|
|
67
|
+
const host = getArgValue('--sse-host') || process.env.MCP_SSE_HOST || '0.0.0.0';
|
|
54
68
|
return {
|
|
55
|
-
type:
|
|
69
|
+
type: 'sse',
|
|
56
70
|
host,
|
|
57
71
|
port,
|
|
58
|
-
allowedOrigins: parseListOption(
|
|
59
|
-
allowedHosts: parseListOption(
|
|
60
|
-
enableDnsRebindingProtection: parseBooleanOption(
|
|
72
|
+
allowedOrigins: parseListOption('--sse-allowed-origins', 'MCP_SSE_ALLOWED_ORIGINS'),
|
|
73
|
+
allowedHosts: parseListOption('--sse-allowed-hosts', 'MCP_SSE_ALLOWED_HOSTS'),
|
|
74
|
+
enableDnsRebindingProtection: parseBooleanOption('--sse-enable-dns-protection', 'MCP_SSE_ENABLE_DNS_PROTECTION', false),
|
|
61
75
|
};
|
|
62
76
|
}
|
|
63
77
|
// Parse HTTP/streamable-http config
|
|
64
|
-
if (transportType ===
|
|
65
|
-
const port = parseInt(getArgValue(
|
|
66
|
-
const host = getArgValue(
|
|
78
|
+
if (transportType === 'streamable-http') {
|
|
79
|
+
const port = parseInt(getArgValue('--http-port') || process.env.MCP_HTTP_PORT || '3001', 10);
|
|
80
|
+
const host = getArgValue('--http-host') || process.env.MCP_HTTP_HOST || '0.0.0.0';
|
|
67
81
|
return {
|
|
68
|
-
type:
|
|
82
|
+
type: 'streamable-http',
|
|
69
83
|
host,
|
|
70
84
|
port,
|
|
71
|
-
enableJsonResponse: parseBooleanOption(
|
|
72
|
-
allowedOrigins: parseListOption(
|
|
73
|
-
allowedHosts: parseListOption(
|
|
74
|
-
enableDnsRebindingProtection: parseBooleanOption(
|
|
85
|
+
enableJsonResponse: parseBooleanOption('--http-json-response', 'MCP_HTTP_ENABLE_JSON_RESPONSE', false),
|
|
86
|
+
allowedOrigins: parseListOption('--http-allowed-origins', 'MCP_HTTP_ALLOWED_ORIGINS'),
|
|
87
|
+
allowedHosts: parseListOption('--http-allowed-hosts', 'MCP_HTTP_ALLOWED_HOSTS'),
|
|
88
|
+
enableDnsRebindingProtection: parseBooleanOption('--http-enable-dns-protection', 'MCP_HTTP_ENABLE_DNS_PROTECTION', false),
|
|
75
89
|
};
|
|
76
90
|
}
|
|
77
91
|
// Stdio config (no additional options)
|
|
78
92
|
return {
|
|
79
|
-
type:
|
|
93
|
+
type: 'stdio',
|
|
80
94
|
};
|
|
81
95
|
}
|
|
82
96
|
/**
|
|
@@ -89,7 +103,7 @@ function getArgValue(argName) {
|
|
|
89
103
|
return args[i + 1];
|
|
90
104
|
}
|
|
91
105
|
if (args[i].startsWith(`${argName}=`)) {
|
|
92
|
-
return args[i].split(
|
|
106
|
+
return args[i].split('=')[1];
|
|
93
107
|
}
|
|
94
108
|
}
|
|
95
109
|
return undefined;
|
|
@@ -100,11 +114,11 @@ function getArgValue(argName) {
|
|
|
100
114
|
function parseBooleanOption(argName, envName, defaultValue) {
|
|
101
115
|
const argValue = getArgValue(argName);
|
|
102
116
|
if (argValue !== undefined) {
|
|
103
|
-
return argValue.toLowerCase() ===
|
|
117
|
+
return argValue.toLowerCase() === 'true' || argValue === '1';
|
|
104
118
|
}
|
|
105
119
|
const envValue = process.env[envName];
|
|
106
120
|
if (envValue !== undefined) {
|
|
107
|
-
return envValue.toLowerCase() ===
|
|
121
|
+
return envValue.toLowerCase() === 'true' || envValue === '1';
|
|
108
122
|
}
|
|
109
123
|
return defaultValue;
|
|
110
124
|
}
|
|
@@ -114,11 +128,17 @@ function parseBooleanOption(argName, envName, defaultValue) {
|
|
|
114
128
|
function parseListOption(argName, envName) {
|
|
115
129
|
const argValue = getArgValue(argName);
|
|
116
130
|
if (argValue) {
|
|
117
|
-
return argValue
|
|
131
|
+
return argValue
|
|
132
|
+
.split(',')
|
|
133
|
+
.map((s) => s.trim())
|
|
134
|
+
.filter((s) => s.length > 0);
|
|
118
135
|
}
|
|
119
136
|
const envValue = process.env[envName];
|
|
120
137
|
if (envValue) {
|
|
121
|
-
return envValue
|
|
138
|
+
return envValue
|
|
139
|
+
.split(',')
|
|
140
|
+
.map((s) => s.trim())
|
|
141
|
+
.filter((s) => s.length > 0);
|
|
122
142
|
}
|
|
123
143
|
return undefined;
|
|
124
144
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BTP Proxy - Proxies requests to MCP servers with JWT authentication
|
|
3
|
+
*
|
|
4
|
+
* For requests with x-btp-destination, proxies to target MCP server
|
|
5
|
+
* with JWT token from auth-broker (XSUAA/BTP)
|
|
6
|
+
*/
|
|
7
|
+
import { AuthBroker } from '@mcp-abap-adt/auth-broker';
|
|
8
|
+
import { type ProxyConfig } from '../lib/config.js';
|
|
9
|
+
import type { RoutingDecision } from '../router/headerAnalyzer.js';
|
|
10
|
+
/**
|
|
11
|
+
* Check if error messages should be written to stderr
|
|
12
|
+
* Only output in verbose mode and not in test environment
|
|
13
|
+
*/
|
|
14
|
+
export declare function shouldWriteStderr(): boolean;
|
|
15
|
+
export interface GenericProxyRequest {
|
|
16
|
+
method: string;
|
|
17
|
+
url?: string;
|
|
18
|
+
data?: unknown;
|
|
19
|
+
id?: string | number | null;
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
}
|
|
22
|
+
export type ProxyRequest = GenericProxyRequest;
|
|
23
|
+
export interface ProxyResponse {
|
|
24
|
+
jsonrpc: string;
|
|
25
|
+
id?: string | number | null;
|
|
26
|
+
result?: unknown;
|
|
27
|
+
error?: {
|
|
28
|
+
code: number;
|
|
29
|
+
message: string;
|
|
30
|
+
data?: unknown;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* BTP Proxy Client
|
|
35
|
+
*/
|
|
36
|
+
export declare class BtpProxy {
|
|
37
|
+
private axiosInstance;
|
|
38
|
+
private defaultBtpAuthBroker;
|
|
39
|
+
private btpAuthBrokers;
|
|
40
|
+
private tokenCache;
|
|
41
|
+
private readonly TOKEN_CACHE_TTL;
|
|
42
|
+
private circuitBreaker;
|
|
43
|
+
private config;
|
|
44
|
+
private unsafe;
|
|
45
|
+
constructor(defaultBtpAuthBroker: AuthBroker, config?: Partial<ProxyConfig>);
|
|
46
|
+
/**
|
|
47
|
+
* Initialize authentication for destination (eager auth)
|
|
48
|
+
* This triggers the browser authentication flow immediately if needed.
|
|
49
|
+
*/
|
|
50
|
+
initialize(destination: string): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Get or create BTP auth broker for specific destination
|
|
53
|
+
* If destination is not provided, returns default broker
|
|
54
|
+
* If broker doesn't exist in map, creates new one and stores it
|
|
55
|
+
*/
|
|
56
|
+
private getOrCreateBtpAuthBroker;
|
|
57
|
+
/**
|
|
58
|
+
* Helper to ensure valid serviceUrl in session if override provided
|
|
59
|
+
*/
|
|
60
|
+
private ensureSessionServiceUrl;
|
|
61
|
+
/**
|
|
62
|
+
* Get JWT token for BTP destination from auth-broker with retry and token refresh
|
|
63
|
+
* @param destination Destination name
|
|
64
|
+
* @param forceRefresh Force token refresh
|
|
65
|
+
*/
|
|
66
|
+
private getJwtToken;
|
|
67
|
+
/**
|
|
68
|
+
* Helper function to extract string value from header (handles arrays)
|
|
69
|
+
*/
|
|
70
|
+
private getHeaderValue;
|
|
71
|
+
/**
|
|
72
|
+
* Build proxy request with JWT token (BTP authentication only)
|
|
73
|
+
*
|
|
74
|
+
* Process flow:
|
|
75
|
+
*
|
|
76
|
+
* 1. BTP Authentication (XSUAA):
|
|
77
|
+
* 1.1 If x-btp-destination header exists:
|
|
78
|
+
* - Check map for broker with key = destination, get or create, save to map
|
|
79
|
+
* - Get token from xsuaa broker
|
|
80
|
+
* - Add/replace Authorization: Bearer <token> header
|
|
81
|
+
* 1.2 If header doesn't exist but --btp parameter exists:
|
|
82
|
+
* - Use destination from parameter, get or create broker, save to map
|
|
83
|
+
* - Get token from xsuaa broker
|
|
84
|
+
* - Add/replace Authorization: Bearer <token> header
|
|
85
|
+
* 1.3 If neither header nor parameter:
|
|
86
|
+
* - Do nothing, pass request further
|
|
87
|
+
*/
|
|
88
|
+
private buildProxyRequest;
|
|
89
|
+
/**
|
|
90
|
+
* Proxy MCP request to target server with retry, circuit breaker, and error handling
|
|
91
|
+
*/
|
|
92
|
+
proxyRequest(originalRequest: ProxyRequest, routingDecision: RoutingDecision, originalHeaders: Record<string, string | string[] | undefined>): Promise<ProxyResponse>;
|
|
93
|
+
/**
|
|
94
|
+
* Create a new BtpProxy instance
|
|
95
|
+
*/
|
|
96
|
+
static create(config?: Partial<ProxyConfig>): Promise<BtpProxy>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Factory function to create BtpProxy
|
|
100
|
+
*/
|
|
101
|
+
export declare function createBtpProxy(config?: Partial<ProxyConfig>): Promise<BtpProxy>;
|
|
102
|
+
//# sourceMappingURL=btpProxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"btpProxy.d.ts","sourceRoot":"","sources":["../../src/proxy/btpProxy.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAgB,MAAM,2BAA2B,CAAC;AAYrE,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGhE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AA4CnE;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAU3C;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAGD,MAAM,MAAM,YAAY,GAAG,mBAAmB,CAAC;AAE/C,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,OAAO,CAAC;KAChB,CAAC;CACH;AAED;;GAEG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,oBAAoB,CAAa;IACzC,OAAO,CAAC,cAAc,CAAsC;IAC5D,OAAO,CAAC,UAAU,CACN;IACZ,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAkB;IAClD,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,MAAM,CAAU;gBAEZ,oBAAoB,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC;IAqF3E;;;OAGG;IACU,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAuB3D;;;;OAIG;YACW,wBAAwB;IAqFtC;;OAEG;YACW,uBAAuB;IAyFrC;;;;OAIG;YACW,WAAW;IAwHzB;;OAEG;IACH,OAAO,CAAC,cAAc;IAUtB;;;;;;;;;;;;;;;;OAgBG;YACW,iBAAiB;IAmT/B;;OAEG;IACG,YAAY,CAChB,eAAe,EAAE,YAAY,EAC7B,eAAe,EAAE,eAAe,EAChC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,GAC7D,OAAO,CAAC,aAAa,CAAC;IA8JzB;;OAEG;WACiB,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC;CAyB7E;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,MAAM,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,GAC5B,OAAO,CAAC,QAAQ,CAAC,CAEnB"}
|