@mcp-abap-adt/header-validator 0.1.0 → 0.1.2
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 +15 -0
- package/dist/headerValidator.js +49 -17
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.1.2] - 2025-11-30
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- **Improved header validation logic** - Absence of headers is no longer treated as an error (allows .env file usage)
|
|
12
|
+
- **MCP destination validation** - `validateMcpDestinationAuth` now accepts optional `sapUrl` parameter and validates it internally
|
|
13
|
+
- **Better error handling** - Validator returns empty errors array when no headers provided (not an error, user may use .env file)
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
- **Test updates** - Updated tests to reflect new validation logic where missing headers are not errors
|
|
17
|
+
|
|
18
|
+
## [0.1.1] - 2025-11-30
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
- Initial published version
|
|
22
|
+
|
|
8
23
|
## [0.1.0] - 2025-11-30
|
|
9
24
|
|
|
10
25
|
### Added
|
package/dist/headerValidator.js
CHANGED
|
@@ -94,6 +94,7 @@ function validateSapDestinationAuth(headers) {
|
|
|
94
94
|
/**
|
|
95
95
|
* Validate MCP destination-based authentication (medium-high priority)
|
|
96
96
|
* x-mcp-destination - uses AuthBroker, always JWT (no x-sap-auth-type needed)
|
|
97
|
+
* x-sap-url is required for MCP destination (unlike x-sap-destination)
|
|
97
98
|
*/
|
|
98
99
|
function validateMcpDestinationAuth(headers, sapUrl) {
|
|
99
100
|
const destinationRaw = headers['x-mcp-destination'];
|
|
@@ -109,7 +110,18 @@ function validateMcpDestinationAuth(headers, sapUrl) {
|
|
|
109
110
|
return {
|
|
110
111
|
priority: types_1.AuthMethodPriority.NONE,
|
|
111
112
|
authType: 'jwt', // MCP destination always uses JWT
|
|
112
|
-
sapUrl,
|
|
113
|
+
sapUrl: sapUrl || '',
|
|
114
|
+
errors,
|
|
115
|
+
warnings,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
// x-sap-url is required for MCP destination
|
|
119
|
+
if (!sapUrl) {
|
|
120
|
+
errors.push('x-sap-url header is required when x-mcp-destination is present');
|
|
121
|
+
return {
|
|
122
|
+
priority: types_1.AuthMethodPriority.NONE,
|
|
123
|
+
authType: 'jwt',
|
|
124
|
+
sapUrl: '',
|
|
113
125
|
errors,
|
|
114
126
|
warnings,
|
|
115
127
|
};
|
|
@@ -224,11 +236,11 @@ function validateBasicAuth(headers, sapUrl, authType) {
|
|
|
224
236
|
* @returns Validation result with prioritized authentication configuration
|
|
225
237
|
*/
|
|
226
238
|
function validateAuthHeaders(headers) {
|
|
227
|
-
// No headers provided
|
|
239
|
+
// No headers provided - this is not an error, user may be using .env file
|
|
228
240
|
if (!headers) {
|
|
229
241
|
return {
|
|
230
242
|
isValid: false,
|
|
231
|
-
errors: [
|
|
243
|
+
errors: [],
|
|
232
244
|
warnings: [],
|
|
233
245
|
};
|
|
234
246
|
}
|
|
@@ -255,24 +267,44 @@ function validateAuthHeaders(headers) {
|
|
|
255
267
|
};
|
|
256
268
|
}
|
|
257
269
|
}
|
|
258
|
-
// For other auth methods, x-sap-url is required
|
|
270
|
+
// For other auth methods, x-sap-url is required (but MCP destination can work without it if URL is optional)
|
|
259
271
|
const sapUrl = getHeaderValue(headers, 'x-sap-url');
|
|
260
|
-
//
|
|
261
|
-
if (
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
272
|
+
// Check for MCP destination (requires x-sap-url header)
|
|
273
|
+
if (sapUrl) {
|
|
274
|
+
// Validate URL format first
|
|
275
|
+
if (!isValidUrl(sapUrl)) {
|
|
276
|
+
errors.push(`x-sap-url is not a valid URL: ${sapUrl}`);
|
|
277
|
+
return {
|
|
278
|
+
isValid: false,
|
|
279
|
+
errors,
|
|
280
|
+
warnings,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
const mcpDestinationConfig = validateMcpDestinationAuth(headers, sapUrl);
|
|
284
|
+
if (mcpDestinationConfig) {
|
|
285
|
+
if (mcpDestinationConfig.errors.length === 0) {
|
|
286
|
+
return {
|
|
287
|
+
isValid: true,
|
|
288
|
+
config: mcpDestinationConfig,
|
|
289
|
+
errors: [],
|
|
290
|
+
warnings: mcpDestinationConfig.warnings,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
return {
|
|
295
|
+
isValid: false,
|
|
296
|
+
errors: mcpDestinationConfig.errors,
|
|
297
|
+
warnings: mcpDestinationConfig.warnings,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
}
|
|
268
301
|
}
|
|
269
|
-
//
|
|
270
|
-
if (!
|
|
271
|
-
errors.push(`x-sap-url is not a valid URL: ${sapUrl}`);
|
|
302
|
+
// If no auth headers at all, return empty result (not an error - may use .env file)
|
|
303
|
+
if (!sapUrl) {
|
|
272
304
|
return {
|
|
273
305
|
isValid: false,
|
|
274
|
-
errors,
|
|
275
|
-
warnings,
|
|
306
|
+
errors: [],
|
|
307
|
+
warnings: [],
|
|
276
308
|
};
|
|
277
309
|
}
|
|
278
310
|
// Try to validate authentication methods in priority order
|
package/package.json
CHANGED