@mcp-abap-adt/connection 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.
Files changed (2) hide show
  1. package/README.md +362 -53
  2. package/package.json +4 -9
package/README.md CHANGED
@@ -1,80 +1,389 @@
1
1
  # @mcp-abap-adt/connection
2
2
 
3
- ABAP connection layer for MCP ABAP ADT server.
3
+ 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.
4
+
5
+ ## Key Features
6
+
7
+ - ๐Ÿ” **Multiple Authentication Methods**:
8
+ - Basic Auth for on-premise SAP systems
9
+ - JWT/OAuth2 for SAP BTP ABAP Environment
10
+ - ๐Ÿ”„ **Automatic JWT Token Refresh**:
11
+ - Detects expired tokens (401/403 errors)
12
+ - Automatically refreshes using OAuth2 refresh token
13
+ - Distinguishes between auth errors and permission errors
14
+ - No manual intervention required
15
+ - ๐Ÿ’พ **Stateful Sessions**:
16
+ - Persistent session management with CSRF tokens and cookies
17
+ - Custom storage backends (file system, database, Redis, etc.)
18
+ - Automatic session state save/load
19
+ - ๐Ÿ—๏ธ **Clean Architecture**:
20
+ - Abstract base class for common HTTP/session logic
21
+ - Auth-type specific implementations (BaseAbapConnection, JwtAbapConnection)
22
+ - Proper separation of concerns - no JWT logic in base class
23
+ - ๐Ÿ“ **Custom Logging**: Pluggable logger interface for integration with any logging system
24
+ - ๐Ÿ› ๏ธ **CLI Tool**: See [JWT Auth Tools](./docs/JWT_AUTH_TOOLS.md) for obtaining SAP BTP tokens
25
+ - ๐Ÿ“ฆ **TypeScript**: Full TypeScript support with type definitions included
26
+ - โšก **Timeout Management**: Configurable timeouts for different operation types
27
+
28
+ ## Architecture
29
+
30
+ The package uses a clean separation of concerns:
31
+
32
+ - **`AbstractAbapConnection`** (abstract, internal only):
33
+ - Common HTTP request logic
34
+ - Session management (cookies, CSRF tokens)
35
+ - CSRF token fetching with retry
36
+ - Auth-agnostic - knows nothing about Basic or JWT
37
+
38
+ - **`BaseAbapConnection`** (concrete, exported):
39
+ - Basic Authentication implementation
40
+ - Simple connect() - fetches CSRF token
41
+ - Suitable for on-premise SAP systems
42
+
43
+ - **`JwtAbapConnection`** (concrete, exported):
44
+ - JWT/OAuth2 Authentication implementation
45
+ - Smart connect() - detects expired tokens and auto-refreshes
46
+ - Permission vs auth error detection
47
+ - Suitable for SAP BTP ABAP Environment
48
+
49
+ ## Documentation
50
+
51
+ - ๐Ÿ“ฆ **[Installation Guide](./docs/INSTALLATION.md)** - Setup and installation instructions
52
+ - ๐Ÿ“š **[Usage Guide](./docs/USAGE.md)** - Detailed usage examples and API documentation
53
+ - ๐Ÿงช **[Testing Guide](./docs/AUTO_REFRESH_TESTING.md)** - Auto-refresh testing and troubleshooting
54
+ - ๐Ÿ”ง **[Session Storage](./docs/CUSTOM_SESSION_STORAGE.md)** - Custom session storage implementation
55
+ - ๐Ÿ” **[Stateful Session Guide (Connection)](./docs/STATEFUL_SESSION_GUIDE.md)** - Cookies, CSRF tokens, and session storage responsibilities
56
+ - ๐Ÿ’ก **[Examples](./examples/)** - Working code examples
57
+
58
+ ## Features
59
+
60
+ - ๐Ÿ” **Multiple Authentication Methods**: Basic Auth for on-premise systems, JWT/OAuth2 for SAP BTP ABAP Environment
61
+ - ๐Ÿ”„ **Auto Token Refresh**: Automatic JWT token refresh when expired (for cloud systems)
62
+ - ๐Ÿ’พ **Stateful Sessions**: Support for persistent sessions with CSRF token and cookie management
63
+ - ๐Ÿ“ **Custom Logging**: Pluggable logger interface for integration with any logging system
64
+ - ๐Ÿ› ๏ธ **CLI Tool**: Built-in authentication helper for SAP BTP service key authentication
65
+ - ๐Ÿ“ฆ **TypeScript**: Full TypeScript support with type definitions included
66
+ - โšก **Timeout Management**: Configurable timeouts for different operation types
4
67
 
