@mcp-abap-adt/proxy 2.0.0 → 4.0.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 (67) hide show
  1. package/CHANGELOG.md +218 -0
  2. package/LICENSE +669 -17
  3. package/README.md +79 -8
  4. package/bin/mcp-abap-adt-proxy-mcp.js +113 -0
  5. package/dist/index.d.ts +10 -4
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +54 -97
  8. package/dist/lib/config.d.ts.map +1 -1
  9. package/dist/lib/config.js +9 -1
  10. package/dist/lib/envInterpolation.d.ts +14 -2
  11. package/dist/lib/envInterpolation.d.ts.map +1 -1
  12. package/dist/lib/envInterpolation.js +34 -7
  13. package/dist/lib/stores.d.ts +23 -2
  14. package/dist/lib/stores.d.ts.map +1 -1
  15. package/dist/lib/stores.js +56 -1
  16. package/dist/mcp/cli.d.ts +2 -0
  17. package/dist/mcp/cli.d.ts.map +1 -0
  18. package/dist/mcp/cli.js +21 -0
  19. package/dist/mcp/configs.d.ts +33 -0
  20. package/dist/mcp/configs.d.ts.map +1 -0
  21. package/dist/mcp/configs.js +142 -0
  22. package/dist/mcp/ports.d.ts +15 -0
  23. package/dist/mcp/ports.d.ts.map +1 -0
  24. package/dist/mcp/ports.js +35 -0
  25. package/dist/mcp/registry.d.ts +57 -0
  26. package/dist/mcp/registry.d.ts.map +1 -0
  27. package/dist/mcp/registry.js +145 -0
  28. package/dist/mcp/server.d.ts +34 -0
  29. package/dist/mcp/server.d.ts.map +1 -0
  30. package/dist/mcp/server.js +79 -0
  31. package/dist/mcp/shutdown.d.ts +37 -0
  32. package/dist/mcp/shutdown.d.ts.map +1 -0
  33. package/dist/mcp/shutdown.js +82 -0
  34. package/dist/mcp/supervisor.d.ts +125 -0
  35. package/dist/mcp/supervisor.d.ts.map +1 -0
  36. package/dist/mcp/supervisor.js +330 -0
  37. package/dist/mcp/tools.d.ts +28 -0
  38. package/dist/mcp/tools.d.ts.map +1 -0
  39. package/dist/mcp/tools.js +152 -0
  40. package/dist/proxy/btpProxy.d.ts +24 -73
  41. package/dist/proxy/btpProxy.d.ts.map +1 -1
  42. package/dist/proxy/btpProxy.js +65 -616
  43. package/dist/proxy/credentials.d.ts +45 -0
  44. package/dist/proxy/credentials.d.ts.map +1 -0
  45. package/dist/proxy/credentials.js +41 -0
  46. package/dist/proxy/requestHandler.d.ts +38 -0
  47. package/dist/proxy/requestHandler.d.ts.map +1 -0
  48. package/dist/proxy/requestHandler.js +73 -0
  49. package/dist/proxy/reverseProxy.d.ts +11 -2
  50. package/dist/proxy/reverseProxy.d.ts.map +1 -1
  51. package/dist/proxy/reverseProxy.js +52 -9
  52. package/dist/router/headerAnalyzer.js +2 -2
  53. package/dist/router/requestInterceptor.js +9 -9
  54. package/docs/API.md +172 -0
  55. package/docs/ARCHITECTURE.md +322 -0
  56. package/docs/CLIENT_SETUP.md +413 -0
  57. package/docs/CONFIGURATION.md +258 -0
  58. package/docs/MIGRATION-4.0.md +125 -0
  59. package/docs/ROUTING_LOGIC.md +126 -0
  60. package/docs/TROUBLESHOOTING.md +488 -0
  61. package/docs/USAGE.md +422 -0
  62. package/docs/YAML_CONFIG.md +290 -0
  63. package/docs/mcp-proxy-config.example.yaml +62 -0
  64. package/package.json +17 -10
  65. package/dist/proxy/cloudLlmHubProxy.d.ts +0 -2
  66. package/dist/proxy/cloudLlmHubProxy.d.ts.map +0 -1
  67. package/dist/proxy/cloudLlmHubProxy.js +0 -3
