@mcp-abap-adt/connection 0.1.0 โ†’ 0.1.1

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 +345 -53
  2. package/package.json +4 -9
package/README.md CHANGED
@@ -1,80 +1,372 @@
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**: Built-in authentication helper for SAP BTP service key authentication
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
237
+
238
+ After installing the package, the CLI tool is available via `npx`:
8
239
 
9
240
  ```bash
10
- # Clone this repository
11
- git clone https://github.com/fr0ster/mcp-abap-connection.git
12
- cd mcp-abap-connection
241
+ npx sap-abap-auth auth -k path/to/service-key.json
242
+ ```
13
243
 
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
244
+ ### Global Installation
18
245
 
19
- # Build
20
- npm run build
246
+ ```bash
247
+ npm install -g @mcp-abap-adt/connection
248
+ sap-abap-auth auth -k path/to/service-key.json
21
249
  ```
22
250
 
23
- ### From Tarball Archive
251
+ ### Usage
24
252
 
25
253
  ```bash
26
- # Generate archive (in package directory)
27
- npm run pack
28
- # Creates: mcp-abap-adt-connection-0.1.0.tgz
254
+ # Show help
255
+ sap-abap-auth --help
256
+
257
+ # Authenticate with service key
258
+ sap-abap-auth auth -k service-key.json
259
+
260
+ # Specify browser
261
+ sap-abap-auth auth -k service-key.json --browser chrome
29
262
 
30
- # Install from archive (in consuming project)
31
- npm install ./path/to/mcp-abap-adt-connection-0.1.0.tgz
263
+ # Custom output file
264
+ sap-abap-auth auth -k service-key.json --output .env.production
32
265
  ```
33
266
 
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
- }
267
+ ### Options
268
+
269
+ - `-k, --key <path>` - Path to service key JSON file (required)
270
+ - `-b, --browser <name>` - Browser to open (chrome, edge, firefox, system, none)
271
+ - `-o, --output <path>` - Path to output .env file (default: .env)
272
+ - `-h, --help` - Show help message
273
+
274
+ ## API Reference
275
+
276
+ ### Types
277
+
278
+ #### `SapConfig`
279
+
280
+ Configuration for SAP ABAP connection.
281
+
282
+ ```typescript
283
+ type SapConfig = {
284
+ url: string;
285
+ client?: string;
286
+ authType: "basic" | "jwt";
287
+ // For basic auth
288
+ username?: string;
289
+ password?: string;
290
+ // For JWT auth
291
+ jwtToken?: string;
292
+ };
293
+ ```
294
+
295
+ #### `AbapConnection`
296
+
297
+ Main interface for ABAP connections.
298
+
299
+ ```typescript
300
+ interface AbapConnection {
301
+ makeAdtRequest(options: AbapRequestOptions): Promise<AxiosResponse>;
302
+ reset(): void;
303
+ enableStatefulSession(sessionId: string, storage: ISessionStorage): Promise<void>;
304
+ disableStatefulSession(): void;
305
+ getSessionMode(): "stateless" | "stateful";
40
306
  }
41
307
  ```
42
308
 
43
- **Note:** This package is completely self-contained and has no dependencies on other `@mcp-abap-adt/*` packages.
309
+ #### `ILogger`
44
310
 
45
- ## Usage
311
+ Logger interface for custom logging implementations.
46
312
 
47
313
  ```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
- });
314
+ interface ILogger {
315
+ info(message: string, meta?: any): void;
316
+ error(message: string, meta?: any): void;
317
+ warn(message: string, meta?: any): void;
318
+ debug(message: string, meta?: any): void;
319
+ csrfToken?(action: "fetch" | "retry" | "success" | "error", message: string, meta?: any): void;
320
+ tlsConfig?(rejectUnauthorized: boolean): void;
321
+ }
322
+ ```
58
323
 
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
- });
324
+ #### `ISessionStorage`
69
325
 
70
- // Make ADT request
71
- const response = await connection.makeAdtRequest({
72
- url: '/sap/bc/adt/oo/classes',
73
- method: 'GET',
74
- timeout: 30000
75
- });
326
+ Interface for session state persistence.
327
+
328
+ ```typescript
329
+ interface ISessionStorage {
330
+ save(sessionId: string, state: SessionState): Promise<void>;
331
+ load(sessionId: string): Promise<SessionState | null>;
332
+ delete(sessionId: string): Promise<void>;
333
+ }
334
+ ```
335
+
336
+ ### Functions
337
+
338
+ #### `createAbapConnection(config, logger, sessionStorage?, sessionId?)`
339
+
340
+ Factory function to create an ABAP connection instance.
341
+
342
+ ```typescript
343
+ function createAbapConnection(
344
+ config: SapConfig,
345
+ logger: ILogger,
346
+ sessionStorage?: ISessionStorage,
347
+ sessionId?: string
348
+ ): AbapConnection;
76
349
  ```
77
350
 
78
- ## Development
351
+ ## Requirements
352
+
353
+ - Node.js >= 18.0.0
354
+ - Access to SAP ABAP system (on-premise or BTP)
355
+
356
+ ## Documentation
357
+
358
+ - [Custom Session Storage](./CUSTOM_SESSION_STORAGE.md) - How to implement custom session persistence (database, Redis, etc.)
359
+ - [Examples](./examples/README.md) - Working code examples
360
+
361
+ ## License
362
+
363
+ MIT
364
+
365
+ ## Repository
366
+
367
+ https://github.com/fr0ster/mcp-abap-adt
368
+
369
+ ## Related Projects
370
+
371
+ - [mcp-abap-adt](https://github.com/fr0ster/mcp-abap-adt) - Main MCP server for ABAP ADT
79
372
 
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.1",
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
  }