@abapify/adt-mcp 0.4.34 → 0.4.37
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 +15 -711
- package/dist/bin/adt-mcp-http.mjs +119 -119
- package/dist/bin/adt-mcp-http.mjs.map +1 -1
- package/dist/bin/adt-mcp.mjs +1 -1
- package/dist/index.d.mts +9 -9
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/{server-ClzRW10R.mjs → server-BW9yBxNy.mjs} +140 -108
- package/dist/server-BW9yBxNy.mjs.map +1 -0
- package/dist/{server-BgM8hx8V.mjs → server-Dylu87TZ.mjs} +400 -355
- package/dist/server-Dylu87TZ.mjs.map +1 -0
- package/package.json +16 -16
- package/dist/server-BgM8hx8V.mjs.map +0 -1
- package/dist/server-ClzRW10R.mjs.map +0 -1
|
@@ -17,6 +17,7 @@ import { loadConfig } from "@abapify/adt-config";
|
|
|
17
17
|
import { getFormatPlugin } from "@abapify/adt-plugin";
|
|
18
18
|
import { lstat, realpath } from "node:fs/promises";
|
|
19
19
|
import { isAbsolute, normalize, relative, resolve, sep } from "node:path";
|
|
20
|
+
import { toJsonSchemaCompat } from "@modelcontextprotocol/sdk/server/zod-json-schema-compat.js";
|
|
20
21
|
import { ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
21
22
|
|
|
22
23
|
// src/lib/tools/shared-schemas.ts
|
|
@@ -52,14 +53,13 @@ const optionalConnectionShape = {
|
|
|
52
53
|
};
|
|
53
54
|
/**
|
|
54
55
|
* Like `connectionShape`, but additionally accepts a logical `systemId`
|
|
55
|
-
* that can be resolved via the multi-system
|
|
56
|
-
* `~/.adt/sessions/<sid>.json` auth store. Intended for tools that want
|
|
56
|
+
* that can be resolved via the server's multi-system configuration. Intended for tools that want
|
|
57
57
|
* to support both explicit credentials and session-scoped resolution in
|
|
58
58
|
* a single call (e.g. `sap_connect`).
|
|
59
59
|
*/
|
|
60
60
|
const sessionOrConnectionShape = {
|
|
61
61
|
...optionalConnectionShape,
|
|
62
|
-
systemId: z.string().optional().describe("Logical system id (resolved via multi-system
|
|
62
|
+
systemId: z.string().optional().describe("Logical system id (resolved via the server multi-system configuration)")
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
// src/lib/tools/session-helpers.ts
|
|
@@ -77,11 +77,13 @@ const sessionOrConnectionShape = {
|
|
|
77
77
|
async function resolveDestinationClient(ctx, args, extra) {
|
|
78
78
|
const mcpSessionId = extra.sessionId;
|
|
79
79
|
if (!mcpSessionId || !ctx.destinationRegistry) throw new Error("A destination requires HTTP shared-service mode with an MCP session.");
|
|
80
|
-
const
|
|
80
|
+
const destinationKey = args.destination;
|
|
81
|
+
if (typeof destinationKey !== "string" || !destinationKey) throw new Error("A destination key is required.");
|
|
82
|
+
const existing = ctx.destinationRegistry.get(mcpSessionId, destinationKey);
|
|
81
83
|
return {
|
|
82
|
-
client: (await ctx.destinationRegistry.getOrCreate(mcpSessionId,
|
|
84
|
+
client: (await ctx.destinationRegistry.getOrCreate(mcpSessionId, destinationKey, ctx.requestIdentity?.(extra) ?? { principal: "unknown" })).client,
|
|
83
85
|
mcpSessionId,
|
|
84
|
-
destination:
|
|
86
|
+
destination: destinationKey,
|
|
85
87
|
alreadyConnected: existing !== void 0
|
|
86
88
|
};
|
|
87
89
|
}
|
|
@@ -139,37 +141,86 @@ async function resolveClient(ctx, args, extra) {
|
|
|
139
141
|
}
|
|
140
142
|
|
|
141
143
|
// src/lib/tools/sap-connect.ts
|
|
142
|
-
|
|
144
|
+
function resolveAdtClient(ctx, args) {
|
|
143
145
|
return resolveConnectionClient(args, {
|
|
144
146
|
createClient: (params) => ctx.getClient(params),
|
|
145
147
|
resolveSystem: ctx.resolveSystem,
|
|
146
|
-
resolveFromAuthStore:
|
|
148
|
+
resolveFromAuthStore: (systemId) => getAdtClientV2Safe({ sid: systemId })
|
|
147
149
|
});
|
|
148
150
|
}
|
|
151
|
+
/** Resolve a legacy client, then smoke-test it (discovery — GET, no side
|
|
152
|
+
* effects) so credentials are verified before registering. */
|
|
153
|
+
async function resolveVerifiedClient(ctx, args) {
|
|
154
|
+
let resolved;
|
|
155
|
+
try {
|
|
156
|
+
resolved = await resolveAdtClient(ctx, args);
|
|
157
|
+
} catch (error) {
|
|
158
|
+
return {
|
|
159
|
+
ok: false,
|
|
160
|
+
text: `${error instanceof AdtAuthError ? `sap_connect auth failure (${error.code})` : "sap_connect failed to resolve a client"}: ${error instanceof Error ? error.message : String(error)}`
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
const serverInfo = await resolved.client.adt.discovery.getDiscovery();
|
|
165
|
+
return {
|
|
166
|
+
ok: true,
|
|
167
|
+
resolved,
|
|
168
|
+
serverInfo
|
|
169
|
+
};
|
|
170
|
+
} catch (error) {
|
|
171
|
+
return {
|
|
172
|
+
ok: false,
|
|
173
|
+
text: `sap_connect verification call failed: ${error instanceof Error ? error.message : String(error)}`
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/** Result for a re-connect while this MCP session is already bound. */
|
|
178
|
+
function existingSessionResult(existing, systemId, mcpSessionId) {
|
|
179
|
+
if (systemId !== void 0 && existing.systemId !== void 0 && systemId !== existing.systemId) return {
|
|
180
|
+
isError: true,
|
|
181
|
+
content: [{
|
|
182
|
+
type: "text",
|
|
183
|
+
text: `sap_connect: this MCP session is already bound to systemId=${existing.systemId}; refusing to rebind to ${systemId}. Call sap_disconnect first, then reconnect.`
|
|
184
|
+
}]
|
|
185
|
+
};
|
|
186
|
+
return { content: [{
|
|
187
|
+
type: "text",
|
|
188
|
+
text: JSON.stringify({
|
|
189
|
+
ok: true,
|
|
190
|
+
alreadyConnected: true,
|
|
191
|
+
systemId: existing.systemId,
|
|
192
|
+
mcpSessionId
|
|
193
|
+
}, null, 2)
|
|
194
|
+
}] };
|
|
195
|
+
}
|
|
196
|
+
/** Shared ADT Server mode prewarm: resolve one destination context. */
|
|
197
|
+
async function connectDestination(ctx, sharedArgs, extra) {
|
|
198
|
+
try {
|
|
199
|
+
const destination = await resolveDestinationClient(ctx, sharedArgs, extra);
|
|
200
|
+
return { content: [{
|
|
201
|
+
type: "text",
|
|
202
|
+
text: JSON.stringify({
|
|
203
|
+
ok: true,
|
|
204
|
+
alreadyConnected: destination.alreadyConnected,
|
|
205
|
+
destination: destination.destination,
|
|
206
|
+
mcpSessionId: destination.mcpSessionId
|
|
207
|
+
}, null, 2)
|
|
208
|
+
}] };
|
|
209
|
+
} catch (error) {
|
|
210
|
+
return {
|
|
211
|
+
isError: true,
|
|
212
|
+
content: [{
|
|
213
|
+
type: "text",
|
|
214
|
+
text: `sap_connect requires HTTP shared-service mode: ${error instanceof Error ? error.message : String(error)}`
|
|
215
|
+
}]
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
149
219
|
function registerSapConnectTool(server, ctx) {
|
|
150
220
|
server.tool("sap_connect", "Open a SAP ADT session bound to the current MCP session. Subsequent tool calls on the same MCP session may omit connection args.", sessionOrConnectionShape, async (args, extra) => {
|
|
151
221
|
const mcpSessionId = extra?.sessionId;
|
|
152
222
|
const sharedArgs = args;
|
|
153
|
-
if (sharedArgs.destination !== void 0)
|
|
154
|
-
const destination = await resolveDestinationClient(ctx, sharedArgs, extra ?? {});
|
|
155
|
-
return { content: [{
|
|
156
|
-
type: "text",
|
|
157
|
-
text: JSON.stringify({
|
|
158
|
-
ok: true,
|
|
159
|
-
alreadyConnected: destination.alreadyConnected,
|
|
160
|
-
destination: destination.destination,
|
|
161
|
-
mcpSessionId: destination.mcpSessionId
|
|
162
|
-
}, null, 2)
|
|
163
|
-
}] };
|
|
164
|
-
} catch (error) {
|
|
165
|
-
return {
|
|
166
|
-
isError: true,
|
|
167
|
-
content: [{
|
|
168
|
-
type: "text",
|
|
169
|
-
text: `sap_connect requires HTTP shared-service mode: ${error instanceof Error ? error.message : String(error)}`
|
|
170
|
-
}]
|
|
171
|
-
};
|
|
172
|
-
}
|
|
223
|
+
if (sharedArgs.destination !== void 0) return connectDestination(ctx, sharedArgs, extra ?? {});
|
|
173
224
|
if (args.baseUrl && args.systemId) return {
|
|
174
225
|
isError: true,
|
|
175
226
|
content: [{
|
|
@@ -192,48 +243,16 @@ function registerSapConnectTool(server, ctx) {
|
|
|
192
243
|
}]
|
|
193
244
|
};
|
|
194
245
|
const existing = ctx.registry.get(mcpSessionId);
|
|
195
|
-
if (existing)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
text: `sap_connect: this MCP session is already bound to systemId=${existing.systemId}; refusing to rebind to ${args.systemId}. Call sap_disconnect first, then reconnect.`
|
|
201
|
-
}]
|
|
202
|
-
};
|
|
203
|
-
return { content: [{
|
|
246
|
+
if (existing) return existingSessionResult(existing, args.systemId, mcpSessionId);
|
|
247
|
+
const verification = await resolveVerifiedClient(ctx, args);
|
|
248
|
+
if (!verification.ok) return {
|
|
249
|
+
isError: true,
|
|
250
|
+
content: [{
|
|
204
251
|
type: "text",
|
|
205
|
-
text:
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
mcpSessionId
|
|
210
|
-
}, null, 2)
|
|
211
|
-
}] };
|
|
212
|
-
}
|
|
213
|
-
let resolved;
|
|
214
|
-
try {
|
|
215
|
-
resolved = await resolveAdtClient(ctx, args);
|
|
216
|
-
} catch (error) {
|
|
217
|
-
return {
|
|
218
|
-
isError: true,
|
|
219
|
-
content: [{
|
|
220
|
-
type: "text",
|
|
221
|
-
text: `${error instanceof AdtAuthError ? `sap_connect auth failure (${error.code})` : "sap_connect failed to resolve a client"}: ${error instanceof Error ? error.message : String(error)}`
|
|
222
|
-
}]
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
let serverInfo;
|
|
226
|
-
try {
|
|
227
|
-
serverInfo = await resolved.client.adt.discovery.getDiscovery();
|
|
228
|
-
} catch (error) {
|
|
229
|
-
return {
|
|
230
|
-
isError: true,
|
|
231
|
-
content: [{
|
|
232
|
-
type: "text",
|
|
233
|
-
text: `sap_connect verification call failed: ${error instanceof Error ? error.message : String(error)}`
|
|
234
|
-
}]
|
|
235
|
-
};
|
|
236
|
-
}
|
|
252
|
+
text: verification.text
|
|
253
|
+
}]
|
|
254
|
+
};
|
|
255
|
+
const { resolved, serverInfo } = verification;
|
|
237
256
|
const sessionRef = {};
|
|
238
257
|
sessionRef.value = ctx.registry.create(mcpSessionId, {
|
|
239
258
|
systemId: resolved.systemId,
|
|
@@ -242,7 +261,7 @@ function registerSapConnectTool(server, ctx) {
|
|
|
242
261
|
}, async () => {
|
|
243
262
|
const session = sessionRef.value;
|
|
244
263
|
const cs = session?.changeset;
|
|
245
|
-
if (cs
|
|
264
|
+
if (cs?.status === "open" && session) try {
|
|
246
265
|
await new ChangesetService(session.client).rollback(cs);
|
|
247
266
|
} catch {}
|
|
248
267
|
});
|
|
@@ -351,7 +370,7 @@ function requireOpenChangeset(ctx, extra, toolName) {
|
|
|
351
370
|
const sess = requireSession(ctx, extra, toolName);
|
|
352
371
|
if (!sess.ok) return sess;
|
|
353
372
|
const cs = sess.value.changeset;
|
|
354
|
-
if (
|
|
373
|
+
if (cs?.status !== "open") return {
|
|
355
374
|
ok: false,
|
|
356
375
|
error: textError(`No open changeset for ${toolName}.`)
|
|
357
376
|
};
|
|
@@ -386,7 +405,7 @@ function registerChangesetBeginTool(server, ctx) {
|
|
|
386
405
|
const guard = requireSession(ctx, extra, "changeset_begin");
|
|
387
406
|
if (!guard.ok) return guard.error;
|
|
388
407
|
const session = guard.value;
|
|
389
|
-
if (session.changeset
|
|
408
|
+
if (session.changeset?.status === "open") {
|
|
390
409
|
if (!args.force) return textError(`A changeset is already open (id=${session.changeset.id}). Call changeset_commit/rollback, or pass force=true to auto-rollback.`);
|
|
391
410
|
try {
|
|
392
411
|
const prior = session.changeset;
|
|
@@ -503,11 +522,13 @@ function isKnownAdtHttpFailure(error) {
|
|
|
503
522
|
* Build a standard MCP error result with BTP 404 awareness.
|
|
504
523
|
*/
|
|
505
524
|
function mcpErrorResult(error, toolLabel, notFoundHint) {
|
|
525
|
+
const status = getErrorStatus(error);
|
|
526
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
506
527
|
return {
|
|
507
528
|
isError: true,
|
|
508
529
|
content: [{
|
|
509
530
|
type: "text",
|
|
510
|
-
text:
|
|
531
|
+
text: status === 404 && notFoundHint ? notFoundHint : `${toolLabel} failed: ${errorMessage}`
|
|
511
532
|
}]
|
|
512
533
|
};
|
|
513
534
|
}
|
|
@@ -703,8 +724,9 @@ function registerDiscoveryTool(server, ctx) {
|
|
|
703
724
|
const { client } = await resolveClient(ctx, args, extra ?? {});
|
|
704
725
|
const discovery = await client.adt.discovery.getDiscovery();
|
|
705
726
|
const workspaces = extractDiscoveryWorkspaces(discovery);
|
|
706
|
-
|
|
707
|
-
|
|
727
|
+
const filter = args.filter;
|
|
728
|
+
if (filter) {
|
|
729
|
+
const filtered = workspaces.filter((workspace) => String(workspace.title ?? "").toLowerCase().includes(filter.toLowerCase()));
|
|
708
730
|
return { content: [{
|
|
709
731
|
type: "text",
|
|
710
732
|
text: JSON.stringify(filtered, null, 2)
|
|
@@ -1419,7 +1441,7 @@ function registerGetFrozenSourceTool(server, ctx) {
|
|
|
1419
1441
|
const frozenSource = (ctx.requestAccess?.(extra ?? {}))?.frozenSource;
|
|
1420
1442
|
const destination = args.destination;
|
|
1421
1443
|
const source = frozenSource?.sources.find((candidate) => candidate.canonicalKey === args.canonicalKey && candidate.componentId === args.componentId);
|
|
1422
|
-
if (!source || !ctx.resolveFrozenSource || typeof destination !== "string") return scopeDeniedResult();
|
|
1444
|
+
if (!frozenSource || !source || !ctx.resolveFrozenSource || typeof destination !== "string") return scopeDeniedResult();
|
|
1423
1445
|
try {
|
|
1424
1446
|
const resolved = await ctx.resolveFrozenSource({
|
|
1425
1447
|
destination,
|
|
@@ -1427,7 +1449,7 @@ function registerGetFrozenSourceTool(server, ctx) {
|
|
|
1427
1449
|
sourceRef: source.sourceRef
|
|
1428
1450
|
});
|
|
1429
1451
|
if (typeof resolved?.sourceUri !== "string" || !resolved.sourceUri.startsWith("/sap/bc/adt/") || /[\s\\\u0000-\u0008\u000e-\u001f\u007f]/u.test(resolved.sourceUri)) return scopeDeniedResult();
|
|
1430
|
-
const { client } = await resolveClient(ctx,
|
|
1452
|
+
const { client } = await resolveClient(ctx, { destination }, extra ?? {});
|
|
1431
1453
|
let text;
|
|
1432
1454
|
try {
|
|
1433
1455
|
text = await client.readTextBounded(resolved.sourceUri, frozenSource.maxSourceBytes, { headers: { Accept: "text/plain" } });
|
|
@@ -1472,6 +1494,32 @@ function registerGetFrozenSourceTool(server, ctx) {
|
|
|
1472
1494
|
* Acquires a lock, PUTs the new source, then releases the lock.
|
|
1473
1495
|
* Uses the adt-locks LockService – no reimplementation of lock protocol.
|
|
1474
1496
|
*/
|
|
1497
|
+
async function writeSourceLocked(client, lockService, objectUri, objectName, transport, sourceToWrite) {
|
|
1498
|
+
let lockHandle;
|
|
1499
|
+
try {
|
|
1500
|
+
const lock = await lockService.lock(objectUri, {
|
|
1501
|
+
transport,
|
|
1502
|
+
objectName
|
|
1503
|
+
});
|
|
1504
|
+
lockHandle = lock.handle;
|
|
1505
|
+
const effectiveTransport = resolveLockCorrelation(lock, transport);
|
|
1506
|
+
const params = new URLSearchParams();
|
|
1507
|
+
params.set("lockHandle", lockHandle);
|
|
1508
|
+
if (effectiveTransport) params.set("corrNr", effectiveTransport);
|
|
1509
|
+
await client.fetch(`${objectUri}/source/main?${params.toString()}`, {
|
|
1510
|
+
method: "PUT",
|
|
1511
|
+
headers: { "Content-Type": "text/plain" },
|
|
1512
|
+
body: sourceToWrite
|
|
1513
|
+
});
|
|
1514
|
+
await lockService.unlock(objectUri, { lockHandle });
|
|
1515
|
+
lockHandle = void 0;
|
|
1516
|
+
} catch (error) {
|
|
1517
|
+
if (lockHandle) try {
|
|
1518
|
+
await lockService.unlock(objectUri, { lockHandle });
|
|
1519
|
+
} catch {}
|
|
1520
|
+
throw error;
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1475
1523
|
function registerUpdateSourceTool(server, ctx) {
|
|
1476
1524
|
server.tool("update_source", "Write new ABAP source code to an existing object (acquires lock, PUTs source, releases lock)", {
|
|
1477
1525
|
...sessionOrConnectionShape,
|
|
@@ -1488,25 +1536,13 @@ function registerUpdateSourceTool(server, ctx) {
|
|
|
1488
1536
|
try {
|
|
1489
1537
|
({client} = await resolveClient(ctx, args, extra ?? {}));
|
|
1490
1538
|
} catch (error) {
|
|
1491
|
-
return
|
|
1492
|
-
isError: true,
|
|
1493
|
-
content: [{
|
|
1494
|
-
type: "text",
|
|
1495
|
-
text: `Update source failed: ${error instanceof Error ? error.message : String(error)}`
|
|
1496
|
-
}]
|
|
1497
|
-
};
|
|
1539
|
+
return mcpErrorResult(error, "Update source");
|
|
1498
1540
|
}
|
|
1499
1541
|
let objectUri;
|
|
1500
1542
|
try {
|
|
1501
1543
|
objectUri = await resolveObjectUri(client, args.objectName, args.objectType);
|
|
1502
1544
|
} catch (error) {
|
|
1503
|
-
return
|
|
1504
|
-
isError: true,
|
|
1505
|
-
content: [{
|
|
1506
|
-
type: "text",
|
|
1507
|
-
text: `Search failed: ${error instanceof Error ? error.message : String(error)}`
|
|
1508
|
-
}]
|
|
1509
|
-
};
|
|
1545
|
+
return mcpErrorResult(error, "Search");
|
|
1510
1546
|
}
|
|
1511
1547
|
if (!objectUri) return {
|
|
1512
1548
|
isError: true,
|
|
@@ -1515,103 +1551,74 @@ function registerUpdateSourceTool(server, ctx) {
|
|
|
1515
1551
|
text: `Object '${args.objectName}' not found`
|
|
1516
1552
|
}]
|
|
1517
1553
|
};
|
|
1518
|
-
const
|
|
1519
|
-
|
|
1520
|
-
|
|
1554
|
+
const applyMethodEdit = async (uri) => {
|
|
1555
|
+
if (!args.methodName) return { errorText: "methodName is required when action=editMethod" };
|
|
1556
|
+
if (!uri.includes("/oo/classes/") && !uri.includes("/oo/interfaces/")) return { errorText: `editMethod is only supported for classes and interfaces, but '${args.objectName}' resolved to ${uri}` };
|
|
1557
|
+
const currentSource = String(await client.fetch(`${uri}/source/main`, {
|
|
1558
|
+
method: "GET",
|
|
1559
|
+
headers: { Accept: "text/plain" }
|
|
1560
|
+
}));
|
|
1561
|
+
const boundary = detectMethodBoundary(currentSource, args.methodName);
|
|
1562
|
+
if (!boundary) return { errorText: `Method ${args.methodName} not found in ${args.objectName}` };
|
|
1563
|
+
const lines = currentSource.split(/\r?\n/);
|
|
1564
|
+
const methodBody = normalizeMethodBody(args.sourceCode, args.methodName);
|
|
1565
|
+
const methodBlock = [
|
|
1566
|
+
`METHOD ${args.methodName.toUpperCase()}.`,
|
|
1567
|
+
methodBody,
|
|
1568
|
+
"ENDMETHOD."
|
|
1569
|
+
].join("\n");
|
|
1570
|
+
lines.splice(boundary.startLine - 1, boundary.endLine - boundary.startLine + 1, methodBlock);
|
|
1571
|
+
return { sourceToWrite: lines.join("\n") };
|
|
1572
|
+
};
|
|
1573
|
+
const lintGateError = (sourceToWrite) => {
|
|
1574
|
+
const blocking = lintSource(sourceToWrite, {
|
|
1575
|
+
filename: `${args.objectName.toLowerCase()}.abap`,
|
|
1576
|
+
systemType: args.lintPreset
|
|
1577
|
+
}).filter((d) => [
|
|
1578
|
+
"parser_error",
|
|
1579
|
+
"cloud_types",
|
|
1580
|
+
"strict_sql"
|
|
1581
|
+
].includes(d.key));
|
|
1582
|
+
if (blocking.length > 0) return JSON.stringify({
|
|
1583
|
+
status: "blocked_by_lint",
|
|
1584
|
+
diagnostics: blocking
|
|
1585
|
+
}, null, 2);
|
|
1586
|
+
};
|
|
1587
|
+
const prepareSourceToWrite = async (uri) => {
|
|
1521
1588
|
let sourceToWrite = args.sourceCode;
|
|
1522
1589
|
if (args.action === "editMethod") {
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
type: "text",
|
|
1527
|
-
text: "methodName is required when action=editMethod"
|
|
1528
|
-
}]
|
|
1529
|
-
};
|
|
1530
|
-
if (!objectUri.includes("/oo/classes/") && !objectUri.includes("/oo/interfaces/")) return {
|
|
1531
|
-
isError: true,
|
|
1532
|
-
content: [{
|
|
1533
|
-
type: "text",
|
|
1534
|
-
text: `editMethod is only supported for classes and interfaces, but '${args.objectName}' resolved to ${objectUri}`
|
|
1535
|
-
}]
|
|
1536
|
-
};
|
|
1537
|
-
const currentSource = String(await client.fetch(`${objectUri}/source/main`, {
|
|
1538
|
-
method: "GET",
|
|
1539
|
-
headers: { Accept: "text/plain" }
|
|
1540
|
-
}));
|
|
1541
|
-
const boundary = detectMethodBoundary(currentSource, args.methodName);
|
|
1542
|
-
if (!boundary) return {
|
|
1543
|
-
isError: true,
|
|
1544
|
-
content: [{
|
|
1545
|
-
type: "text",
|
|
1546
|
-
text: `Method ${args.methodName} not found in ${args.objectName}`
|
|
1547
|
-
}]
|
|
1548
|
-
};
|
|
1549
|
-
const lines = currentSource.split(/\r?\n/);
|
|
1550
|
-
const methodBody = normalizeMethodBody(args.sourceCode, args.methodName);
|
|
1551
|
-
const methodBlock = [
|
|
1552
|
-
`METHOD ${args.methodName.toUpperCase()}.`,
|
|
1553
|
-
methodBody,
|
|
1554
|
-
"ENDMETHOD."
|
|
1555
|
-
].join("\n");
|
|
1556
|
-
lines.splice(boundary.startLine - 1, boundary.endLine - boundary.startLine + 1, methodBlock);
|
|
1557
|
-
sourceToWrite = lines.join("\n");
|
|
1590
|
+
const edited = await applyMethodEdit(uri);
|
|
1591
|
+
if ("errorText" in edited) return edited;
|
|
1592
|
+
sourceToWrite = edited.sourceToWrite;
|
|
1558
1593
|
}
|
|
1559
1594
|
if (args.lintBeforeWrite) {
|
|
1560
|
-
const
|
|
1561
|
-
|
|
1562
|
-
systemType: args.lintPreset
|
|
1563
|
-
}).filter((d) => [
|
|
1564
|
-
"parser_error",
|
|
1565
|
-
"cloud_types",
|
|
1566
|
-
"strict_sql"
|
|
1567
|
-
].includes(d.key));
|
|
1568
|
-
if (blocking.length > 0) return {
|
|
1569
|
-
isError: true,
|
|
1570
|
-
content: [{
|
|
1571
|
-
type: "text",
|
|
1572
|
-
text: JSON.stringify({
|
|
1573
|
-
status: "blocked_by_lint",
|
|
1574
|
-
diagnostics: blocking
|
|
1575
|
-
}, null, 2)
|
|
1576
|
-
}]
|
|
1577
|
-
};
|
|
1595
|
+
const lintError = lintGateError(sourceToWrite);
|
|
1596
|
+
if (lintError !== void 0) return { errorText: lintError };
|
|
1578
1597
|
}
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
const params = new URLSearchParams();
|
|
1586
|
-
params.set("lockHandle", lockHandle);
|
|
1587
|
-
if (effectiveTransport) params.set("corrNr", effectiveTransport);
|
|
1588
|
-
await client.fetch(`${objectUri}/source/main?${params.toString()}`, {
|
|
1589
|
-
method: "PUT",
|
|
1590
|
-
headers: { "Content-Type": "text/plain" },
|
|
1591
|
-
body: sourceToWrite
|
|
1592
|
-
});
|
|
1593
|
-
await lockService.unlock(objectUri, { lockHandle });
|
|
1594
|
-
lockHandle = void 0;
|
|
1595
|
-
return { content: [{
|
|
1596
|
-
type: "text",
|
|
1597
|
-
text: JSON.stringify({
|
|
1598
|
-
status: "updated",
|
|
1599
|
-
object: args.objectName,
|
|
1600
|
-
action: args.action ?? "update"
|
|
1601
|
-
}, null, 2)
|
|
1602
|
-
}] };
|
|
1603
|
-
} catch (error) {
|
|
1604
|
-
if (lockHandle) try {
|
|
1605
|
-
await lockService.unlock(objectUri, { lockHandle });
|
|
1606
|
-
} catch {}
|
|
1607
|
-
return {
|
|
1598
|
+
return { sourceToWrite };
|
|
1599
|
+
};
|
|
1600
|
+
const lockService = createLockService(client);
|
|
1601
|
+
try {
|
|
1602
|
+
const prepared = await prepareSourceToWrite(objectUri);
|
|
1603
|
+
if ("errorText" in prepared) return {
|
|
1608
1604
|
isError: true,
|
|
1609
1605
|
content: [{
|
|
1610
1606
|
type: "text",
|
|
1611
|
-
text:
|
|
1607
|
+
text: prepared.errorText
|
|
1612
1608
|
}]
|
|
1613
1609
|
};
|
|
1610
|
+
await writeSourceLocked(client, lockService, objectUri, args.objectName, args.transport, prepared.sourceToWrite);
|
|
1611
|
+
} catch (error) {
|
|
1612
|
+
return mcpErrorResult(error, "Update source");
|
|
1614
1613
|
}
|
|
1614
|
+
return { content: [{
|
|
1615
|
+
type: "text",
|
|
1616
|
+
text: JSON.stringify({
|
|
1617
|
+
status: "updated",
|
|
1618
|
+
object: args.objectName,
|
|
1619
|
+
action: args.action ?? "update"
|
|
1620
|
+
}, null, 2)
|
|
1621
|
+
}] };
|
|
1615
1622
|
});
|
|
1616
1623
|
}
|
|
1617
1624
|
|
|
@@ -1627,8 +1634,8 @@ function registerLintAbapTool(server, _ctx) {
|
|
|
1627
1634
|
source: z.string().optional().describe("ABAP source code to lint"),
|
|
1628
1635
|
objectName: z.string().optional().describe("Optional object name used for issue filename context"),
|
|
1629
1636
|
lintPreset: z.enum(["btp", "onpremise"]).optional().describe("Lint preset to apply (defaults to onpremise)"),
|
|
1630
|
-
ruleOverrides: z.record(z.unknown()).optional().describe("Optional per-rule override config passed to abaplint")
|
|
1631
|
-
},
|
|
1637
|
+
ruleOverrides: z.record(z.string(), z.unknown()).optional().describe("Optional per-rule override config passed to abaplint")
|
|
1638
|
+
}, (args) => {
|
|
1632
1639
|
try {
|
|
1633
1640
|
const options = {
|
|
1634
1641
|
filename: args.objectName ? `${args.objectName.toLowerCase()}.abap` : void 0,
|
|
@@ -1694,10 +1701,11 @@ function registerActivateObjectTool(server, ctx) {
|
|
|
1694
1701
|
try {
|
|
1695
1702
|
const { client } = await resolveClient(ctx, args, extra ?? {});
|
|
1696
1703
|
const toActivate = [];
|
|
1697
|
-
const
|
|
1704
|
+
const fallbackObjects = args.objectName && args.objectType ? [{
|
|
1698
1705
|
objectName: args.objectName,
|
|
1699
1706
|
objectType: args.objectType
|
|
1700
1707
|
}] : [];
|
|
1708
|
+
const rawObjects = args.objects && args.objects.length > 0 ? args.objects : fallbackObjects;
|
|
1701
1709
|
if (rawObjects.length === 0) return {
|
|
1702
1710
|
isError: true,
|
|
1703
1711
|
content: [{
|
|
@@ -1763,6 +1771,41 @@ function registerActivateObjectTool(server, ctx) {
|
|
|
1763
1771
|
* adt-contracts) for both request serialisation and response parsing – no
|
|
1764
1772
|
* manual XML building and no third-party XML parser.
|
|
1765
1773
|
*/
|
|
1774
|
+
function scanReportMessages(report) {
|
|
1775
|
+
let hasErrors = false;
|
|
1776
|
+
let hasWarnings = false;
|
|
1777
|
+
const msgs = report.checkMessageList?.checkMessage ?? [];
|
|
1778
|
+
const arr = Array.isArray(msgs) ? msgs : [msgs];
|
|
1779
|
+
for (const msg of arr) {
|
|
1780
|
+
const sev = msg.type ?? msg.category;
|
|
1781
|
+
if (sev === "E" || sev === "A") hasErrors = true;
|
|
1782
|
+
if (sev === "W") hasWarnings = true;
|
|
1783
|
+
}
|
|
1784
|
+
return {
|
|
1785
|
+
hasErrors,
|
|
1786
|
+
hasWarnings
|
|
1787
|
+
};
|
|
1788
|
+
}
|
|
1789
|
+
/** Parse the discriminated union: response is checkRunReports */
|
|
1790
|
+
function summarizeCheckResponse(response) {
|
|
1791
|
+
const reports = [];
|
|
1792
|
+
let hasErrors = false;
|
|
1793
|
+
let hasWarnings = false;
|
|
1794
|
+
if ("checkRunReports" in response) {
|
|
1795
|
+
const raw = response.checkRunReports.checkReport ?? [];
|
|
1796
|
+
reports.push(...raw);
|
|
1797
|
+
for (const report of raw) {
|
|
1798
|
+
const flags = scanReportMessages(report);
|
|
1799
|
+
hasErrors ||= flags.hasErrors;
|
|
1800
|
+
hasWarnings ||= flags.hasWarnings;
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
return {
|
|
1804
|
+
reports,
|
|
1805
|
+
hasErrors,
|
|
1806
|
+
hasWarnings
|
|
1807
|
+
};
|
|
1808
|
+
}
|
|
1766
1809
|
function registerCheckSyntaxTool(server, ctx) {
|
|
1767
1810
|
server.tool("check_syntax", "Run ABAP syntax check (checkruns) on an object and return structured messages", {
|
|
1768
1811
|
...sessionOrConnectionShape,
|
|
@@ -1788,23 +1831,7 @@ function registerCheckSyntaxTool(server, ctx) {
|
|
|
1788
1831
|
uri: objectUri,
|
|
1789
1832
|
version: args.version ?? "active"
|
|
1790
1833
|
}] } };
|
|
1791
|
-
const
|
|
1792
|
-
const reports = [];
|
|
1793
|
-
let hasErrors = false;
|
|
1794
|
-
let hasWarnings = false;
|
|
1795
|
-
if ("checkRunReports" in response) {
|
|
1796
|
-
const raw = response.checkRunReports.checkReport ?? [];
|
|
1797
|
-
reports.push(...raw);
|
|
1798
|
-
for (const report of raw) {
|
|
1799
|
-
const msgs = report.checkMessageList?.checkMessage ?? [];
|
|
1800
|
-
const arr = Array.isArray(msgs) ? msgs : [msgs];
|
|
1801
|
-
for (const msg of arr) {
|
|
1802
|
-
const sev = msg.type ?? msg.category;
|
|
1803
|
-
if (sev === "E" || sev === "A") hasErrors = true;
|
|
1804
|
-
if (sev === "W") hasWarnings = true;
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1834
|
+
const { reports, hasErrors, hasWarnings } = summarizeCheckResponse(await client.adt.checkruns.checkObjects.post(body));
|
|
1808
1835
|
return { content: [{
|
|
1809
1836
|
type: "text",
|
|
1810
1837
|
text: JSON.stringify({
|
|
@@ -2033,7 +2060,7 @@ function isScopedReadResourceAllowed(scoped, name, arguments_) {
|
|
|
2033
2060
|
return Boolean(key && scoped.resourceKeys.includes(key));
|
|
2034
2061
|
}
|
|
2035
2062
|
function validateAtcScope(policy, scope) {
|
|
2036
|
-
if (
|
|
2063
|
+
if (policy?.operationId !== "atc_run" || policy.check !== "atc" || !scope || typeof scope !== "object" || Array.isArray(scope)) return;
|
|
2037
2064
|
const scopeRecord = scope;
|
|
2038
2065
|
if (policy.maxVariants < 1) return void 0;
|
|
2039
2066
|
if (scopeRecord.kind === "package") return;
|
|
@@ -2046,6 +2073,7 @@ function validateAtcScope(policy, scope) {
|
|
|
2046
2073
|
};
|
|
2047
2074
|
}
|
|
2048
2075
|
function collectAtcObjectKeys(objects) {
|
|
2076
|
+
if (!Array.isArray(objects)) return void 0;
|
|
2049
2077
|
const keys = [];
|
|
2050
2078
|
let packageCount = 0;
|
|
2051
2079
|
for (const object of objects) {
|
|
@@ -2073,7 +2101,7 @@ function isScopedUnitTestResourceAllowed(scoped, arguments_) {
|
|
|
2073
2101
|
const policy = scoped.safeExecutePolicy;
|
|
2074
2102
|
const key = canonicalObjectKey(arguments_.objectType, arguments_.objectName);
|
|
2075
2103
|
const normalized = normalizeUnitTestOptions(arguments_);
|
|
2076
|
-
if (
|
|
2104
|
+
if (policy?.operationId !== "run_unit_tests" || !key || !normalized || policy.maxObjects < 1 || !exactStringArrays(scoped.resourceKeys, [key])) return false;
|
|
2077
2105
|
return policy.check === "aunit" ? normalized.effectiveWithCoverage === false && normalized.effectiveCoverageFormat === null && policy.effectiveWithCoverage === false && policy.effectiveCoverageFormat === null : normalized.effectiveWithCoverage === true && normalized.effectiveCoverageFormat === policy.effectiveCoverageFormat && policy.effectiveWithCoverage === true;
|
|
2078
2106
|
}
|
|
2079
2107
|
/**
|
|
@@ -2109,18 +2137,23 @@ function isMcpDestinationAllowed(access, destination) {
|
|
|
2109
2137
|
*/
|
|
2110
2138
|
function isMcpToolListed(access, name) {
|
|
2111
2139
|
const entry = MCP_TOOL_SCOPE_CATALOGUE[name];
|
|
2112
|
-
if (!entry || !
|
|
2140
|
+
if (!entry || !isUsableAccess(access)) return false;
|
|
2113
2141
|
if (access.frozenSource) return name === "get_frozen_source";
|
|
2114
|
-
if (access.scoped)
|
|
2115
|
-
const operationClass = "actionClasses" in entry ? void 0 : entry.operationClass;
|
|
2116
|
-
if (operationClass !== access.scoped.operationClass && !((name === "atc_run" || name === "run_unit_tests") && access.scoped.operationClass === "safe_execute" && access.classes.includes("safe_execute"))) return false;
|
|
2117
|
-
if (!access.scoped.toolNames.includes(name)) return false;
|
|
2118
|
-
if (operationClass === "read" && access.scoped.resourceKeys.length === 0) return false;
|
|
2119
|
-
return true;
|
|
2120
|
-
}
|
|
2142
|
+
if (access.scoped) return isScopedToolListed(entry, name, access.scoped, access.classes);
|
|
2121
2143
|
if (name === "get_frozen_source") return false;
|
|
2122
2144
|
return ("actionClasses" in entry ? Object.values(entry.actionClasses) : [entry.operationClass]).some((operationClass) => access.classes.includes(operationClass));
|
|
2123
2145
|
}
|
|
2146
|
+
/** Structural sanity check before the access record may drive listing. */
|
|
2147
|
+
function isUsableAccess(access) {
|
|
2148
|
+
return !!access && Array.isArray(access.classes) && access.classes.every(isMcpOperationClass) && Array.isArray(access.destinationKeys) && access.destinationKeys.length > 0 && access.destinationKeys.every(isMcpDestinationKey);
|
|
2149
|
+
}
|
|
2150
|
+
function isScopedToolListed(entry, name, scoped, classes) {
|
|
2151
|
+
const operationClass = "actionClasses" in entry ? void 0 : entry.operationClass;
|
|
2152
|
+
if (operationClass !== scoped.operationClass && !((name === "atc_run" || name === "run_unit_tests") && scoped.operationClass === "safe_execute" && classes.includes("safe_execute"))) return false;
|
|
2153
|
+
if (!scoped.toolNames.includes(name)) return false;
|
|
2154
|
+
if (operationClass === "read" && scoped.resourceKeys.length === 0) return false;
|
|
2155
|
+
return true;
|
|
2156
|
+
}
|
|
2124
2157
|
|
|
2125
2158
|
// src/lib/tools/run-unit-tests.ts
|
|
2126
2159
|
/**
|
|
@@ -2161,36 +2194,39 @@ function buildRunConfiguration(targetUris, withCoverage = false) {
|
|
|
2161
2194
|
}] }
|
|
2162
2195
|
} };
|
|
2163
2196
|
}
|
|
2197
|
+
function toArray(value) {
|
|
2198
|
+
return Array.isArray(value) ? [...value] : [value];
|
|
2199
|
+
}
|
|
2200
|
+
function tallyMethod(tm, tally) {
|
|
2201
|
+
tally.totalTests++;
|
|
2202
|
+
const alertArr = toArray(tm?.alerts?.alert ?? []);
|
|
2203
|
+
if (alertArr.length === 0) {
|
|
2204
|
+
tally.passCount++;
|
|
2205
|
+
return;
|
|
2206
|
+
}
|
|
2207
|
+
const hasFail = alertArr.some((a) => a?.kind === "failedAssertion" || a?.severity === "critical");
|
|
2208
|
+
if (alertArr.some((a) => a?.kind === "error" || a?.severity === "fatal")) tally.errorCount++;
|
|
2209
|
+
else if (hasFail) tally.failCount++;
|
|
2210
|
+
else tally.passCount++;
|
|
2211
|
+
}
|
|
2164
2212
|
/** Normalize AUnit response into a simple summary using proper schema types */
|
|
2165
2213
|
function normalizeResult(response) {
|
|
2166
2214
|
const programs = response.runResult.program ?? [];
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2215
|
+
const tally = {
|
|
2216
|
+
totalTests: 0,
|
|
2217
|
+
passCount: 0,
|
|
2218
|
+
failCount: 0,
|
|
2219
|
+
errorCount: 0
|
|
2220
|
+
};
|
|
2171
2221
|
for (const prog of programs) {
|
|
2172
2222
|
const testClasses = prog.testClasses?.testClass ?? [];
|
|
2173
|
-
for (const tc of
|
|
2223
|
+
for (const tc of toArray(testClasses)) {
|
|
2174
2224
|
const methods = tc?.testMethods?.testMethod ?? [];
|
|
2175
|
-
for (const tm of
|
|
2176
|
-
totalTests++;
|
|
2177
|
-
const alerts = tm?.alerts?.alert ?? [];
|
|
2178
|
-
const alertArr = Array.isArray(alerts) ? alerts : [alerts];
|
|
2179
|
-
if (alertArr.length === 0) passCount++;
|
|
2180
|
-
else {
|
|
2181
|
-
const hasFail = alertArr.some((a) => a?.kind === "failedAssertion" || a?.severity === "critical");
|
|
2182
|
-
if (alertArr.some((a) => a?.kind === "error" || a?.severity === "fatal")) errorCount++;
|
|
2183
|
-
else if (hasFail) failCount++;
|
|
2184
|
-
else passCount++;
|
|
2185
|
-
}
|
|
2186
|
-
}
|
|
2225
|
+
for (const tm of toArray(methods)) tallyMethod(tm, tally);
|
|
2187
2226
|
}
|
|
2188
2227
|
}
|
|
2189
2228
|
return {
|
|
2190
|
-
|
|
2191
|
-
passCount,
|
|
2192
|
-
failCount,
|
|
2193
|
-
errorCount,
|
|
2229
|
+
...tally,
|
|
2194
2230
|
programs
|
|
2195
2231
|
};
|
|
2196
2232
|
}
|
|
@@ -2227,7 +2263,8 @@ function coverageMeasurementCount(value) {
|
|
|
2227
2263
|
const nodes = value.nodes;
|
|
2228
2264
|
if (!nodes || typeof nodes !== "object" || Array.isArray(nodes)) return 0;
|
|
2229
2265
|
const rawChildren = nodes.node;
|
|
2230
|
-
|
|
2266
|
+
const singleChild = rawChildren ? [rawChildren] : [];
|
|
2267
|
+
return (Array.isArray(rawChildren) ? rawChildren : singleChild).reduce((total, child) => total + 1 + coverageMeasurementCount(child), 0);
|
|
2231
2268
|
}
|
|
2232
2269
|
function checkSafeExecuteLimits(counts, safePolicy) {
|
|
2233
2270
|
if (!safePolicy) return void 0;
|
|
@@ -2450,7 +2487,7 @@ function registerGrepObjectsTool(server, ctx) {
|
|
|
2450
2487
|
objects: z.array(z.object({
|
|
2451
2488
|
objectName: z.string().describe("ABAP object name"),
|
|
2452
2489
|
objectType: z.string().describe("Object type (e.g. CLAS, PROG)")
|
|
2453
|
-
})).
|
|
2490
|
+
})).min(1, "Provide at least one object").describe("Objects to search within (resolved to URIs automatically)"),
|
|
2454
2491
|
maxResults: z.number().optional().describe("Maximum number of results (default: 50)")
|
|
2455
2492
|
}, async (args, extra) => {
|
|
2456
2493
|
try {
|
|
@@ -2977,22 +3014,9 @@ const CREATE_OBJECT_TYPES = [
|
|
|
2977
3014
|
"SRVD",
|
|
2978
3015
|
"SRVB"
|
|
2979
3016
|
];
|
|
2980
|
-
const SOURCE_BACKED_OBJECT_TYPES = [
|
|
2981
|
-
"PROG",
|
|
2982
|
-
"INCL",
|
|
2983
|
-
"CLAS",
|
|
2984
|
-
"INTF",
|
|
2985
|
-
"DDLS",
|
|
2986
|
-
"DCLS",
|
|
2987
|
-
"BDEF",
|
|
2988
|
-
"SRVD"
|
|
2989
|
-
];
|
|
2990
3017
|
function isCreateObjectType(type) {
|
|
2991
3018
|
return CREATE_OBJECT_TYPES.includes(type.toUpperCase());
|
|
2992
3019
|
}
|
|
2993
|
-
function isSourceBackedObjectType(type) {
|
|
2994
|
-
return SOURCE_BACKED_OBJECT_TYPES.includes(type.toUpperCase());
|
|
2995
|
-
}
|
|
2996
3020
|
/**
|
|
2997
3021
|
* Wire ADK's global context to the current client so that any helper using
|
|
2998
3022
|
* @abapify/adk (e.g. lock/unlock, transport operations) picks up the
|
|
@@ -3780,6 +3804,50 @@ function registerPrettyPrintTool(server, ctx) {
|
|
|
3780
3804
|
}
|
|
3781
3805
|
|
|
3782
3806
|
// src/lib/tools/get-context.ts
|
|
3807
|
+
async function collectDependencyContext(client, rootSource, depth, maxDeps) {
|
|
3808
|
+
const queue = extractDependencies(rootSource).map((name) => ({
|
|
3809
|
+
name,
|
|
3810
|
+
level: 1
|
|
3811
|
+
}));
|
|
3812
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3813
|
+
const dependencies = [];
|
|
3814
|
+
while (queue.length > 0 && dependencies.length < maxDeps) {
|
|
3815
|
+
const current = queue.shift();
|
|
3816
|
+
if (!current) break;
|
|
3817
|
+
if (seen.has(current.name)) continue;
|
|
3818
|
+
seen.add(current.name);
|
|
3819
|
+
const searchResult = await client.adt.repository.informationsystem.search.quickSearch({
|
|
3820
|
+
query: current.name,
|
|
3821
|
+
maxResults: 10
|
|
3822
|
+
});
|
|
3823
|
+
const upperName = current.name.toUpperCase();
|
|
3824
|
+
const object = extractObjectReferences(searchResult).find((candidate) => String(candidate.name ?? "").toUpperCase() === upperName);
|
|
3825
|
+
const depUri = object?.uri;
|
|
3826
|
+
if (!depUri) continue;
|
|
3827
|
+
const depSourceRaw = await client.fetch(`${depUri}/source/main`, {
|
|
3828
|
+
method: "GET",
|
|
3829
|
+
headers: { Accept: "text/plain" }
|
|
3830
|
+
});
|
|
3831
|
+
const depSource = String(depSourceRaw);
|
|
3832
|
+
const stripped = stripToPublicApi(depSource, object?.type ?? "CLAS");
|
|
3833
|
+
dependencies.push({
|
|
3834
|
+
name: current.name,
|
|
3835
|
+
type: object?.type,
|
|
3836
|
+
uri: depUri,
|
|
3837
|
+
source: stripped.source,
|
|
3838
|
+
fallback: stripped.fallback
|
|
3839
|
+
});
|
|
3840
|
+
if (current.level < depth) enqueueNextDeps(queue, seen, depSource, current.level + 1);
|
|
3841
|
+
}
|
|
3842
|
+
return dependencies;
|
|
3843
|
+
}
|
|
3844
|
+
function enqueueNextDeps(queue, seen, depSource, level) {
|
|
3845
|
+
const nextDeps = extractDependencies(depSource);
|
|
3846
|
+
for (const next of nextDeps) if (!seen.has(next)) queue.push({
|
|
3847
|
+
name: next,
|
|
3848
|
+
level
|
|
3849
|
+
});
|
|
3850
|
+
}
|
|
3783
3851
|
function registerGetContextTool(server, ctx) {
|
|
3784
3852
|
server.tool("get_context", "Fetch compressed dependency context for an ABAP object by stripping dependencies to their public API surface.", {
|
|
3785
3853
|
...sessionOrConnectionShape,
|
|
@@ -3802,46 +3870,7 @@ function registerGetContextTool(server, ctx) {
|
|
|
3802
3870
|
method: "GET",
|
|
3803
3871
|
headers: { Accept: "text/plain" }
|
|
3804
3872
|
});
|
|
3805
|
-
const
|
|
3806
|
-
name,
|
|
3807
|
-
level: 1
|
|
3808
|
-
}));
|
|
3809
|
-
const seen = /* @__PURE__ */ new Set();
|
|
3810
|
-
const dependencies = [];
|
|
3811
|
-
while (queue.length > 0 && dependencies.length < args.maxDeps) {
|
|
3812
|
-
const current = queue.shift();
|
|
3813
|
-
if (!current) break;
|
|
3814
|
-
if (seen.has(current.name)) continue;
|
|
3815
|
-
seen.add(current.name);
|
|
3816
|
-
const searchResult = await client.adt.repository.informationsystem.search.quickSearch({
|
|
3817
|
-
query: current.name,
|
|
3818
|
-
maxResults: 10
|
|
3819
|
-
});
|
|
3820
|
-
const upperName = current.name.toUpperCase();
|
|
3821
|
-
const object = extractObjectReferences(searchResult).find((candidate) => String(candidate.name ?? "").toUpperCase() === upperName);
|
|
3822
|
-
const depUri = object?.uri;
|
|
3823
|
-
if (!depUri) continue;
|
|
3824
|
-
const depSourceRaw = await client.fetch(`${depUri}/source/main`, {
|
|
3825
|
-
method: "GET",
|
|
3826
|
-
headers: { Accept: "text/plain" }
|
|
3827
|
-
});
|
|
3828
|
-
const depSource = String(depSourceRaw);
|
|
3829
|
-
const stripped = stripToPublicApi(depSource, object?.type ?? "CLAS");
|
|
3830
|
-
dependencies.push({
|
|
3831
|
-
name: current.name,
|
|
3832
|
-
type: object?.type,
|
|
3833
|
-
uri: depUri,
|
|
3834
|
-
source: stripped.source,
|
|
3835
|
-
fallback: stripped.fallback
|
|
3836
|
-
});
|
|
3837
|
-
if (current.level < args.depth) {
|
|
3838
|
-
const nextDeps = extractDependencies(depSource);
|
|
3839
|
-
for (const next of nextDeps) if (!seen.has(next)) queue.push({
|
|
3840
|
-
name: next,
|
|
3841
|
-
level: current.level + 1
|
|
3842
|
-
});
|
|
3843
|
-
}
|
|
3844
|
-
}
|
|
3873
|
+
const dependencies = await collectDependencyContext(client, String(rootSourceRaw), args.depth, args.maxDeps);
|
|
3845
3874
|
return { content: [{
|
|
3846
3875
|
type: "text",
|
|
3847
3876
|
text: JSON.stringify({
|
|
@@ -3880,10 +3909,11 @@ function registerGetShortDumpsTool(server, ctx) {
|
|
|
3880
3909
|
}, async (args, extra) => {
|
|
3881
3910
|
try {
|
|
3882
3911
|
const { client } = await resolveClient(ctx, args, extra ?? {});
|
|
3883
|
-
const
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3912
|
+
const queryParams = {};
|
|
3913
|
+
if (args.user) queryParams.user = args.user;
|
|
3914
|
+
if (args.maxResults != null) queryParams.maxResults = String(args.maxResults);
|
|
3915
|
+
const query = args.user || args.maxResults != null ? `?${new URLSearchParams(queryParams).toString()}` : "";
|
|
3916
|
+
const path = args.id ? `/sap/bc/adt/runtime/dumps/${encodeURIComponent(args.id)}` : `/sap/bc/adt/runtime/dumps${query}`;
|
|
3887
3917
|
const result = await client.fetch(path, {
|
|
3888
3918
|
method: "GET",
|
|
3889
3919
|
headers: { Accept: "application/json" }
|
|
@@ -4140,6 +4170,9 @@ function registerGetFeaturesTool(server, ctx) {
|
|
|
4140
4170
|
*
|
|
4141
4171
|
* ADT approach: create new object → copy source → activate clone
|
|
4142
4172
|
*/
|
|
4173
|
+
function isCloneSourceType(type) {
|
|
4174
|
+
return type === "PROG" || type === "CLAS" || type === "INTF";
|
|
4175
|
+
}
|
|
4143
4176
|
async function getSourceCode(client, objectType, objectName) {
|
|
4144
4177
|
const name = objectName.toLowerCase();
|
|
4145
4178
|
switch (objectType) {
|
|
@@ -4200,17 +4233,17 @@ function registerCloneObjectTool(server, ctx) {
|
|
|
4200
4233
|
transport: z.string().optional().describe("Transport request number for the clone")
|
|
4201
4234
|
}, async (args, extra) => {
|
|
4202
4235
|
try {
|
|
4203
|
-
const { client } = await resolveClient(ctx, args, extra ?? {});
|
|
4204
4236
|
const sourceType = args.sourceObjectType.toUpperCase().split("/")[0];
|
|
4205
4237
|
const sourceName = args.sourceObjectName.toUpperCase();
|
|
4206
4238
|
const targetName = args.targetObjectName.toUpperCase();
|
|
4207
|
-
if (!
|
|
4239
|
+
if (!isCloneSourceType(sourceType)) return {
|
|
4208
4240
|
isError: true,
|
|
4209
4241
|
content: [{
|
|
4210
4242
|
type: "text",
|
|
4211
|
-
text: `Object type '${sourceType}' is not supported for cloning. Supported types:
|
|
4243
|
+
text: `Object type '${sourceType}' is not supported for cloning. Supported types: PROG, CLAS, INTF`
|
|
4212
4244
|
}]
|
|
4213
4245
|
};
|
|
4246
|
+
const { client } = await resolveClient(ctx, args, extra ?? {});
|
|
4214
4247
|
const description = await resolveCloneDescription(client, sourceType, sourceName, args.targetDescription);
|
|
4215
4248
|
const sourceCode = await getSourceCode(client, sourceType, sourceName);
|
|
4216
4249
|
await createAdtObject(client, {
|
|
@@ -4410,6 +4443,71 @@ function buildClassSource(rawSource, className) {
|
|
|
4410
4443
|
if (rawSource.trimStart().toUpperCase().startsWith("CLASS ")) return rawSource;
|
|
4411
4444
|
return buildClassTemplate(className, rawSource);
|
|
4412
4445
|
}
|
|
4446
|
+
/** 1. Create temp class (POST skeleton). Returns true when freshly created. */
|
|
4447
|
+
async function createTempClass(client, className, packageName, transport) {
|
|
4448
|
+
try {
|
|
4449
|
+
await client.adt.oo.classes.post(transport ? { corrNr: transport } : {}, { abapClass: {
|
|
4450
|
+
name: className,
|
|
4451
|
+
type: "CLAS/OC",
|
|
4452
|
+
description: "Temporary ADT MCP runner class",
|
|
4453
|
+
language: "EN",
|
|
4454
|
+
masterLanguage: "EN",
|
|
4455
|
+
packageRef: {
|
|
4456
|
+
uri: `/sap/bc/adt/packages/${packageName}`,
|
|
4457
|
+
name: packageName,
|
|
4458
|
+
type: "DEVC/K"
|
|
4459
|
+
}
|
|
4460
|
+
} });
|
|
4461
|
+
return true;
|
|
4462
|
+
} catch (err) {
|
|
4463
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
4464
|
+
if (!msg.includes("already exists") && !msg.includes("422")) throw err;
|
|
4465
|
+
return false;
|
|
4466
|
+
}
|
|
4467
|
+
}
|
|
4468
|
+
/** 2–4. Lock → write source → unlock → activate → execute. */
|
|
4469
|
+
async function executeClassRun(client, lockService, classUri, className, classSource, transport) {
|
|
4470
|
+
const lock = await lockService.lock(classUri, {
|
|
4471
|
+
transport,
|
|
4472
|
+
objectName: className,
|
|
4473
|
+
objectType: "CLAS"
|
|
4474
|
+
});
|
|
4475
|
+
let lockHandle = lock.handle;
|
|
4476
|
+
try {
|
|
4477
|
+
const effectiveTransport = resolveLockCorrelation(lock, transport);
|
|
4478
|
+
const params = new URLSearchParams();
|
|
4479
|
+
params.set("lockHandle", lockHandle);
|
|
4480
|
+
if (effectiveTransport) params.set("corrNr", effectiveTransport);
|
|
4481
|
+
await client.fetch(`${classUri}/source/main?${params.toString()}`, {
|
|
4482
|
+
method: "PUT",
|
|
4483
|
+
headers: { "Content-Type": "text/plain" },
|
|
4484
|
+
body: classSource
|
|
4485
|
+
});
|
|
4486
|
+
await lockService.unlock(classUri, { lockHandle });
|
|
4487
|
+
lockHandle = void 0;
|
|
4488
|
+
await client.adt.activation.activate.post({}, { objectReferences: { objectReference: [{
|
|
4489
|
+
uri: classUri,
|
|
4490
|
+
name: className
|
|
4491
|
+
}] } });
|
|
4492
|
+
const result = await client.adt.oo.classrun.post(className);
|
|
4493
|
+
return typeof result === "string" ? result : String(result ?? "");
|
|
4494
|
+
} catch (err) {
|
|
4495
|
+
if (lockHandle) try {
|
|
4496
|
+
await lockService.unlock(classUri, { lockHandle });
|
|
4497
|
+
} catch {}
|
|
4498
|
+
throw err;
|
|
4499
|
+
}
|
|
4500
|
+
}
|
|
4501
|
+
/** 5. Cleanup — always try to delete unless keepClass is set. */
|
|
4502
|
+
async function cleanupTempClass(client, className, transport, created, keepClass) {
|
|
4503
|
+
if (!created || keepClass) return false;
|
|
4504
|
+
try {
|
|
4505
|
+
await client.adt.oo.classes.delete(className.toLowerCase(), transport ? { corrNr: transport } : {});
|
|
4506
|
+
return true;
|
|
4507
|
+
} catch {
|
|
4508
|
+
return false;
|
|
4509
|
+
}
|
|
4510
|
+
}
|
|
4413
4511
|
function registerRunAbapTool(server, ctx) {
|
|
4414
4512
|
server.tool("run_abap", "Execute an ad-hoc ABAP snippet via a temporary IF_OO_ADT_CLASSRUN class. Creates the class, writes the source, activates, executes, then deletes (unless keepClass is true).", {
|
|
4415
4513
|
...sessionOrConnectionShape,
|
|
@@ -4439,63 +4537,17 @@ function registerRunAbapTool(server, ctx) {
|
|
|
4439
4537
|
const classUri = `/sap/bc/adt/oo/classes/${className.toLowerCase()}`;
|
|
4440
4538
|
const classSource = buildClassSource(args.source, className);
|
|
4441
4539
|
const lockService = createLockService(client);
|
|
4442
|
-
let lockHandle;
|
|
4443
4540
|
let output = "";
|
|
4444
4541
|
let executionError;
|
|
4445
4542
|
let created = false;
|
|
4446
|
-
let classDeleted
|
|
4543
|
+
let classDeleted;
|
|
4447
4544
|
try {
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
name: className,
|
|
4451
|
-
type: "CLAS/OC",
|
|
4452
|
-
description: "Temporary ADT MCP runner class",
|
|
4453
|
-
language: "EN",
|
|
4454
|
-
masterLanguage: "EN",
|
|
4455
|
-
packageRef: {
|
|
4456
|
-
uri: `/sap/bc/adt/packages/${packageName}`,
|
|
4457
|
-
name: packageName,
|
|
4458
|
-
type: "DEVC/K"
|
|
4459
|
-
}
|
|
4460
|
-
} });
|
|
4461
|
-
created = true;
|
|
4462
|
-
} catch (err) {
|
|
4463
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
4464
|
-
if (!msg.includes("already exists") && !msg.includes("422")) throw err;
|
|
4465
|
-
}
|
|
4466
|
-
const lock = await lockService.lock(classUri, {
|
|
4467
|
-
transport,
|
|
4468
|
-
objectName: className,
|
|
4469
|
-
objectType: "CLAS"
|
|
4470
|
-
});
|
|
4471
|
-
lockHandle = lock.handle;
|
|
4472
|
-
const effectiveTransport = resolveLockCorrelation(lock, transport);
|
|
4473
|
-
const params = new URLSearchParams();
|
|
4474
|
-
params.set("lockHandle", lockHandle);
|
|
4475
|
-
if (effectiveTransport) params.set("corrNr", effectiveTransport);
|
|
4476
|
-
await client.fetch(`${classUri}/source/main?${params.toString()}`, {
|
|
4477
|
-
method: "PUT",
|
|
4478
|
-
headers: { "Content-Type": "text/plain" },
|
|
4479
|
-
body: classSource
|
|
4480
|
-
});
|
|
4481
|
-
await lockService.unlock(classUri, { lockHandle });
|
|
4482
|
-
lockHandle = void 0;
|
|
4483
|
-
await client.adt.activation.activate.post({}, { objectReferences: { objectReference: [{
|
|
4484
|
-
uri: classUri,
|
|
4485
|
-
name: className
|
|
4486
|
-
}] } });
|
|
4487
|
-
const result = await client.adt.oo.classrun.post(className);
|
|
4488
|
-
output = typeof result === "string" ? result : String(result ?? "");
|
|
4545
|
+
created = await createTempClass(client, className, packageName, transport);
|
|
4546
|
+
output = await executeClassRun(client, lockService, classUri, className, classSource, transport);
|
|
4489
4547
|
} catch (err) {
|
|
4490
4548
|
executionError = err instanceof Error ? err : new Error(String(err));
|
|
4491
|
-
if (lockHandle) try {
|
|
4492
|
-
await lockService.unlock(classUri, { lockHandle });
|
|
4493
|
-
} catch {}
|
|
4494
4549
|
} finally {
|
|
4495
|
-
|
|
4496
|
-
await client.adt.oo.classes.delete(className.toLowerCase(), transport ? { corrNr: transport } : {});
|
|
4497
|
-
classDeleted = true;
|
|
4498
|
-
} catch {}
|
|
4550
|
+
classDeleted = await cleanupTempClass(client, className, transport, created, keepClass);
|
|
4499
4551
|
}
|
|
4500
4552
|
if (executionError) return {
|
|
4501
4553
|
isError: true,
|
|
@@ -5193,7 +5245,7 @@ function registerUnpublishSrvbTool(server, ctx) {
|
|
|
5193
5245
|
* then releases the lock.
|
|
5194
5246
|
*/
|
|
5195
5247
|
function escapeXmlAttr(value) {
|
|
5196
|
-
return value.replaceAll(
|
|
5248
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """);
|
|
5197
5249
|
}
|
|
5198
5250
|
function registerCtsUpdateTransportTool(server, ctx) {
|
|
5199
5251
|
server.tool("cts_update_transport", "Update a transport request (description, target, project). Uses ADT lock/unlock protocol.", {
|
|
@@ -6204,7 +6256,7 @@ function registerCallRfcTool(server, ctx) {
|
|
|
6204
6256
|
server.tool("call_rfc", "Invoke a classic RFC function module on the SAP system via SOAP-over-HTTP (/sap/bc/soap/rfc). Use this for BAPIs, STFC_CONNECTION, custom RFC FMs, etc.", {
|
|
6205
6257
|
...sessionOrConnectionShape,
|
|
6206
6258
|
functionModule: z.string().describe("RFC function module name (case-insensitive, e.g. \"STFC_CONNECTION\")"),
|
|
6207
|
-
parameters: z.record(z.unknown()).optional().describe("Flat key/value map of RFC parameters. Scalars as strings; structures as objects; tables as arrays of objects."),
|
|
6259
|
+
parameters: z.record(z.string(), z.unknown()).optional().describe("Flat key/value map of RFC parameters. Scalars as strings; structures as objects; tables as arrays of objects."),
|
|
6208
6260
|
client: z.string().optional().describe("Override sap-client query parameter")
|
|
6209
6261
|
}, async (args, extra) => {
|
|
6210
6262
|
try {
|
|
@@ -6595,16 +6647,8 @@ function registerCtsTransportSourceManifestTool(server, ctx) {
|
|
|
6595
6647
|
|
|
6596
6648
|
// src/lib/flow-workspace.ts
|
|
6597
6649
|
function isWithin(root, candidate) {
|
|
6598
|
-
const
|
|
6599
|
-
|
|
6600
|
-
if (normalizedCandidate === normalizedRoot) return true;
|
|
6601
|
-
if (!normalizedCandidate.startsWith(normalizedRoot + sep)) {
|
|
6602
|
-
const rel = relative(normalizedRoot, normalizedCandidate);
|
|
6603
|
-
if (rel.startsWith("..") || isAbsolute(rel)) return false;
|
|
6604
|
-
return !rel.split(sep).includes("..");
|
|
6605
|
-
}
|
|
6606
|
-
const path = relative(normalizedRoot, normalizedCandidate);
|
|
6607
|
-
return path === "" || !isAbsolute(path) && !path.split(sep).filter(Boolean).includes("..");
|
|
6650
|
+
const rel = relative(normalize(root), normalize(candidate));
|
|
6651
|
+
return rel === "" || rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel);
|
|
6608
6652
|
}
|
|
6609
6653
|
async function resolveFlowWorkspaceRoot(requested, allowedRoots = [process.cwd()]) {
|
|
6610
6654
|
if (typeof requested !== "string" || requested.length === 0) throw new Error("workspaceRoot must be a non-empty string.");
|
|
@@ -6613,6 +6657,7 @@ async function resolveFlowWorkspaceRoot(requested, allowedRoots = [process.cwd()
|
|
|
6613
6657
|
if (!isAbsolute(requested) && !isAbsolute(normalizedInput)) throw new Error("workspaceRoot must be absolute.");
|
|
6614
6658
|
const requestedPath = resolve(normalizedInput);
|
|
6615
6659
|
if (normalize(requestedPath).split(sep).includes("..")) throw new Error("workspaceRoot must not contain path traversal sequences.");
|
|
6660
|
+
if (!allowedRoots.map((root) => resolve(root)).some((root) => isWithin(root, requestedPath))) throw new Error("workspaceRoot is outside the server-owned roots.");
|
|
6616
6661
|
const requestedStats = await lstat(requestedPath);
|
|
6617
6662
|
if (!requestedStats.isDirectory() || requestedStats.isSymbolicLink()) throw new Error("workspaceRoot must be a real directory (no symlinks).");
|
|
6618
6663
|
const candidate = await realpath(requestedPath);
|
|
@@ -6911,7 +6956,7 @@ function toolListEntry(name, tool) {
|
|
|
6911
6956
|
return {
|
|
6912
6957
|
name,
|
|
6913
6958
|
...tool.description ? { description: tool.description } : {},
|
|
6914
|
-
inputSchema:
|
|
6959
|
+
inputSchema: toJsonSchemaCompat(tool.inputSchema),
|
|
6915
6960
|
...tool.annotations ? { annotations: tool.annotations } : {}
|
|
6916
6961
|
};
|
|
6917
6962
|
}
|
|
@@ -6939,7 +6984,7 @@ function normalizeToolArgs(args) {
|
|
|
6939
6984
|
if (typeof name !== "string") throw new TypeError("MCP tools must declare a string name");
|
|
6940
6985
|
const handler = args.at(-1);
|
|
6941
6986
|
const hasDescription = typeof args[1] === "string" && args.length >= 4;
|
|
6942
|
-
const description = hasDescription ? args[1] : void 0;
|
|
6987
|
+
const description = hasDescription && typeof args[1] === "string" ? args[1] : void 0;
|
|
6943
6988
|
const inputSchema = args[hasDescription ? 2 : 1];
|
|
6944
6989
|
const annotationsIndex = hasDescription ? 3 : 2;
|
|
6945
6990
|
return {
|
|
@@ -7219,4 +7264,4 @@ function createMcpServer(options) {
|
|
|
7219
7264
|
}
|
|
7220
7265
|
|
|
7221
7266
|
export { isMcpDestinationKey as a, operationClassForMcpTool as c, assertMcpToolIsClassified as i, resolveObjectUri as l, registerTools as n, isMcpOperationClass as o, MCP_TOOL_SCOPE_CATALOGUE as r, isMcpToolAllowed as s, createMcpServer as t };
|
|
7222
|
-
//# sourceMappingURL=server-
|
|
7267
|
+
//# sourceMappingURL=server-Dylu87TZ.mjs.map
|