@abapify/adt-mcp 0.3.5 → 0.4.4
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/README.md +140 -48
- package/dist/bin/adt-mcp-http.d.mts +1 -0
- package/dist/bin/adt-mcp-http.mjs +311 -0
- package/dist/bin/adt-mcp-http.mjs.map +1 -0
- package/dist/bin/adt-mcp.d.mts +1 -0
- package/dist/bin/adt-mcp.mjs +18 -0
- package/dist/bin/adt-mcp.mjs.map +1 -0
- package/dist/index.d.mts +707 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +164 -0
- package/dist/index.mjs.map +1 -0
- package/dist/mock.d.mts +2 -0
- package/dist/mock.mjs +3 -0
- package/dist/server-5bFocUjx.mjs +1561 -0
- package/dist/server-5bFocUjx.mjs.map +1 -0
- package/dist/server-Dj44Rgau.mjs +7254 -0
- package/dist/server-Dj44Rgau.mjs.map +1 -0
- package/package.json +21 -13
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,707 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { AdtClient } from "@abapify/adt-client";
|
|
3
|
+
import { KeyObject } from "node:crypto";
|
|
4
|
+
import { FlowConfig } from "@abapify/adt-config";
|
|
5
|
+
import { CryptoKey } from "jose";
|
|
6
|
+
import http from "node:http";
|
|
7
|
+
//#region src/lib/session/changeset.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Session-scoped changeset state (Wave 3).
|
|
10
|
+
*
|
|
11
|
+
* A `Changeset` is an ordered list of object writes + their lock handles
|
|
12
|
+
* acquired during the "open" phase of a unit-of-work. Source code PUTs
|
|
13
|
+
* happen eagerly inside `changeset_add` (i.e. the source is persisted to
|
|
14
|
+
* SAP under lock), but the objects remain INACTIVE until `changeset_commit`
|
|
15
|
+
* runs a single batch activation.
|
|
16
|
+
*
|
|
17
|
+
* Rollback semantics (important — document for callers):
|
|
18
|
+
* - `changeset_rollback` releases every lock (best-effort) and sets
|
|
19
|
+
* `status = 'rolled_back'`.
|
|
20
|
+
* - It does NOT revert the source PUTs. SAP has no transactional
|
|
21
|
+
* "discard changes" API over ADT; the inactive version stays on the
|
|
22
|
+
* system until the next edit/activate cycle. This matches what
|
|
23
|
+
* Eclipse ADT does when a developer closes the editor without
|
|
24
|
+
* activating.
|
|
25
|
+
*
|
|
26
|
+
* The changeset itself lives on the `SapSessionContext` of an MCP HTTP
|
|
27
|
+
* session. Under stdio, tools fall back to ephemeral per-call state — the
|
|
28
|
+
* changeset tools therefore require an HTTP session to operate.
|
|
29
|
+
*/
|
|
30
|
+
type ChangesetStatus = 'open' | 'committing' | 'committed' | 'rolled_back';
|
|
31
|
+
interface ChangesetEntry {
|
|
32
|
+
/** Fully-qualified ADT object URI (e.g. `/sap/bc/adt/oo/classes/zcl_demo`). */
|
|
33
|
+
objectUri: string;
|
|
34
|
+
/** Short SAP object type (e.g. `CLAS`, `INTF`, `PROG`). */
|
|
35
|
+
objectType: string;
|
|
36
|
+
/** Upper-cased object name for display / activation payload. */
|
|
37
|
+
objectName: string;
|
|
38
|
+
/** Lock handle returned by the ADT lock service. */
|
|
39
|
+
lockHandle: string;
|
|
40
|
+
/** High-level intent. `update` is the only value today; `create` is reserved. */
|
|
41
|
+
action: 'update' | 'create';
|
|
42
|
+
/** Milliseconds since epoch at which the entry was recorded. */
|
|
43
|
+
createdAt: number;
|
|
44
|
+
}
|
|
45
|
+
interface Changeset {
|
|
46
|
+
/** Opaque identifier (UUID v4) returned to callers. */
|
|
47
|
+
id: string;
|
|
48
|
+
/** Milliseconds since epoch. */
|
|
49
|
+
openedAt: number;
|
|
50
|
+
/** Lifecycle state. */
|
|
51
|
+
status: ChangesetStatus;
|
|
52
|
+
/** Entries, ordered by insertion. */
|
|
53
|
+
entries: ChangesetEntry[];
|
|
54
|
+
/** Optional free-text description supplied by the caller. */
|
|
55
|
+
description?: string;
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/lib/session/types.d.ts
|
|
59
|
+
interface SapSessionContext {
|
|
60
|
+
/** MCP session id (the value of the `Mcp-Session-Id` header). */
|
|
61
|
+
mcpSessionId: string;
|
|
62
|
+
/** Wall-clock timestamp (ms) when the session was created. */
|
|
63
|
+
createdAt: number;
|
|
64
|
+
/** Wall-clock timestamp (ms) of the last observed activity. */
|
|
65
|
+
lastUsedAt: number;
|
|
66
|
+
/** Optional logical system identifier (from multi-system config). */
|
|
67
|
+
systemId?: string;
|
|
68
|
+
/** Authenticated ADT client scoped to this session. */
|
|
69
|
+
client: AdtClient;
|
|
70
|
+
/** Object URIs currently locked by this session. */
|
|
71
|
+
locks: Set<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Pending transactional unit-of-work for this session (Wave 3). When
|
|
74
|
+
* set, `changeset.status === 'open'` means locks are held and at least
|
|
75
|
+
* one source PUT has happened but no activation has run yet.
|
|
76
|
+
*/
|
|
77
|
+
changeset?: Changeset;
|
|
78
|
+
/**
|
|
79
|
+
* Releases SAP-side resources (locks, security session). Must be
|
|
80
|
+
* idempotent — the registry may call it more than once under races.
|
|
81
|
+
*/
|
|
82
|
+
close: () => Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/lib/session/registry.d.ts
|
|
86
|
+
interface SessionRegistry {
|
|
87
|
+
/**
|
|
88
|
+
* Registers a new session. The caller provides everything except the
|
|
89
|
+
* housekeeping fields (`createdAt`, `lastUsedAt`) and the idempotent
|
|
90
|
+
* `close` handler, which is supplied as a separate argument so the
|
|
91
|
+
* registry can wrap it for idempotency.
|
|
92
|
+
*/
|
|
93
|
+
create(mcpSessionId: string, ctx: Omit<SapSessionContext, 'close' | 'createdAt' | 'lastUsedAt' | 'mcpSessionId'>, close: () => Promise<void>): SapSessionContext;
|
|
94
|
+
get(mcpSessionId: string): SapSessionContext | undefined;
|
|
95
|
+
touch(mcpSessionId: string): void;
|
|
96
|
+
/** Removes the session and invokes its close handler. */
|
|
97
|
+
delete(mcpSessionId: string): Promise<void>;
|
|
98
|
+
list(): SapSessionContext[];
|
|
99
|
+
/** Closes every session and stops background timers. */
|
|
100
|
+
shutdown(): Promise<void>;
|
|
101
|
+
}
|
|
102
|
+
interface SessionRegistryOptions {
|
|
103
|
+
/**
|
|
104
|
+
* Idle TTL in milliseconds. Sessions with `now - lastUsedAt > ttlMs`
|
|
105
|
+
* are evicted by a background sweep. Defaults to 30 minutes.
|
|
106
|
+
* Set to 0 to disable TTL sweeping.
|
|
107
|
+
*/
|
|
108
|
+
ttlMs?: number;
|
|
109
|
+
/** Sweep interval in ms. Defaults to `min(ttlMs / 4, 60_000)`. */
|
|
110
|
+
sweepIntervalMs?: number;
|
|
111
|
+
}
|
|
112
|
+
declare function createSessionRegistry(options?: SessionRegistryOptions): SessionRegistry;
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/lib/session/destination-registry.d.ts
|
|
115
|
+
interface RequestIdentity {
|
|
116
|
+
principal: string;
|
|
117
|
+
agentId?: string;
|
|
118
|
+
}
|
|
119
|
+
/** Private lease material is deliberately opaque to MCP and REST handlers. */
|
|
120
|
+
interface DestinationLease {
|
|
121
|
+
destination: string;
|
|
122
|
+
expiresAt: number;
|
|
123
|
+
version: number;
|
|
124
|
+
/**
|
|
125
|
+
* Private broker material. It is deliberately opaque and is only passed to
|
|
126
|
+
* the context factory inside this process; MCP/REST handlers never receive
|
|
127
|
+
* or serialise it.
|
|
128
|
+
*/
|
|
129
|
+
material: unknown;
|
|
130
|
+
/** Idempotent broker/secret cleanup. */
|
|
131
|
+
release(): Promise<void>;
|
|
132
|
+
}
|
|
133
|
+
interface DestinationLeaseProvider {
|
|
134
|
+
acquire(input: {
|
|
135
|
+
destination: string;
|
|
136
|
+
identity: RequestIdentity;
|
|
137
|
+
}): Promise<DestinationLease>;
|
|
138
|
+
}
|
|
139
|
+
interface DestinationContext {
|
|
140
|
+
mcpSessionId: string;
|
|
141
|
+
destination: string;
|
|
142
|
+
lease: DestinationLease;
|
|
143
|
+
client: AdtClient;
|
|
144
|
+
locks: Set<string>;
|
|
145
|
+
changeset?: Changeset;
|
|
146
|
+
createdAt: number;
|
|
147
|
+
lastUsedAt: number;
|
|
148
|
+
/** Serialise mutation work for this context without blocking other keys. */
|
|
149
|
+
runExclusive<T>(operation: () => Promise<T>): Promise<T>;
|
|
150
|
+
close(): Promise<void>;
|
|
151
|
+
}
|
|
152
|
+
interface DestinationContextFactory {
|
|
153
|
+
create(input: {
|
|
154
|
+
mcpSessionId: string;
|
|
155
|
+
destination: string;
|
|
156
|
+
lease: DestinationLease;
|
|
157
|
+
}): Promise<{
|
|
158
|
+
client: AdtClient;
|
|
159
|
+
locks?: Set<string>;
|
|
160
|
+
changeset?: Changeset;
|
|
161
|
+
close(): Promise<void>;
|
|
162
|
+
}>;
|
|
163
|
+
}
|
|
164
|
+
interface DestinationContextRegistry {
|
|
165
|
+
get(mcpSessionId: string, destination: string): DestinationContext | undefined;
|
|
166
|
+
getOrCreate(mcpSessionId: string, destination: string, identity: RequestIdentity): Promise<DestinationContext>;
|
|
167
|
+
touch(mcpSessionId: string, destination: string): void;
|
|
168
|
+
release(mcpSessionId: string, destination: string): Promise<void>;
|
|
169
|
+
releaseAll(mcpSessionId: string): Promise<void>;
|
|
170
|
+
list(): DestinationContext[];
|
|
171
|
+
shutdown(): Promise<void>;
|
|
172
|
+
}
|
|
173
|
+
interface DestinationContextRegistryOptions {
|
|
174
|
+
leaseProvider: DestinationLeaseProvider;
|
|
175
|
+
contextFactory: DestinationContextFactory;
|
|
176
|
+
ttlMs?: number;
|
|
177
|
+
sweepIntervalMs?: number;
|
|
178
|
+
now?: () => number;
|
|
179
|
+
}
|
|
180
|
+
declare function createDestinationContextRegistry(options: DestinationContextRegistryOptions): DestinationContextRegistry;
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region src/lib/http/invocation.d.ts
|
|
183
|
+
type McpTrustedOperationClass = 'server' | 'read' | 'safe_execute';
|
|
184
|
+
type McpInvocationJsonValue = boolean | number | string | null | readonly McpInvocationJsonValue[] | Readonly<Record<string, McpInvocationJsonValue>>;
|
|
185
|
+
/** Claims proved by a verified, ADT-issued invocation credential. */
|
|
186
|
+
interface TrustedMcpInvocationClaims {
|
|
187
|
+
readonly tokenId: string;
|
|
188
|
+
readonly principal: string;
|
|
189
|
+
readonly agentId: 'ai-review' | 'system-assistant' | 'autonomous-review-agent' | 'adt-execution' | 'delegated-assistant';
|
|
190
|
+
readonly classes: readonly McpTrustedOperationClass[];
|
|
191
|
+
readonly destinationKeys: readonly string[];
|
|
192
|
+
readonly correlationId: string;
|
|
193
|
+
readonly constraint: Readonly<Record<string, McpInvocationJsonValue>>;
|
|
194
|
+
readonly limits: Readonly<Record<string, McpInvocationJsonValue>>;
|
|
195
|
+
}
|
|
196
|
+
type SafeExecutePolicy = {
|
|
197
|
+
readonly operationId: 'atc_run';
|
|
198
|
+
readonly check: 'atc';
|
|
199
|
+
readonly maxDurationMs: number;
|
|
200
|
+
readonly maxResultBytes: number;
|
|
201
|
+
readonly maxFindings: number;
|
|
202
|
+
readonly maxObjects: number;
|
|
203
|
+
readonly maxPackages: number;
|
|
204
|
+
readonly maxVariants: number;
|
|
205
|
+
} | {
|
|
206
|
+
readonly operationId: 'run_unit_tests';
|
|
207
|
+
readonly check: 'aunit';
|
|
208
|
+
readonly effectiveWithCoverage: false;
|
|
209
|
+
readonly effectiveCoverageFormat: null;
|
|
210
|
+
readonly maxDurationMs: number;
|
|
211
|
+
readonly maxResultBytes: number;
|
|
212
|
+
readonly maxFindings: number;
|
|
213
|
+
readonly maxObjects: number;
|
|
214
|
+
readonly maxTestClasses: number;
|
|
215
|
+
readonly maxTestMethods: number;
|
|
216
|
+
} | {
|
|
217
|
+
readonly operationId: 'run_unit_tests';
|
|
218
|
+
readonly check: 'coverage';
|
|
219
|
+
readonly effectiveWithCoverage: true;
|
|
220
|
+
readonly effectiveCoverageFormat: 'jacoco' | 'sonar-generic';
|
|
221
|
+
readonly maxDurationMs: number;
|
|
222
|
+
readonly maxResultBytes: number;
|
|
223
|
+
readonly maxFindings: number;
|
|
224
|
+
readonly maxObjects: number;
|
|
225
|
+
readonly maxPrograms: number;
|
|
226
|
+
readonly maxMeasurements: number;
|
|
227
|
+
};
|
|
228
|
+
interface ScopedAdtInvocationPolicy {
|
|
229
|
+
readonly scopeId: string;
|
|
230
|
+
readonly executionId: string;
|
|
231
|
+
readonly systemSid: string;
|
|
232
|
+
readonly resourceKeys: readonly string[];
|
|
233
|
+
readonly toolNames: readonly string[];
|
|
234
|
+
readonly operationClass: 'read' | 'safe_execute';
|
|
235
|
+
readonly maxToolCalls: number;
|
|
236
|
+
readonly safeExecutePolicy?: SafeExecutePolicy;
|
|
237
|
+
/** Server-owned opaque grant material; never exposed in a tool schema. */
|
|
238
|
+
readonly authorizationId?: string;
|
|
239
|
+
readonly authorizationToken?: string;
|
|
240
|
+
}
|
|
241
|
+
interface DelegatedAssistantReadPolicy {
|
|
242
|
+
readonly threadId: string;
|
|
243
|
+
readonly executionId: string;
|
|
244
|
+
readonly systemSid: string;
|
|
245
|
+
}
|
|
246
|
+
interface McpInvocationVerifierOptions {
|
|
247
|
+
/** ES256 public key mounted at ADT Server; it cannot issue credentials. */
|
|
248
|
+
publicKey: CryptoKey | KeyObject;
|
|
249
|
+
/** The exact key id required in both JWS header and JWT payload. */
|
|
250
|
+
keyId: string;
|
|
251
|
+
/** The exact ADT API issuer expected in `iss`. */
|
|
252
|
+
issuer: string;
|
|
253
|
+
/** The exact audience expected in `aud`. */
|
|
254
|
+
audience: string;
|
|
255
|
+
/** Test-only clock injection. Production defaults to the current time. */
|
|
256
|
+
now?: () => Date | number;
|
|
257
|
+
}
|
|
258
|
+
interface McpInvocationVerifier {
|
|
259
|
+
/**
|
|
260
|
+
* Verify a complete `Authorization: Bearer <JWS>` header. Validation
|
|
261
|
+
* failures are intentionally indistinguishable and return `undefined`.
|
|
262
|
+
*/
|
|
263
|
+
verify(authorizationHeader: string | string[] | undefined): Promise<TrustedMcpInvocationClaims | undefined>;
|
|
264
|
+
}
|
|
265
|
+
declare function parseDelegatedAssistantReadPolicy(claims: TrustedMcpInvocationClaims): DelegatedAssistantReadPolicy | undefined;
|
|
266
|
+
declare function parseSafeExecutePolicy(value: unknown): SafeExecutePolicy | undefined;
|
|
267
|
+
declare function parseScopedAdtInvocationPolicy(claims: TrustedMcpInvocationClaims): ScopedAdtInvocationPolicy | undefined;
|
|
268
|
+
/**
|
|
269
|
+
* Build a fail-closed verifier for the one ADT-Server invocation key.
|
|
270
|
+
* Configuration failures throw before serving traffic; credential failures
|
|
271
|
+
* always resolve to `undefined` without logging token-derived information.
|
|
272
|
+
*/
|
|
273
|
+
declare function createMcpInvocationVerifier(options: McpInvocationVerifierOptions): McpInvocationVerifier;
|
|
274
|
+
//#endregion
|
|
275
|
+
//#region src/lib/tools/scope-catalogue.d.ts
|
|
276
|
+
type McpOperationClass = 'server' | 'read' | 'safe_execute' | 'write';
|
|
277
|
+
interface McpRequestAccess {
|
|
278
|
+
/** Explicit trusted classes. `write` is never inferred from `read`. */
|
|
279
|
+
classes: readonly McpOperationClass[];
|
|
280
|
+
/** Explicit trusted destination keys. An empty list authorises no SAP I/O. */
|
|
281
|
+
destinationKeys: readonly string[];
|
|
282
|
+
/** A typed signed policy that removes ambient AI Review read authority. */
|
|
283
|
+
frozenSource?: McpFrozenSourceAccess;
|
|
284
|
+
/** Exact execution-scoped Scoped catalogue and dispatch policy. */
|
|
285
|
+
scoped?: McpScopedAccess;
|
|
286
|
+
/** Delegated-assistant read policy — binds tool calls to a signed thread/execution/system. */
|
|
287
|
+
delegated?: McpDelegatedAccess;
|
|
288
|
+
}
|
|
289
|
+
interface McpDelegatedAccess {
|
|
290
|
+
readonly threadId: string;
|
|
291
|
+
readonly executionId: string;
|
|
292
|
+
readonly systemSid: string;
|
|
293
|
+
}
|
|
294
|
+
interface McpScopedAccess {
|
|
295
|
+
readonly tokenId: string;
|
|
296
|
+
readonly principal: string;
|
|
297
|
+
readonly correlationId: string;
|
|
298
|
+
readonly scopeId: string;
|
|
299
|
+
readonly executionId: string;
|
|
300
|
+
readonly systemSid: string;
|
|
301
|
+
readonly resourceKeys: readonly string[];
|
|
302
|
+
readonly toolNames: readonly string[];
|
|
303
|
+
readonly operationClass: 'read' | 'safe_execute';
|
|
304
|
+
readonly maxToolCalls: number;
|
|
305
|
+
readonly safeExecutePolicy?: SafeExecutePolicy;
|
|
306
|
+
readonly authorizationId?: string;
|
|
307
|
+
readonly authorizationToken?: string;
|
|
308
|
+
}
|
|
309
|
+
interface McpFrozenSourceAccess {
|
|
310
|
+
readonly systemSid: string;
|
|
311
|
+
readonly sources: readonly {
|
|
312
|
+
readonly canonicalKey: string;
|
|
313
|
+
/** Immutable source component within the canonical review object. */
|
|
314
|
+
readonly componentId: string;
|
|
315
|
+
/** Opaque ADT capability; never accepted as a model/tool argument. */
|
|
316
|
+
readonly sourceRef: string;
|
|
317
|
+
}[];
|
|
318
|
+
readonly maxSourceBytes: number;
|
|
319
|
+
}
|
|
320
|
+
type StaticToolScope = {
|
|
321
|
+
operationClass: McpOperationClass;
|
|
322
|
+
};
|
|
323
|
+
type DynamicToolScope = {
|
|
324
|
+
/** Every validated action and the operation class it requires. */
|
|
325
|
+
actionClasses: Readonly<Record<string, McpOperationClass>>;
|
|
326
|
+
};
|
|
327
|
+
type McpToolScope = StaticToolScope | DynamicToolScope;
|
|
328
|
+
/**
|
|
329
|
+
* Every registered MCP tool has one entry. A mixed-action tool resolves its
|
|
330
|
+
* operation class from validated arguments; the default remains `write`.
|
|
331
|
+
*/
|
|
332
|
+
declare const MCP_TOOL_SCOPE_CATALOGUE: Readonly<Record<string, McpToolScope>>;
|
|
333
|
+
/** Unknown or ambiguous operations fail closed as `write`. */
|
|
334
|
+
declare function operationClassForMcpTool(name: string, arguments_?: Record<string, unknown>): McpOperationClass;
|
|
335
|
+
/** Registration fails when a newly added tool lacks an explicit catalogue row. */
|
|
336
|
+
declare function assertMcpToolIsClassified(name: string): void;
|
|
337
|
+
declare function isMcpToolAllowed(access: McpRequestAccess | undefined, name: string, arguments_?: Record<string, unknown>): boolean;
|
|
338
|
+
//#endregion
|
|
339
|
+
//#region src/lib/source-capabilities.d.ts
|
|
340
|
+
interface SourceCapabilityRegistryOptions {
|
|
341
|
+
now?: () => number;
|
|
342
|
+
ttlMs?: number;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Keeps opaque source-read capabilities in the sidecar process. A capability
|
|
346
|
+
* is an unguessable handle rather than an encoded URI, so neither the client
|
|
347
|
+
* nor an MCP transcript can recover SAP path details from it.
|
|
348
|
+
*/
|
|
349
|
+
declare function createSourceCapabilityRegistry(options?: SourceCapabilityRegistryOptions): {
|
|
350
|
+
issue(input: {
|
|
351
|
+
sessionId?: string;
|
|
352
|
+
destination?: string;
|
|
353
|
+
sourceUri: string;
|
|
354
|
+
}): string;
|
|
355
|
+
resolve(input: {
|
|
356
|
+
sourceCapability: string;
|
|
357
|
+
sessionId?: string;
|
|
358
|
+
destination?: string;
|
|
359
|
+
}): {
|
|
360
|
+
sourceUri: string;
|
|
361
|
+
};
|
|
362
|
+
};
|
|
363
|
+
//#endregion
|
|
364
|
+
//#region src/lib/types.d.ts
|
|
365
|
+
/**
|
|
366
|
+
* Connection parameters that every tool receives.
|
|
367
|
+
*
|
|
368
|
+
* - `baseUrl`: Base ADT endpoint of the SAP system.
|
|
369
|
+
* - `client`: Optional SAP client to connect to.
|
|
370
|
+
* - `username`: Optional username for authentication.
|
|
371
|
+
* - `password`: Optional password for authentication.
|
|
372
|
+
*/
|
|
373
|
+
interface ConnectionParams {
|
|
374
|
+
baseUrl: string;
|
|
375
|
+
client?: string;
|
|
376
|
+
username?: string;
|
|
377
|
+
password?: string;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Context passed to each tool handler at runtime.
|
|
381
|
+
*
|
|
382
|
+
* The legacy `getClient` factory remains the primary path for stdio-mode
|
|
383
|
+
* tools that carry connection parameters in every call. HTTP-mode tools
|
|
384
|
+
* additionally get:
|
|
385
|
+
*
|
|
386
|
+
* - `registry` / `getSession` — to resolve the active `SapSessionContext`
|
|
387
|
+
* for the current MCP session (populated by future `sap_connect` tool).
|
|
388
|
+
* - `resolveSystem` — to map a logical system id (from multi-system
|
|
389
|
+
* config) to concrete connection parameters.
|
|
390
|
+
*/
|
|
391
|
+
interface ToolContext {
|
|
392
|
+
getClient: (params: ConnectionParams) => AdtClient;
|
|
393
|
+
getSession?: (mcpSessionId: string) => SapSessionContext | undefined;
|
|
394
|
+
registry?: SessionRegistry;
|
|
395
|
+
resolveSystem?: (systemId: string) => ConnectionParams | undefined;
|
|
396
|
+
/**
|
|
397
|
+
* Shared-service mode. Contexts are keyed by both MCP session and the
|
|
398
|
+
* public destination key; no connection material reaches a tool handler.
|
|
399
|
+
*/
|
|
400
|
+
destinationRegistry?: DestinationContextRegistry;
|
|
401
|
+
requestIdentity?: (extra: {
|
|
402
|
+
sessionId?: string;
|
|
403
|
+
}) => RequestIdentity;
|
|
404
|
+
requestAccess?: (extra: {
|
|
405
|
+
sessionId?: string;
|
|
406
|
+
}) => McpRequestAccess | undefined;
|
|
407
|
+
/**
|
|
408
|
+
* Atomically consumes the policy broker's opaque scoped check grant. The implementation
|
|
409
|
+
* owns ADT Server service authentication and must return true only after
|
|
410
|
+
* the policy broker responds with the successful consume result.
|
|
411
|
+
*/
|
|
412
|
+
consumeExecutionAuthorization?: (input: {
|
|
413
|
+
authorizationId: string;
|
|
414
|
+
authorizationToken: string;
|
|
415
|
+
principal: string;
|
|
416
|
+
scopeId: string;
|
|
417
|
+
executionId: string;
|
|
418
|
+
systemSid: string;
|
|
419
|
+
resourceKeys: readonly string[];
|
|
420
|
+
destination: string;
|
|
421
|
+
operationId: 'atc_run' | 'run_unit_tests';
|
|
422
|
+
policy: SafeExecutePolicy;
|
|
423
|
+
}) => Promise<boolean>;
|
|
424
|
+
/**
|
|
425
|
+
* Records the single terminal state of a consumed broker grant. It is called
|
|
426
|
+
* exactly once after the SAP operation settles and must never trigger a
|
|
427
|
+
* retry of that operation.
|
|
428
|
+
*/
|
|
429
|
+
reportExecutionOutcome?: (input: {
|
|
430
|
+
authorizationId: string;
|
|
431
|
+
authorizationToken: string;
|
|
432
|
+
outcome: 'succeeded' | 'failed' | 'outcome_unknown';
|
|
433
|
+
}) => Promise<boolean>;
|
|
434
|
+
/**
|
|
435
|
+
* Executes a consumed safe check under a runtime that can actually
|
|
436
|
+
* terminate its SAP transport at `maxDurationMs`. Returning early while the
|
|
437
|
+
* supplied operation continues is forbidden.
|
|
438
|
+
*/
|
|
439
|
+
executeWithDeadline?: (input: {
|
|
440
|
+
maxDurationMs: number;
|
|
441
|
+
operation: () => Promise<unknown>;
|
|
442
|
+
}) => Promise<unknown>;
|
|
443
|
+
/**
|
|
444
|
+
* Redeems an opaque ADT source capability after destination-mode policy has
|
|
445
|
+
* selected it. The resolver may return only a trusted server-relative URI.
|
|
446
|
+
*/
|
|
447
|
+
resolveFrozenSource?: (input: {
|
|
448
|
+
destination: string;
|
|
449
|
+
systemSid: string;
|
|
450
|
+
sourceRef: string;
|
|
451
|
+
}) => Promise<{
|
|
452
|
+
sourceUri: string;
|
|
453
|
+
}>;
|
|
454
|
+
/** Opaque, short-lived source capabilities issued by this MCP server. */
|
|
455
|
+
sourceCapabilities?: ReturnType<typeof createSourceCapabilityRegistry>;
|
|
456
|
+
/** Server-owned roots within which filesystem-mutating flow tools may act. */
|
|
457
|
+
workspaceRoots?: readonly string[];
|
|
458
|
+
/** Optional server-owned flow config; otherwise workspace config is loaded. */
|
|
459
|
+
flowConfig?: FlowConfig;
|
|
460
|
+
}
|
|
461
|
+
//#endregion
|
|
462
|
+
//#region src/lib/server.d.ts
|
|
463
|
+
interface McpServerOptions {
|
|
464
|
+
/** Override the client factory – useful for injecting a mock client in tests. */
|
|
465
|
+
clientFactory?: (params: ConnectionParams) => AdtClient;
|
|
466
|
+
/**
|
|
467
|
+
* Session registry, present only in HTTP mode. When supplied, the
|
|
468
|
+
* ToolContext exposes `registry` and a `getSession` closure so that
|
|
469
|
+
* session-scoped tools (added in a later wave) can look up the active
|
|
470
|
+
* SAP connection for the current MCP session.
|
|
471
|
+
*/
|
|
472
|
+
registry?: SessionRegistry;
|
|
473
|
+
/**
|
|
474
|
+
* Multi-system resolver. Maps a logical system id (e.g. `DEV`) to
|
|
475
|
+
* concrete `ConnectionParams`. Present only when the HTTP bin has a
|
|
476
|
+
* multi-system configuration loaded.
|
|
477
|
+
*/
|
|
478
|
+
resolveSystem?: (systemId: string) => ConnectionParams | undefined;
|
|
479
|
+
/** Enables destination-only schemas and per-destination shared contexts. */
|
|
480
|
+
destinationRegistry?: DestinationContextRegistry;
|
|
481
|
+
/** Derives an audit-safe principal from the authenticated transport. */
|
|
482
|
+
requestIdentity?: (extra: {
|
|
483
|
+
sessionId?: string;
|
|
484
|
+
}) => RequestIdentity;
|
|
485
|
+
/**
|
|
486
|
+
* Resolves explicit operation classes from trusted transport identity.
|
|
487
|
+
* Only ADT Server destination mode consumes this hook; stdio keeps its
|
|
488
|
+
* existing interactive behaviour.
|
|
489
|
+
*/
|
|
490
|
+
requestAccess?: (extra: {
|
|
491
|
+
sessionId?: string;
|
|
492
|
+
}) => McpRequestAccess | undefined;
|
|
493
|
+
/** Deployment-owned atomic authorization hook required by scoped execution. */
|
|
494
|
+
consumeExecutionAuthorization?: ToolContext['consumeExecutionAuthorization'];
|
|
495
|
+
/** Deployment-owned terminal outcome hook required by scoped execution. */
|
|
496
|
+
reportExecutionOutcome?: ToolContext['reportExecutionOutcome'];
|
|
497
|
+
/** Hard-cancellable runtime required for scoped execution. */
|
|
498
|
+
executeWithDeadline?: ToolContext['executeWithDeadline'];
|
|
499
|
+
/** Private ADT broker resolver for signed frozen-source capabilities. */
|
|
500
|
+
resolveFrozenSource: ToolContext['resolveFrozenSource'];
|
|
501
|
+
/** Filesystem roots available to workspace-mutating flow tools. */
|
|
502
|
+
workspaceRoots?: readonly string[];
|
|
503
|
+
/** Optional deployment-owned flow configuration. */
|
|
504
|
+
flowConfig?: ToolContext['flowConfig'];
|
|
505
|
+
}
|
|
506
|
+
declare function createMcpServer(options?: McpServerOptions): McpServer;
|
|
507
|
+
//#endregion
|
|
508
|
+
//#region src/lib/tools/index.d.ts
|
|
509
|
+
declare function registerTools(server: McpServer, ctx: ToolContext): void;
|
|
510
|
+
//#endregion
|
|
511
|
+
//#region src/lib/tools/utils.d.ts
|
|
512
|
+
/**
|
|
513
|
+
* Minimal structural type for the ADT client subset used by resolveObjectUri.
|
|
514
|
+
*
|
|
515
|
+
* Using a structural (duck-typed) interface rather than importing the full
|
|
516
|
+
* AdtClient type avoids coupling utils.ts to @abapify/adt-client and keeps
|
|
517
|
+
* this utility testable with any object that satisfies the shape.
|
|
518
|
+
*/
|
|
519
|
+
type QuickSearchClient = {
|
|
520
|
+
adt: {
|
|
521
|
+
repository: {
|
|
522
|
+
informationsystem: {
|
|
523
|
+
search: {
|
|
524
|
+
quickSearch(params: {
|
|
525
|
+
query: string;
|
|
526
|
+
maxResults: number;
|
|
527
|
+
}): Promise<unknown>;
|
|
528
|
+
};
|
|
529
|
+
};
|
|
530
|
+
};
|
|
531
|
+
};
|
|
532
|
+
};
|
|
533
|
+
/**
|
|
534
|
+
* Resolve the ADT URI for an ABAP object by name and optional type.
|
|
535
|
+
*
|
|
536
|
+
* Tries type-based resolution first (no network round-trip), then falls back
|
|
537
|
+
* to a quickSearch if the type is unknown or not mapped. Returns undefined
|
|
538
|
+
* when the object cannot be found.
|
|
539
|
+
*/
|
|
540
|
+
declare function resolveObjectUri(client: QuickSearchClient, objectName: string, objectType?: string): Promise<string | undefined>;
|
|
541
|
+
//#endregion
|
|
542
|
+
//#region src/lib/http/oauth.d.ts
|
|
543
|
+
interface OAuthOptions {
|
|
544
|
+
/** Expected `iss` claim, e.g. `https://company.okta.com/oauth2/default`. */
|
|
545
|
+
issuer: string;
|
|
546
|
+
/** Expected `aud` claim(s). Strongly recommended. */
|
|
547
|
+
audience?: string | string[];
|
|
548
|
+
/** Explicit JWKS endpoint; falls back to OIDC discovery when absent. */
|
|
549
|
+
jwksUri?: string;
|
|
550
|
+
/**
|
|
551
|
+
* Scopes that must be present in the token's `scope`/`scp` claim. All
|
|
552
|
+
* listed scopes are required (AND).
|
|
553
|
+
*/
|
|
554
|
+
requiredScopes?: string[];
|
|
555
|
+
/** Clock skew tolerance in seconds. Default 5. */
|
|
556
|
+
clockTolerance?: number;
|
|
557
|
+
/**
|
|
558
|
+
* Primary claim to use as the user identity. When absent the validator
|
|
559
|
+
* falls back to `preferred_username` → `email` → `sub`.
|
|
560
|
+
*/
|
|
561
|
+
userClaim?: string;
|
|
562
|
+
/** Claim to read as the user email. Default `email`. */
|
|
563
|
+
emailClaim?: string;
|
|
564
|
+
/** Claim to read as the groups array. Default `groups`. */
|
|
565
|
+
groupsClaim?: string;
|
|
566
|
+
}
|
|
567
|
+
//#endregion
|
|
568
|
+
//#region src/lib/http/auth.d.ts
|
|
569
|
+
type AuthMode = 'none' | 'bearer' | 'proxy' | 'oauth' | 'invocation';
|
|
570
|
+
interface UserHint {
|
|
571
|
+
user: string;
|
|
572
|
+
email?: string;
|
|
573
|
+
groups?: string[];
|
|
574
|
+
}
|
|
575
|
+
//#endregion
|
|
576
|
+
//#region src/lib/http/multi-system.d.ts
|
|
577
|
+
interface SystemEntry {
|
|
578
|
+
baseUrl: string;
|
|
579
|
+
client?: string;
|
|
580
|
+
}
|
|
581
|
+
interface MultiSystemConfig {
|
|
582
|
+
systems: Record<string, SystemEntry>;
|
|
583
|
+
resolve(systemId: string): ConnectionParams | undefined;
|
|
584
|
+
}
|
|
585
|
+
declare function loadMultiSystemConfig(): MultiSystemConfig;
|
|
586
|
+
//#endregion
|
|
587
|
+
//#region src/lib/http/server.d.ts
|
|
588
|
+
interface HttpServerOptions {
|
|
589
|
+
/** Port to listen on. Default: `MCP_PORT` env or 3000. */
|
|
590
|
+
port?: number;
|
|
591
|
+
/** Host to bind to. Default: `MCP_HOST` env or `127.0.0.1`. */
|
|
592
|
+
host?: string;
|
|
593
|
+
/** Idle session TTL in ms. Default: 30 minutes. */
|
|
594
|
+
ttlMs?: number;
|
|
595
|
+
/**
|
|
596
|
+
* Extra host names to accept in the `Host` header. The bound host is
|
|
597
|
+
* always accepted; `localhost`, `127.0.0.1`, and `[::1]` are accepted
|
|
598
|
+
* by default.
|
|
599
|
+
*/
|
|
600
|
+
allowedHosts?: string[];
|
|
601
|
+
/**
|
|
602
|
+
* Authentication mode for incoming requests. Defaults to `'none'` when
|
|
603
|
+
* no token / forwarded-auth flag is configured. Misconfiguration (e.g.
|
|
604
|
+
* `bearer` without a token) throws synchronously when the handler is
|
|
605
|
+
* created, including through `startHttpServer`.
|
|
606
|
+
*/
|
|
607
|
+
authMode?: AuthMode;
|
|
608
|
+
/** Bearer token (required when `authMode === 'bearer'`). */
|
|
609
|
+
authToken?: string;
|
|
610
|
+
/**
|
|
611
|
+
* Convenience flag — when true, forces `authMode='proxy'` and trusts
|
|
612
|
+
* `x-forwarded-user` from the caller. Intended for deployments behind
|
|
613
|
+
* an authenticating reverse proxy (oauth2-proxy, Cloudflare Access).
|
|
614
|
+
*/
|
|
615
|
+
trustForwardedAuth?: boolean;
|
|
616
|
+
/**
|
|
617
|
+
* OAuth / OIDC validation options (required when `authMode === 'oauth'`).
|
|
618
|
+
* Issuer, audience, JWKS, required scopes, user-claim mapping. See
|
|
619
|
+
* `./oauth.ts` for the full option list.
|
|
620
|
+
*/
|
|
621
|
+
oauth?: OAuthOptions;
|
|
622
|
+
/**
|
|
623
|
+
* ADT-issued invocation verifier (required when `authMode ===
|
|
624
|
+
* 'invocation'`). Its trusted claims are the only source for identity and
|
|
625
|
+
* scope in destination-aware sidecar mode.
|
|
626
|
+
*/
|
|
627
|
+
invocationVerifier?: McpInvocationVerifier;
|
|
628
|
+
/**
|
|
629
|
+
* Internal test hook — called with each successful OAuth `userHint`.
|
|
630
|
+
* Not part of the public API.
|
|
631
|
+
* @internal
|
|
632
|
+
*/
|
|
633
|
+
onOAuthUserHint?: (hint: UserHint | undefined) => void;
|
|
634
|
+
/**
|
|
635
|
+
* CORS allow-list. Exact-match origins only (plus `'*'` for dev).
|
|
636
|
+
* Undefined or empty = CORS disabled (no headers added).
|
|
637
|
+
*/
|
|
638
|
+
allowedOrigins?: string[];
|
|
639
|
+
/** Override the multi-system config loader (mainly for tests). */
|
|
640
|
+
multiSystem?: MultiSystemConfig;
|
|
641
|
+
/** Override the session registry (mainly for tests). */
|
|
642
|
+
registry?: SessionRegistry;
|
|
643
|
+
/** Path to the PEM-encoded TLS certificate; also read from MCP_TLS_CERT. */
|
|
644
|
+
tlsCert?: string;
|
|
645
|
+
/** Path to the PEM-encoded TLS private key; also read from MCP_TLS_KEY. */
|
|
646
|
+
tlsKey?: string;
|
|
647
|
+
/** Inline PEM-encoded TLS certificate (useful for embedders and tests). */
|
|
648
|
+
tlsCertContent?: string;
|
|
649
|
+
/** Inline PEM-encoded TLS private key (useful for embedders and tests). */
|
|
650
|
+
tlsKeyContent?: string;
|
|
651
|
+
/**
|
|
652
|
+
* Enables destination-aware shared-server mode. Access and identity are
|
|
653
|
+
* derived only from the authenticated request's trusted `UserHint` at MCP
|
|
654
|
+
* session initialization, then captured for the life of that session.
|
|
655
|
+
*/
|
|
656
|
+
destinationServer?: {
|
|
657
|
+
destinationRegistry: DestinationContextRegistry;
|
|
658
|
+
requestIdentity: (input: {
|
|
659
|
+
userHint?: UserHint;
|
|
660
|
+
invocation?: TrustedMcpInvocationClaims;
|
|
661
|
+
}) => RequestIdentity;
|
|
662
|
+
requestAccess: (input: {
|
|
663
|
+
userHint?: UserHint;
|
|
664
|
+
invocation?: TrustedMcpInvocationClaims;
|
|
665
|
+
}) => McpRequestAccess | undefined;
|
|
666
|
+
resolveFrozenSource?: NonNullable<ToolContext['resolveFrozenSource']>;
|
|
667
|
+
consumeExecutionAuthorization?: NonNullable<ToolContext['consumeExecutionAuthorization']>;
|
|
668
|
+
reportExecutionOutcome?: NonNullable<ToolContext['reportExecutionOutcome']>;
|
|
669
|
+
executeWithDeadline?: NonNullable<ToolContext['executeWithDeadline']>;
|
|
670
|
+
};
|
|
671
|
+
/** Inject a logger that writes to stderr by default. */
|
|
672
|
+
log?: (level: 'info' | 'warn' | 'error', msg: string) => void;
|
|
673
|
+
}
|
|
674
|
+
interface RunningHttpServer {
|
|
675
|
+
readonly url: string;
|
|
676
|
+
readonly port: number;
|
|
677
|
+
readonly host: string;
|
|
678
|
+
readonly registry: SessionRegistry;
|
|
679
|
+
close(): Promise<void>;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* A reusable Streamable HTTP MCP request handler.
|
|
683
|
+
*
|
|
684
|
+
* The embedding application owns its Node listener and delegates only the
|
|
685
|
+
* requests routed to MCP to `handle`. Calling `close` releases MCP sessions
|
|
686
|
+
* and transports, but deliberately never closes that listener.
|
|
687
|
+
*/
|
|
688
|
+
interface HttpMcpHandler {
|
|
689
|
+
readonly registry: SessionRegistry;
|
|
690
|
+
handle(req: http.IncomingMessage, res: http.ServerResponse): Promise<void>;
|
|
691
|
+
close(): Promise<void>;
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Creates a reusable MCP HTTP handler without binding a Node listener.
|
|
695
|
+
*/
|
|
696
|
+
declare function createHttpMcpHandler(options?: HttpServerOptions): HttpMcpHandler;
|
|
697
|
+
/**
|
|
698
|
+
* Starts the HTTP transport and returns a handle that can be used to close
|
|
699
|
+
* both the listener and all active MCP sessions gracefully.
|
|
700
|
+
*
|
|
701
|
+
* This is a backwards-compatible listener adapter around
|
|
702
|
+
* `createHttpMcpHandler` for standalone deployments.
|
|
703
|
+
*/
|
|
704
|
+
declare function startHttpServer(options?: HttpServerOptions): Promise<RunningHttpServer>;
|
|
705
|
+
//#endregion
|
|
706
|
+
export { type ConnectionParams, type DelegatedAssistantReadPolicy, type DestinationContext, type DestinationContextFactory, type DestinationContextRegistry, type DestinationContextRegistryOptions, type DestinationLease, type DestinationLeaseProvider, type HttpMcpHandler, type HttpServerOptions, MCP_TOOL_SCOPE_CATALOGUE, type McpDelegatedAccess, type McpInvocationJsonValue, type McpInvocationVerifier, type McpInvocationVerifierOptions, type McpOperationClass, type McpRequestAccess, type McpServerOptions, type McpToolScope, type McpTrustedOperationClass, type MultiSystemConfig, type RequestIdentity, type RunningHttpServer, type SafeExecutePolicy, type SapSessionContext, type ScopedAdtInvocationPolicy, type SessionRegistry, type SessionRegistryOptions, type SystemEntry, type ToolContext, type TrustedMcpInvocationClaims, assertMcpToolIsClassified, createDestinationContextRegistry, createHttpMcpHandler, createMcpInvocationVerifier, createMcpServer, createSessionRegistry, isMcpToolAllowed, loadMultiSystemConfig, operationClassForMcpTool, parseDelegatedAssistantReadPolicy, parseSafeExecutePolicy, parseScopedAdtInvocationPolicy, registerTools, resolveObjectUri, startHttpServer };
|
|
707
|
+
//# sourceMappingURL=index.d.mts.map
|