5
68
  ## Installation
6
69
 
7
- ### From Git Repository
70
+ ```bash
71
+ npm install @mcp-abap-adt/connection
72
+ ```
73
+
74
+ For detailed installation instructions, see [Installation Guide](./docs/INSTALLATION.md).
75
+
76
+ ## Quick Start
77
+
78
+ ### Basic Usage (On-Premise)
79
+
80
+ ```typescript
81
+ import { createAbapConnection, SapConfig } from "@mcp-abap-adt/connection";
82
+
83
+ const config: SapConfig = {
84
+ url: "https://your-sap-system.com",
85
+ client: "100",
86
+ authType: "basic",
87
+ username: "your-username",
88
+ password: "your-password",
89
+ };
90
+
91
+ // Create a simple logger
92
+ const logger = {
93
+ info: (msg: string, meta?: any) => console.log(msg, meta),
94
+ error: (msg: string, meta?: any) => console.error(msg, meta),
95
+ warn: (msg: string, meta?: any) => console.warn(msg, meta),
96
+ debug: (msg: string, meta?: any) => console.debug(msg, meta),
97
+ };
98
+
99
+ // Create connection
100
+ const connection = createAbapConnection(config, logger);
101
+
102
+ // Make ADT request
103
+ const response = await connection.makeAdtRequest({
104
+ method: "GET",
105
+ url: "/sap/bc/adt/programs/programs/your-program",
106
+ });
107
+ ```
108
+
109
+ ### Cloud Usage (JWT/OAuth2 with Auto-Refresh)
110
+
111
+ ```typescript
112
+ import { createAbapConnection, SapConfig } from "@mcp-abap-adt/connection";
113
+
114
+ // JWT configuration with refresh token for auto-refresh
115
+ const config: SapConfig = {
116
+ url: "https://your-instance.abap.cloud.sap",
117
+ client: "100", // Optional
118
+ authType: "jwt",
119
+ jwtToken: "your-jwt-token-here", // Obtained via OAuth2 flow
120
+ // For auto-refresh support:
121
+ refreshToken: "your-refresh-token",
122
+ uaaUrl: "https://your-tenant.authentication.cert.eu10.hana.ondemand.com",
123
+ uaaClientId: "your-client-id",
124
+ uaaClientSecret: "your-client-secret",
125
+ };
126
+
127
+ const logger = {
128
+ info: (msg: string, meta?: any) => console.log(msg, meta),
129
+ error: (msg: string, meta?: any) => console.error(msg, meta),
130
+ warn: (msg: string, meta?: any) => console.warn(msg, meta),
131
+ debug: (msg: string, meta?: any) => console.debug(msg, meta),
132
+ };
133
+
134
+ const connection = createAbapConnection(config, logger);
135
+
136
+ // Token will be automatically refreshed if expired during requests
137
+ const response = await connection.makeAdtRequest({
138
+ method: "GET",
139
+ url: "/sap/bc/adt/programs/programs/your-program",
140
+ });
141
+
142
+ // How auto-refresh works:
143
+ // 1. If JWT token expired โ†’ SAP returns 401/403
144
+ // 2. Connection detects this is auth error (not permission error)
145
+ // 3. Automatically calls refresh token endpoint
146
+ // 4. Retries the request with new token
147
+ // 5. User doesn't need to handle this manually
148
+ ```
149
+
150
+ ### Stateful Sessions
151
+
152
+ For operations that require session state (e.g., object modifications), you can enable stateful sessions:
153
+
154
+ ```typescript
155
+ import {
156
+ createAbapConnection,
157
+ ISessionStorage,
158
+ SessionState,
159
+ } from "@mcp-abap-adt/connection";
160
+
161
+ // Implement session storage (e.g., file system, database, memory)
162
+ class FileSessionStorage implements ISessionStorage {
163
+ async save(sessionId: string, state: SessionState): Promise<void> {
164
+ // Save to file system
165
+ await fs.writeFile(
166
+ `sessions/${sessionId}.json`,
167
+ JSON.stringify(state, null, 2)
168
+ );
169
+ }
170
+
171
+ async load(sessionId: string): Promise<SessionState | null> {
172
+ // Load from file system
173
+ const data = await fs.readFile(`sessions/${sessionId}.json`, "utf-8");
174
+ return JSON.parse(data);
175
+ }
176
+
177
+ async delete(sessionId: string): Promise<void> {
178
+ // Delete from file system
179
+ await fs.unlink(`sessions/${sessionId}.json`);
180
+ }
181
+ }
182
+
183
+ const connection = createAbapConnection(config, logger);
184
+ const sessionStorage = new FileSessionStorage();
185
+
186
+ // Enable stateful session
187
+ await connection.enableStatefulSession("my-session-id", sessionStorage);
188
+
189
+ // Now CSRF tokens and cookies are automatically managed
190
+ await connection.makeAdtRequest({
191
+ method: "POST",
192
+ url: "/sap/bc/adt/objects/domains",
193
+ data: { /* domain data */ },
194
+ });
195
+ ```
196
+
197
+ ### Custom Logger
198
+
199
+ ```typescript
200
+ import { ILogger } from "@mcp-abap-adt/connection";
201
+
202
+ class MyLogger implements ILogger {
203
+ info(message: string, meta?: any): void {
204
+ // Your logging implementation
205
+ }
206
+
207
+ error(message: string, meta?: any): void {
208
+ // Your logging implementation
209
+ }
210
+
211
+ warn(message: string, meta?: any): void {
212
+ // Your logging implementation
213
+ }
214
+
215
+ debug(message: string, meta?: any): void {
216
+ // Your logging implementation
217
+ }
218
+
219
+ csrfToken(action: "fetch" | "retry" | "success" | "error", message: string, meta?: any): void {
220
+ // CSRF token specific logging
221
+ }
222
+
223
+ tlsConfig(rejectUnauthorized: boolean): void {
224
+ // TLS configuration logging
225
+ }
226
+ }
227
+
228
+ const logger = new MyLogger();
229
+ const connection = createAbapConnection(config, logger);
230
+ ```
231
+
232
+ ## CLI Tool
233
+
234
+ The package includes a CLI tool for authenticating with SAP BTP using service keys:
235
+
236
+ ### Installation Options
237
+
238
+ - **Local project install**
239
+ ```bash
240
+ npm install @mcp-abap-adt/connection --save-dev
241
+ npx sap-abap-auth auth -k path/to/service-key.json
242
+ ```
243
+ - **Global install**
244
+ ```bash
245
+ npm install -g @mcp-abap-adt/connection
246
+ sap-abap-auth auth -k path/to/service-key.json
247
+ ```
248
+ - **On-demand (npx)**
249
+ ```bash
250
+ npx @mcp-abap-adt/connection sap-abap-auth auth -k path/to/service-key.json
251
+ ```
252
+
253
+ ### Usage
8
254
 