@@ -0,0 +1,488 @@
1
+ # Troubleshooting Guide
2
+
3
+ This guide helps you diagnose and resolve common issues with `@mcp-abap-adt/proxy`.
4
+
5
+ ## Common Issues
6
+
7
+ ### 1. Server Won't Start
8
+
9
+ #### Error: "Configuration validation failed"
10
+
11
+ **Symptoms:**
12
+ - Server fails to start
13
+ - Error message about configuration validation
14
+
15
+ **Causes:**
16
+ - Missing required configuration
17
+ - Invalid configuration values
18
+ - Port conflicts
19
+
20
+ **Solutions:**
21
+
22
+ 1. **Check the BTP destination:**
23
+ ```bash
24
+ # A BTP destination is required (CLI --btp, header x-sap-destination, or btpDestination in config)
25
+ mcp-abap-adt-proxy --btp=btp-cloud
26
+ ```
27
+
28
+ 2. **Validate configuration file:**
29
+ ```bash
30
+ # Check that the YAML config parses
31
+ npx js-yaml mcp-proxy-config.yaml
32
+ ```
33
+
34
+ 3. **Check port availability:**
35
+ ```bash
36
+ # Check if port is in use
37
+ lsof -i :3001 # Linux/Mac
38
+ netstat -ano | findstr :3001 # Windows
39
+ ```
40
+
41
+ 4. **Review validation errors:**
42
+ ```bash
43
+ # Enable debug logging to see validation details
44
+ export LOG_LEVEL=debug
45
+ mcp-abap-adt-proxy --btp=btp-cloud
46
+ ```
47
+
48
+ #### Error: "Port already in use"
49
+
50
+ **Symptoms:**
51
+ - Server fails to start
52
+ - Error: "EADDRINUSE"
53
+
54
+ **Solutions:**
55
+
56
+ 1. **Use different port:**
57
+ ```bash
58
+ export MCP_HTTP_PORT=3002
59
+ mcp-abap-adt-proxy --btp=btp-cloud
60
+ ```
61
+
62
+ 2. **Kill process using port:**
63
+ ```bash
64
+ # Find process
65
+ lsof -i :3001
66
+
67
+ # Kill process
68
+ kill -9 <PID>
69
+ ```
70
+
71
+ #### Error: "Port N is already in use" naming your browserAuthPort
72
+
73
+ **Symptoms:**
74
+ - Startup fails with `Token provider error for <destination>: Port <n> is already in use. Please specify a different port or free the port.`
75
+ - The number is the one from `browserAuthPort` (or `--browser-auth-port`), not `httpPort`
76
+ - It often appears on the *second* start: the first run worked, you stopped it, and now the port is still taken
77
+
78
+ The callback port is only needed while you are logging in. It is bound when the
79
+ login window opens and released as soon as the authorization code has been
80
+ exchanged for a token — the proxy keeps running afterwards without it. So a
81
+ callback port that stays busy means something is still holding it.
82
+
83
+ **Diagnose — find out what actually holds it:**
84
+
85
+ ```bash
86
+ # Linux
87
+ ss -ltnp | grep :7777
88
+ # macOS
89
+ lsof -nP -iTCP:7777 -sTCP:LISTEN
90
+ ```
91
+
92
+ Four things it usually turns out to be:
93
+
94
+ 1. **An unrelated program on the same number.** The proxy's callback port and
95
+ another service's main port are easy to collide by accident. Check what the
96
+ command line actually is before assuming it is a proxy.
97
+
98
+ 2. **A proxy you thought you had stopped — in versions before 1.6.3.** The
99
+ launcher forwarded only `SIGINT`, so `kill`, `pkill`, a closing terminal or
100
+ an MCP client stopping the server killed the launcher and left the real
101
+ server running. Look for it under its inner name, not the CLI name:
102
+
103
+ ```bash
104
+ ps -eo pid,ppid,args | grep '[d]ist/index.js'
105
+ ```
106
+
107
+ A parent PID of 1 (or `systemd --user`) means it was orphaned. Upgrade to
108
+ 1.6.3 or later, and kill any strays once:
109
+
110
+ ```bash
111
+ pkill -f 'proxy/dist/index.js'
112
+ ```
113
+
114
+ 3. **Another proxy still inside its login window.** The port is held for the
115
+ entire interactive login, so two proxies configured with the same
116
+ `browserAuthPort` cannot log in at the same time. This is expected. Give each
117
+ config its own port, or complete one login before starting the next.
118
+
119
+ 4. **A running proxy whose previous login leaked the socket — in versions before
120
+ 1.6.4.** A callback that arrived without a `code` parameter — a reloaded tab,
121
+ a duplicate request, a port scanner — ended the login through a path that
122
+ never closed the server, so a live proxy kept the port for the rest of its
123
+ life. Unlike cause 2, the process is one you meant to be running, so it looks
124
+ innocent. Fixed in 1.6.4 via `@mcp-abap-adt/auth-providers@1.2.0`.
125
+
126
+ Since `auth-providers@2.0.0` such a request no longer ends the login at all:
127
+ it is answered `400`, counted, and the login keeps waiting. If a login then
128
+ times out, the error names the tally — `3 incomplete request(s) reached
129
+ /callback and were ignored.` — which tells you something was probing the
130
+ callback port while you were logging in.
131
+
132
+ **Note:** the main `httpPort` being free is not evidence that the proxy is gone,
133
+ but it does narrow things down. An orphaned server from before 1.6.3 held *both*
134
+ ports, so when only the callback port looks busy the culprit is one of the causes
135
+ that leaves the main port alone: an unrelated program on the same number (1), a
136
+ proxy still inside its login window (3), or — before 1.6.4 — a running proxy
137
+ whose earlier login leaked the socket (4).
138
+
139
+ ### 2. Proxy Requests Failing
140
+
141
+ #### Error: "--btp parameter is required for stdio transport"
142
+
143
+ **Symptoms:**
144
+ - Server exits immediately on stdio transport
145
+ - Error type: `STDIO_DESTINATION_REQUIRED`
146
+
147
+ **Solutions:**
148
+
149
+ For stdio/SSE transports the destination cannot come from request headers, so it must
150
+ be provided on the command line (or in a config file):
151
+ ```bash
152
+ mcp-abap-adt-proxy --transport=stdio --btp=btp-cloud
153
+ ```
154
+
155
+ #### ~~Error: "Circuit breaker is open"~~ — cannot happen since 4.0.0
156
+
157
+ The circuit breaker was removed together with the buffered forward it guarded. A
158
+ target that keeps failing now fails visibly on every request instead of being
159
+ short-circuited, so there is no state to reset and nothing to tune.
160
+ `circuitBreakerThreshold` and `circuitBreakerTimeout` are still accepted in
161
+ configuration and do nothing.
162
+
163
+ What to look at instead when requests keep failing:
164
+
165
+ 1. **Check network connectivity:**
166
+ ```bash
167
+ ping cloud-llm-hub.example.com
168
+ ```
169
+
170
+ 2. **Check the retry log.** Token acquisition is retried on failures that can get
171
+ better; each attempt logs `RETRY_ATTEMPT`, and the final failure logs
172
+ `CREDENTIAL_HEADER_ERROR` with the reason.
173
+
174
+ #### Error: "Failed to get JWT token from auth-broker"
175
+
176
+ **Symptoms:**
177
+ - Proxy requests fail
178
+ - Error about JWT token
179
+
180
+ **Causes:**
181
+ - Service key not found
182
+ - Invalid service key
183
+ - AuthBroker configuration issue
184
+
185
+ **Solutions:**
186
+
187
+ 1. **Verify service key exists:**
188
+ ```bash
189
+ # Unix
190
+ ls ~/.config/mcp-abap-adt/service-keys/sk.json
191
+
192
+ # Windows
193
+ dir %USERPROFILE%\Documents\mcp-abap-adt\service-keys\sk.json
194
+ ```
195
+
196
+ 2. **Validate service key format:**
197
+ ```json
198
+ {
199
+ "uaa": {
200
+ "url": "https://uaa-url.com",
201
+ "clientid": "client-id",
202
+ "clientsecret": "client-secret"
203
+ },
204
+ "abap": {
205
+ "url": "https://abap-url.com",
206
+ "client": "100"
207
+ }
208
+ }
209
+ ```
210
+
211
+ 3. **Check AuthBroker paths:**
212
+ ```bash
213
+ export AUTH_BROKER_PATH="/custom/path"
214
+ # Service keys will be resolved from /custom/path/service-keys
215
+ # Sessions will be resolved from /custom/path/sessions
216
+ ```
217
+
218
+ 4. **Test authentication manually:**
219
+ ```bash
220
+ npx sap-abap-auth auth -k sk.json
221
+ ```
222
+
223
+ ### 3. Routing Issues
224
+
225
+ #### Request routed incorrectly
226
+
227
+ **Symptoms:**
228
+ - Request goes to wrong destination
229
+ - Unexpected routing strategy
230
+
231
+ **Solutions:**
232
+
233
+ 1. **Check headers:**
234
+ ```bash
235
+ # Enable debug logging
236
+ export LOG_LEVEL=debug
237
+ ```
238
+
239
+ 2. **Verify header format:**
240
+ ```json
241
+ {
242
+ "headers": {
243
+ "x-sap-destination": "sk" // Must be lowercase "sk" for proxy
244
+ }
245
+ }
246
+ ```
247
+
248
+ 3. **Review routing decision logs:**
249
+ ```
250
+ [DEBUG] Routing decision made: { strategy: "proxy", destination: "sk" }
251
+ ```
252
+
253
+ #### Unknown routing strategy
254
+
255
+ **Symptoms:**
256
+ - Error: "Unknown routing strategy"
257
+ - Request rejected
258
+
259
+ **Causes:**
260
+ - Missing required destination
261
+ - Neither `x-sap-destination` header nor `--btp` CLI parameter provided
262
+
263
+ **Solutions:**
264
+
265
+ 1. **Provide a BTP destination:**
266
+ - `x-sap-destination` header (HTTP/SSE), or
267
+ - `--btp` CLI parameter / `btpDestination` in the config file
268
+
269
+ 2. **Review header validation:**
270
+ ```bash
271
+ # Check validation errors in logs
272
+ export LOG_LEVEL=debug
273
+ ```
274
+
275
+ ### 4. Connection Issues
276
+
277
+ #### Error: "Failed to connect to target server"
278
+
279
+ **Symptoms:**
280
+ - Proxy requests fail with connection errors
281
+
282
+ **Solutions:**
283
+
284
+ 1. **Verify destination service key:**
285
+ ```bash
286
+ # Check service key exists
287
+ ls ~/.config/mcp-abap-adt/service-keys/<destination>.json
288
+ ```
289
+
290
+ 2. **Check network connectivity:**
291
+ ```bash
292
+ # Test target URL
293
+ curl -I https://your-mcp-server.com
294
+ ```
295
+
296
+ ### 5. Performance Issues
297
+
298
+ #### High Latency
299
+
300
+ **Symptoms:**
301
+ - Requests take too long
302
+ - Timeout errors
303
+
304
+ **Solutions:**
305
+
306
+ 1. **Increase timeout:**
307
+ ```json
308
+ {
309
+ "requestTimeout": 120000
310
+ }
311
+ ```
312
+
313
+ 2. **Check network latency:**
314
+ ```bash
315
+ ping cloud-llm-hub.example.com
316
+ ```
317
+
318
+ 3. **Review retry settings:**
319
+ ```json
320
+ {
321
+ "maxRetries": 2, // Reduce retries for faster failure
322
+ "retryDelay": 500 // Reduce delay
323
+ }
324
+ ```
325
+
326
+ #### Memory Issues
327
+
328
+ **Symptoms:**
329
+ - High memory usage
330
+ - Server crashes
331
+
332
+ **Solutions:**
333
+
334
+ 1. **Check connection cache size:**
335
+ ```bash
336
+ # Connection cache auto-cleans after 100 entries
337
+ # Old connections are removed after 1 hour
338
+ ```
339
+
340
+ 2. **Reduce cache TTL:**
341
+ ```typescript
342
+ // Modify in code if needed
343
+ const TOKEN_CACHE_TTL = 15 * 60 * 1000; // 15 minutes instead of 30
344
+ ```
345
+
346
+ 3. **Monitor connection count:**
347
+ ```bash
348
+ # Check logs for connection creation
349
+ export LOG_LEVEL=debug
350
+ ```
351
+
352
+ ### 6. Token Issues
353
+
354
+ #### Token Expiration Errors
355
+
356
+ **Symptoms:**
357
+ - 401/403 errors
358
+ - "Token expired" messages
359
+
360
+ **Solutions:**
361
+
362
+ 1. **Token refresh is automatic:**
363
+ - Proxy detects token expiration
364
+ - Automatically refreshes token
365
+ - Retries request with new token
366
+
367
+ 2. **Check token cache:**
368
+ ```bash
369
+ # Tokens are cached for 30 minutes
370
+ # On 401/403 the proxy automatically clears the cache and retries with a fresh token
371
+ ```
372
+
373
+ 3. **Verify service key:**
374
+ ```bash
375
+ # Ensure service key has valid UAA credentials
376
+ npx sap-abap-auth auth -k sk.json
377
+ ```
378
+
379
+ #### Token Not Found
380
+
381
+ **Symptoms:**
382
+ - "No authentication found for destination"
383
+
384
+ **Solutions:**
385
+
386
+ 1. **Create service key file:**
387
+ ```bash
388
+ # Place in platform-specific location
389
+ # Unix: ~/.config/mcp-abap-adt/service-keys/sk.json
390
+ # Windows: %USERPROFILE%\Documents\mcp-abap-adt\service-keys\sk.json
391
+ ```
392
+
393
+ 2. **Use custom path:**
394
+ ```bash
395
+ export AUTH_BROKER_PATH="/custom/path"
396
+ # Supports both base path and explicit subfolder paths
397
+ # /custom/path -> /custom/path/service-keys
398
+ # /custom/path/service-keys -> /custom/path/service-keys
399
+ ```
400
+
401
+ 3. **Check file permissions:**
402
+ ```bash
403
+ # Ensure file is readable
404
+ chmod 644 sk.json
405
+ ```
406
+
407
+ ## Debugging Tips
408
+
409
+ ### Enable Debug Logging
410
+
411
+ ```bash
412
+ export LOG_LEVEL=debug
413
+ mcp-abap-adt-proxy --btp=btp-cloud
414
+ ```
415
+
416
+ ### Check Routing Decisions
417
+
418
+ Look for logs like:
419
+ ```
420
+ [DEBUG] Routing decision made: { strategy: "proxy", destination: "sk" }
421
+ ```
422
+
423
+ ### ~~Monitor Circuit Breaker~~ — removed in 4.0.0
424
+
425
+ There is no breaker to monitor. What is worth watching instead is
426
+ `RETRY_ATTEMPT`, logged while a token is being acquired, and
427
+ `CREDENTIAL_HEADER_ERROR` when it could not be.
428
+
429
+ ### Check Connection Cache
430
+
431
+ Look for logs like:
432
+ ```
433
+ [DEBUG] Creating new direct cloud connection
434
+ [DEBUG] Reusing cached direct cloud connection
435
+ ```
436
+
437
+ ### Verify Token Retrieval
438
+
439
+ Look for logs like:
440
+ ```
441
+ [DEBUG] Retrieved JWT token from auth-broker
442
+ [DEBUG] Using cached JWT token
443
+ ```
444
+
445
+ ## Getting Help
446
+
447
+ ### Check Logs
448
+
449
+ Always check logs first:
450
+ ```bash
451
+ # Enable debug logging
452
+ export LOG_LEVEL=debug
453
+ mcp-abap-adt-proxy 2>&1 | tee proxy.log
454
+ ```
455
+
456
+ ### Common Log Patterns
457
+
458
+ **Successful Request:**
459
+ ```
460
+ [INFO] Request intercepted
461
+ [DEBUG] Routing decision made: { strategy: "proxy" }
462
+ [DEBUG] Proxied request completed
463
+ ```
464
+
465
+ **Failed Request:**
466
+ ```
467
+ [ERROR] Failed to proxy request to cloud-llm-hub
468
+ [ERROR] Circuit breaker opened due to failures
469
+ ```
470
+
471
+ ### Report Issues
472
+
473
+ When reporting issues, include:
474
+ 1. Error messages from logs
475
+ 2. Configuration (sanitized)
476
+ 3. Request headers (sanitized)
477
+ 4. Steps to reproduce
478
+ 5. Environment details (OS, Node.js version)
479
+
480
+ ## Best Practices
481
+
482
+ 1. **Always provide a BTP destination** - via `--btp`, `x-sap-destination`, or `btpDestination` in config
483
+ 2. **Monitor circuit breaker** - Check logs for circuit breaker state
484
+ 3. **Use appropriate timeouts** - Set timeouts based on network conditions
485
+ 4. **Keep service keys secure** - Never commit service keys to version control
486
+ 5. **Enable debug logging** - Use debug mode for troubleshooting
487
+ 6. **Check network connectivity** - Verify connectivity before troubleshooting
488
+ 7. **Validate configuration** - Always validate config on startup