9
255
  ```bash
10
- # Clone this repository
11
- git clone https://github.com/fr0ster/mcp-abap-connection.git
12
- cd mcp-abap-connection
256
+ # Show help
257
+ sap-abap-auth --help
13
258
 
14
- # Install dependencies
15
- # If used as submodule in monorepo, use: npm run install:local
16
- # Otherwise, regular npm install works fine
17
- npm install
259
+ # Authenticate with service key
260
+ sap-abap-auth auth -k service-key.json
18
261
 
19
- # Build
20
- npm run build
262
+ # Specify browser
263
+ sap-abap-auth auth -k service-key.json --browser chrome
264
+
265
+ # Custom output file
266
+ sap-abap-auth auth -k service-key.json --output .env.production
21
267
  ```
22
268
 
23
- ### From Tarball Archive
269
+ ### Options
270
+
271
+ - `-k, --key <path>` - Path to service key JSON file (required)
272
+ - `-b, --browser <name>` - Browser to open (chrome, edge, firefox, system, none)
273
+ - `-o, --output <path>` - Path to output .env file (default: .env)
274
+ - `-h, --help` - Show help message
275
+
276
+ ### Using via `npx` (without global install)
277
+
278
+ If `@mcp-abap-adt/connection` is listed as a dependency in your project, you can invoke the CLI directly:
24
279
 
25
280
  ```bash
26
- # Generate archive (in package directory)
27
- npm run pack
28
- # Creates: mcp-abap-adt-connection-0.1.0.tgz
281
+ npx sap-abap-auth auth -k service-key.json
282
+ ```
283
+
284
+ This works even when you do not install the package globally. For one-off usage, you can also run:
29
285
 
30
- # Install from archive (in consuming project)
31
- npm install ./path/to/mcp-abap-adt-connection-0.1.0.tgz
286
+ ```bash
287
+ npx @mcp-abap-adt/connection sap-abap-auth auth -k service-key.json
32
288
  ```
33
289
 
34
- Or in `package.json`:
35
- ```json
36
- {
37
- "dependencies": {
38
- "@mcp-abap-adt/connection": "file:./archives/mcp-abap-adt-connection-0.1.0.tgz"
39
- }
290
+ This will download the package on demand and execute the CLI.
291
+ ## API Reference
292
+
293
+ ### Types
294
+
295
+ #### `SapConfig`
296
+
297
+ Configuration for SAP ABAP connection.
298
+
299
+ ```typescript
300
+ type SapConfig = {
301
+ url: string;
302
+ client?: string;
303
+ authType: "basic" | "jwt";
304
+ // For basic auth
305
+ username?: string;
306
+ password?: string;
307
+ // For JWT auth
308
+ jwtToken?: string;
309
+ };
310
+ ```
311
+
312
+ #### `AbapConnection`
313
+
314
+ Main interface for ABAP connections.
315
+
316
+ ```typescript
317
+ interface AbapConnection {
318
+ makeAdtRequest(options: AbapRequestOptions): Promise<AxiosResponse>;
319
+ reset(): void;
320
+ enableStatefulSession(sessionId: string, storage: ISessionStorage): Promise<void>;
321
+ disableStatefulSession(): void;
322
+ getSessionMode(): "stateless" | "stateful";
40
323
  }
41
324
  ```
42
325
 
43
- **Note:** This package is completely self-contained and has no dependencies on other `@mcp-abap-adt/*` packages.
326
+ #### `ILogger`
44
327
 
45
- ## Usage
328
+ Logger interface for custom logging implementations.
46
329
 
47
330
  ```typescript
48
- import { createAbapConnection } from '@mcp-abap-adt/connection';
49
-
50
- // Basic authentication
51
- const connection = createAbapConnection({
52
- url: 'https://your-sap-system.com',
53
- authType: 'basic',
54
- username: 'user',
55
- password: 'pass',
56
- client: '100'
57
- });
331
+ interface ILogger {
332
+ info(message: string, meta?: any): void;
333
+ error(message: string, meta?: any): void;
334
+ warn(message: string, meta?: any): void;
335
+ debug(message: string, meta?: any): void;
336
+ csrfToken?(action: "fetch" | "retry" | "success" | "error", message: string, meta?: any): void;
337
+ tlsConfig?(rejectUnauthorized: boolean): void;
338
+ }
339
+ ```
58
340
 
59
- // JWT authentication
60
- const connection = createAbapConnection({
61
- url: 'https://your-sap-system.com',
62
- authType: 'jwt',
63
- jwtToken: 'your-jwt-token',
64
- refreshToken: 'your-refresh-token',
65
- uaaUrl: 'https://uaa-url.com',
66
- uaaClientId: 'client-id',
67
- uaaClientSecret: 'client-secret'
68
- });
341
+ #### `ISessionStorage`
69
342
 
70
- // Make ADT request
71
- const response = await connection.makeAdtRequest({
72
- url: '/sap/bc/adt/oo/classes',
73
- method: 'GET',
74
- timeout: 30000
75
- });
343
+ Interface for session state persistence.
344
+
345
+ ```typescript
346
+ interface ISessionStorage {
347
+ save(sessionId: string, state: SessionState): Promise<void>;
348
+ load(sessionId: string): Promise<SessionState | null>;
349
+ delete(sessionId: string): Promise<void>;
350
+ }
76
351
  ```
77
352
 
78
- ## Development
353
+ ### Functions
354
+
355
+ #### `createAbapConnection(config, logger, sessionStorage?, sessionId?)`
356
+
357
+ Factory function to create an ABAP connection instance.
358
+
359
+ ```typescript
360
+ function createAbapConnection(
361
+ config: SapConfig,
362
+ logger: ILogger,
363
+ sessionStorage?: ISessionStorage,
364
+ sessionId?: string
365
+ ): AbapConnection;
366
+ ```
367
+
368
+ ## Requirements
369
+
370
+ - Node.js >= 18.0.0
371
+ - Access to SAP ABAP system (on-premise or BTP)
372
+
373
+ ## Documentation
374
+
375
+ - [Custom Session Storage](./CUSTOM_SESSION_STORAGE.md) - How to implement custom session persistence (database, Redis, etc.)
376
+ - [Examples](./examples/README.md) - Working code examples
377
+
378
+ ## License
379
+
380
+ MIT
381
+
382
+ ## Repository
383
+
384
+ https://github.com/fr0ster/mcp-abap-adt
385
+
386
+ ## Related Projects
387
+
388
+ - [mcp-abap-adt](https://github.com/fr0ster/mcp-abap-adt) - Main MCP server for ABAP ADT
79
389
 
80
- This package is developed independently. For development setup, see the repository's documentation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcp-abap-adt/connection",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "ABAP connection layer for MCP ABAP ADT server",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -36,8 +36,6 @@
36
36
  "clean": "rm -rf dist tsconfig.tsbuildinfo",
37
37
  "build": "npm run clean --silent && npx tsc -p tsconfig.json",
38
38
  "build:fast": "npx tsc -p tsconfig.json",
39
- "install:local": "npm install --no-workspaces",
40
- "pack": "npm run build && npm pack",
41
39
  "test": "jest",
42
40
  "prepublishOnly": "npm run build"
43
41
  },
@@ -51,13 +49,10 @@
51
49
  "open": "^11.0.0"
52
50
  },
53
51
  "devDependencies": {
54
- "@types/jest": "^30.0.0",
55
- "@types/node": "^24.10.1",
56
- "jest": "^30.2.0",
52
+ "@types/jest": "^29.5.14",
53
+ "@types/node": "^24.2.1",
54
+ "jest": "^29.7.0",
57
55
  "ts-jest": "^29.2.5",
58
56
  "typescript": "^5.9.2"
59
- },
60
- "publishConfig": {
61
- "access": "public"
62
57
  }
63
58
  }