@mwillbanks/ast-mcp 0.2.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/CONTRIBUTING.md +13 -0
  2. package/README.md +18 -16
  3. package/dist/ast-mcp.js +209 -147
  4. package/dist/ast-mcp.js.map +70 -50
  5. package/package.json +21 -15
  6. package/src/ast-bro/capability.ts +20 -10
  7. package/src/ast-bro/client.ts +12 -6
  8. package/src/ast-bro/result.ts +79 -0
  9. package/src/ast-bro/tools.json +29 -4
  10. package/src/cli.ts +10 -7
  11. package/src/config-cli.ts +166 -19
  12. package/src/config-edit.ts +236 -0
  13. package/src/config-migrate.ts +206 -0
  14. package/src/config-registry.ts +329 -0
  15. package/src/config-schema-common.ts +88 -0
  16. package/src/config-v2-schema.ts +109 -0
  17. package/src/config.ts +523 -170
  18. package/src/helpers/ast-bro.ts +1 -7
  19. package/src/helpers/config.ts +16 -3
  20. package/src/helpers/installer.ts +8 -0
  21. package/src/helpers/mcp-schema.ts +98 -4
  22. package/src/host-smoke.ts +182 -0
  23. package/src/http.ts +8 -3
  24. package/src/installer-transport.ts +6 -4
  25. package/src/installer.ts +242 -54
  26. package/src/patch/engine.ts +575 -280
  27. package/src/patch/languages.ts +9 -0
  28. package/src/patch/strategy/aiderBlock.ts +110 -0
  29. package/src/patch/strategy/ast.ts +170 -0
  30. package/src/patch/strategy.ts +61 -0
  31. package/src/runtime/approval.ts +438 -0
  32. package/src/runtime/config-write.ts +327 -0
  33. package/src/runtime/dependencies.ts +14 -78
  34. package/src/runtime/document-inspection.ts +78 -0
  35. package/src/runtime/file-capabilities.ts +250 -0
  36. package/src/runtime/file-delete.ts +110 -37
  37. package/src/runtime/file-read.ts +134 -15
  38. package/src/runtime/file-rename.ts +5 -2
  39. package/src/runtime/format.ts +90 -30
  40. package/src/runtime/git-worktrees.ts +179 -0
  41. package/src/runtime/path-policy.ts +643 -0
  42. package/src/runtime/path-utils.ts +80 -0
  43. package/src/runtime/paths.ts +171 -47
  44. package/src/server.ts +2 -1
  45. package/src/tools/ast-bro.ts +294 -75
  46. package/src/tools/configuration.ts +668 -0
  47. package/src/tools/configured.ts +49 -21
  48. package/src/tools/files.ts +169 -62
  49. package/src/tools/index.ts +2 -0
  50. package/src/tools/lifecycle.ts +82 -38
  51. package/templates/AGENTS.md +17 -15
  52. package/templates/skills/ast-mcp/SKILL.md +57 -20
  53. package/templates/skills/ast-mcp/evals/evals.json +319 -9
  54. package/templates/skills/ast-mcp/evals/score.ts +80 -0
  55. package/templates/skills/ast-mcp/evals/semantic.ts +3 -1
  56. package/templates/skills/ast-mcp/references/installation.md +12 -12
  57. package/templates/skills/ast-mcp/references/patch-state-machine.md +15 -14
  58. package/templates/skills/ast-mcp/references/tool-catalog.md +18 -8
  59. package/templates/skills/ast-mcp/scripts/binary-resolution.ts +112 -0
  60. package/templates/skills/ast-mcp/scripts/check-install.ts +165 -51
  61. package/templates/skills/ast-mcp/scripts/managed-hook.ts +34 -2
  62. package/src/ast-bro/rewrite-capability.ts +0 -9
@@ -0,0 +1,668 @@
1
+ import { constants } from "node:fs";
2
+ import { open } from "node:fs/promises";
3
+ import path from "node:path";
4
+ import type { McpServer } from "@modelcontextprotocol/server";
5
+ import { z } from "zod";
6
+ import { currentConfig, type ResolvedConfig } from "../config";
7
+ import { configRegistry } from "../config-registry";
8
+ import {
9
+ toolFailure,
10
+ toolOutputSchema,
11
+ toolSuccess,
12
+ } from "../helpers/mcp-schema";
13
+ import { applyConfigCore, applyConfigPaths } from "../runtime/config-write";
14
+ import {
15
+ parseStructuredDocument,
16
+ selectDocumentValue,
17
+ } from "../runtime/document-inspection";
18
+ import { sha256 } from "../runtime/hash";
19
+ import { evaluatePolicyForCheck } from "../runtime/path-policy";
20
+ import { resolveWorkspacePath } from "../runtime/paths";
21
+ import { type ConfiguredExecution, localExecution } from "./configured";
22
+
23
+ interface JsonLocationToken {
24
+ end: number;
25
+ start: number;
26
+ text: string;
27
+ value?: string;
28
+ }
29
+
30
+ function skipJsonTrivia(source: string, start: number): number {
31
+ let cursor = start;
32
+ while (cursor < source.length) {
33
+ if (/\s/.test(source[cursor] ?? "")) {
34
+ cursor += 1;
35
+ continue;
36
+ }
37
+ if (source.startsWith("//", cursor)) {
38
+ const newline = source.indexOf("\n", cursor + 2);
39
+ cursor = newline < 0 ? source.length : newline + 1;
40
+ continue;
41
+ }
42
+ if (source.startsWith("/*", cursor)) {
43
+ const close = source.indexOf("*/", cursor + 2);
44
+ cursor = close < 0 ? source.length : close + 2;
45
+ continue;
46
+ }
47
+ break;
48
+ }
49
+ return cursor;
50
+ }
51
+
52
+ function scanJsonString(source: string, start: number): JsonLocationToken {
53
+ let cursor = start + 1;
54
+ while (cursor < source.length) {
55
+ if (source[cursor] === "\\") {
56
+ cursor += 2;
57
+ continue;
58
+ }
59
+ if (source[cursor] === '"') {
60
+ cursor += 1;
61
+ break;
62
+ }
63
+ cursor += 1;
64
+ }
65
+ const text = source.slice(start, cursor);
66
+ return { end: cursor, start, text, value: JSON.parse(text) as string };
67
+ }
68
+
69
+ function nextJsonLocationToken(
70
+ source: string,
71
+ cursor: number,
72
+ ): JsonLocationToken | undefined {
73
+ const start = skipJsonTrivia(source, cursor);
74
+ if (start >= source.length) return undefined;
75
+ if (source[start] === '"') return scanJsonString(source, start);
76
+ const punctuation = source[start] ?? "";
77
+ if ("{}[],:".includes(punctuation))
78
+ return { end: start + 1, start, text: punctuation };
79
+ let end = start + 1;
80
+ while (end < source.length && !/[\s{}[\],:]/.test(source[end] ?? ""))
81
+ end += 1;
82
+ return { end, start, text: source.slice(start, end) };
83
+ }
84
+
85
+ function pointerChild(pointer: string, token: string): string {
86
+ const encoded = token.replaceAll("~", "~0").replaceAll("/", "~1");
87
+ return `${pointer}/${encoded}`;
88
+ }
89
+
90
+ function walkJsonObject(
91
+ source: string,
92
+ cursor: number,
93
+ pointer: string,
94
+ locations: Map<string, number>,
95
+ ): number {
96
+ while (true) {
97
+ const key = nextJsonLocationToken(source, cursor);
98
+ if (!key) return cursor;
99
+ if (key.text === "}") return key.end;
100
+ if (key.value === undefined) return key.end;
101
+ const colon = nextJsonLocationToken(source, key.end);
102
+ if (!colon) return key.end;
103
+ cursor = walkJsonValue(
104
+ source,
105
+ colon.end,
106
+ pointerChild(pointer, key.value),
107
+ locations,
108
+ key.start,
109
+ );
110
+ const delimiter = nextJsonLocationToken(source, cursor);
111
+ if (!delimiter) return cursor;
112
+ if (delimiter.text === "}") return delimiter.end;
113
+ cursor = delimiter.end;
114
+ }
115
+ }
116
+
117
+ function walkJsonArray(
118
+ source: string,
119
+ cursor: number,
120
+ pointer: string,
121
+ locations: Map<string, number>,
122
+ ): number {
123
+ let index = 0;
124
+ while (true) {
125
+ const item = nextJsonLocationToken(source, cursor);
126
+ if (!item) return cursor;
127
+ if (item.text === "]") return item.end;
128
+ cursor = walkJsonValue(
129
+ source,
130
+ item.start,
131
+ pointerChild(pointer, String(index)),
132
+ locations,
133
+ );
134
+ const delimiter = nextJsonLocationToken(source, cursor);
135
+ if (!delimiter) return cursor;
136
+ if (delimiter.text === "]") return delimiter.end;
137
+ cursor = delimiter.end;
138
+ index += 1;
139
+ }
140
+ }
141
+
142
+ function walkJsonValue(
143
+ source: string,
144
+ cursor: number,
145
+ pointer: string,
146
+ locations: Map<string, number>,
147
+ location?: number,
148
+ ): number {
149
+ const token = nextJsonLocationToken(source, cursor);
150
+ if (!token) return cursor;
151
+ locations.set(pointer, location ?? token.start);
152
+ if (token.text === "{")
153
+ return walkJsonObject(source, token.end, pointer, locations);
154
+ if (token.text === "[")
155
+ return walkJsonArray(source, token.end, pointer, locations);
156
+ return token.end;
157
+ }
158
+
159
+ function jsonPointerLocations(source: string): Map<string, number> {
160
+ const locations = new Map<string, number>();
161
+ walkJsonValue(source, 0, "", locations);
162
+ return locations;
163
+ }
164
+
165
+ function allOccurrences(source: string, candidate: string): number[] {
166
+ const positions: number[] = [];
167
+ let cursor = 0;
168
+ while (cursor < source.length) {
169
+ const position = source.indexOf(candidate, cursor);
170
+ if (position < 0) break;
171
+ positions.push(position);
172
+ cursor = position + Math.max(candidate.length, 1);
173
+ }
174
+ return positions;
175
+ }
176
+
177
+ function fallbackLocationPosition(source: string, selector: string) {
178
+ const token = selector
179
+ .split("/")
180
+ .at(-1)
181
+ ?.replaceAll("~1", "/")
182
+ .replaceAll("~0", "~");
183
+ if (!token) return undefined;
184
+ const candidates = [`"${token}"`, `'${token}'`, `${token}:`, `${token} =`];
185
+ const positions = [
186
+ ...new Set(
187
+ candidates.flatMap((candidate) => allOccurrences(source, candidate)),
188
+ ),
189
+ ];
190
+ return positions.length === 1 ? positions[0] : undefined;
191
+ }
192
+
193
+ function sourceLocation(source: string, selector: string, extension: string) {
194
+ const position =
195
+ extension === ".json" || extension === ".jsonc"
196
+ ? jsonPointerLocations(source).get(selector)
197
+ : selector === ""
198
+ ? 0
199
+ : fallbackLocationPosition(source, selector);
200
+ if (position === undefined) return { selector };
201
+ const preceding = source.slice(0, position);
202
+ const lines = preceding.split("\n");
203
+ return {
204
+ column: (lines.at(-1)?.length ?? 0) + 1,
205
+ line: lines.length,
206
+ selector,
207
+ };
208
+ }
209
+
210
+ const DOCUMENT_SOURCE_LIMIT = 1024 * 1024;
211
+
212
+ function documentTooLarge(): Error {
213
+ return Object.assign(
214
+ new Error("document_query source exceeds the 1 MiB limit"),
215
+ { code: "document_too_large", retryable: false },
216
+ );
217
+ }
218
+
219
+ async function readBoundedDocument(filePath: string): Promise<Buffer> {
220
+ const handle = await open(
221
+ filePath,
222
+ constants.O_RDONLY | constants.O_NONBLOCK,
223
+ );
224
+ try {
225
+ const metadata = await handle.stat();
226
+ if (!metadata.isFile())
227
+ throw Object.assign(new Error("document_query requires a regular file"), {
228
+ code: "document_not_regular",
229
+ retryable: false,
230
+ });
231
+ if (metadata.size > DOCUMENT_SOURCE_LIMIT) throw documentTooLarge();
232
+ const bytes = Buffer.alloc(DOCUMENT_SOURCE_LIMIT + 1);
233
+ let offset = 0;
234
+ while (offset < bytes.length) {
235
+ const result = await handle.read(
236
+ bytes,
237
+ offset,
238
+ bytes.length - offset,
239
+ offset,
240
+ );
241
+ if (result.bytesRead === 0) break;
242
+ offset += result.bytesRead;
243
+ }
244
+ if (offset > DOCUMENT_SOURCE_LIMIT) throw documentTooLarge();
245
+ return bytes.subarray(0, offset);
246
+ } finally {
247
+ await handle.close();
248
+ }
249
+ }
250
+
251
+ function formattingStatus(config: Readonly<ResolvedConfig> | undefined) {
252
+ if (!config) return undefined;
253
+ return {
254
+ enabled: config.formatting.enabled,
255
+ fallback: config.formatting.fallback,
256
+ formatters: config.formatting.formatters.map((formatter) => ({
257
+ enabled: formatter.enabled ?? config.formatting.enabled,
258
+ extensions: formatter.extensions,
259
+ globs: formatter.globs,
260
+ id: formatter.id,
261
+ mode: formatter.mode,
262
+ timeoutMs: formatter.timeoutMs,
263
+ })),
264
+ };
265
+ }
266
+
267
+ async function statusClientRoots(server: McpServer): Promise<string[]> {
268
+ if (!server.server.getClientCapabilities()?.roots) return [];
269
+ return (await server.server.listRoots()).roots.map((root) => root.uri);
270
+ }
271
+
272
+ function statusPayload(
273
+ snapshot: Awaited<ReturnType<typeof configRegistry.snapshot>>,
274
+ ) {
275
+ const base = {
276
+ error: snapshot.error,
277
+ generation: snapshot.generation,
278
+ healthy: snapshot.healthy,
279
+ loadedAt: snapshot.loadedAt,
280
+ };
281
+ const config = snapshot.config;
282
+ if (!config) return base;
283
+ const diagnostics: Array<{
284
+ code: string;
285
+ message: string;
286
+ source: string;
287
+ }> = [];
288
+ for (const name of config.sources.environment)
289
+ if (name === "AST_MCP_PROJECT_ROOT" || name === "AST_MCP_ROOTS")
290
+ diagnostics.push({
291
+ code: "deprecated_root_environment",
292
+ message: `${name} is deprecated; configure workspace.roots in ast-mcp.toml.`,
293
+ source: name,
294
+ });
295
+ return {
296
+ ...base,
297
+ diagnostics,
298
+ formatting: formattingStatus(config),
299
+ mcp: config.mcp.configuration,
300
+ projectRoot: config.projectRoot,
301
+ provenance: config.provenance,
302
+ safety: config.safety,
303
+ sources: config.sources,
304
+ version: config.version,
305
+ workspace: config.workspace,
306
+ };
307
+ }
308
+
309
+ async function configStatus(server: McpServer) {
310
+ try {
311
+ const clientRoots = await statusClientRoots(server);
312
+ return toolSuccess(
313
+ statusPayload(await configRegistry.snapshot({ clientRoots })),
314
+ );
315
+ } catch (error) {
316
+ return toolFailure(error);
317
+ }
318
+ }
319
+
320
+ export default function registerConfigurationTools(
321
+ server: McpServer,
322
+ execute: ConfiguredExecution = localExecution,
323
+ ): void {
324
+ server.registerTool(
325
+ "config_status",
326
+ {
327
+ annotations: {
328
+ destructiveHint: false,
329
+ idempotentHint: true,
330
+ openWorldHint: false,
331
+ readOnlyHint: true,
332
+ },
333
+ description:
334
+ "Returns the redacted effective configuration, source provenance, generation, formatter selection order, and health-relevant metadata.",
335
+ inputSchema: z.object({}).strict(),
336
+ outputSchema: toolOutputSchema,
337
+ title: "Inspect Effective AST MCP Configuration",
338
+ },
339
+ async () => configStatus(server),
340
+ );
341
+
342
+ server.registerTool(
343
+ "policy_check",
344
+ {
345
+ annotations: {
346
+ destructiveHint: false,
347
+ idempotentHint: true,
348
+ openWorldHint: false,
349
+ readOnlyHint: true,
350
+ },
351
+ description:
352
+ "Explains the effective read, write, or delete decision for a batch of paths without performing the operation.",
353
+ inputSchema: z
354
+ .object({
355
+ checks: z
356
+ .array(
357
+ z
358
+ .object({
359
+ operation: z.enum(["read", "write", "delete"]),
360
+ path: z.string().min(1),
361
+ })
362
+ .strict(),
363
+ )
364
+ .min(1)
365
+ .max(50),
366
+ })
367
+ .strict(),
368
+ outputSchema: toolOutputSchema,
369
+ title: "Check Path Authorization Policy",
370
+ },
371
+ async ({ checks }) => {
372
+ try {
373
+ return toolSuccess(
374
+ await execute({ checks }, async () => {
375
+ const config = await currentConfig();
376
+ return {
377
+ decisions: await Promise.all(
378
+ checks.map(async (check) =>
379
+ evaluatePolicyForCheck(config, check.path, check.operation),
380
+ ),
381
+ ),
382
+ };
383
+ }),
384
+ );
385
+ } catch (error) {
386
+ return toolFailure(error);
387
+ }
388
+ },
389
+ );
390
+
391
+ server.registerTool(
392
+ "document_query",
393
+ {
394
+ annotations: {
395
+ destructiveHint: false,
396
+ idempotentHint: true,
397
+ openWorldHint: false,
398
+ readOnlyHint: true,
399
+ },
400
+ description:
401
+ "Reads bounded values from JSON, JSONC, TOML, or YAML by RFC 6901 selectors and returns the whole-file hash.",
402
+ inputSchema: z
403
+ .object({
404
+ filePath: z.string().min(1),
405
+ selectors: z.array(z.string()).min(1).max(100),
406
+ })
407
+ .strict(),
408
+ outputSchema: toolOutputSchema,
409
+ title: "Query Structured Documents",
410
+ },
411
+ async ({ filePath, selectors }, context) => {
412
+ try {
413
+ return toolSuccess(
414
+ await execute(
415
+ { filePath },
416
+ async () => {
417
+ const resolved = await resolveWorkspacePath(filePath);
418
+ const bytes = await readBoundedDocument(resolved);
419
+ const source = bytes.toString("utf8");
420
+ const document = parseStructuredDocument(resolved, source);
421
+ const values = selectors.map((selector) => ({
422
+ location: sourceLocation(
423
+ source,
424
+ selector,
425
+ path.extname(resolved).toLowerCase(),
426
+ ),
427
+ selector,
428
+ value: selectDocumentValue(document, selector),
429
+ }));
430
+ if (Buffer.byteLength(JSON.stringify(values)) > 256 * 1024)
431
+ throw Object.assign(
432
+ new Error(
433
+ "document_query result exceeds the 256 KiB limit; use narrower selectors",
434
+ ),
435
+ { code: "document_result_too_large", retryable: true },
436
+ );
437
+ return {
438
+ filePath: resolved,
439
+ sha256: sha256(bytes),
440
+ values,
441
+ };
442
+ },
443
+ context,
444
+ "document_query",
445
+ ),
446
+ );
447
+ } catch (error) {
448
+ return toolFailure(error);
449
+ }
450
+ },
451
+ );
452
+
453
+ const pathPolicy = z.enum(["allow", "deny", "request"]);
454
+ const configTarget = z.enum(["global", "project"]).optional();
455
+ const pathRulePatch = z
456
+ .object({
457
+ excludes: z.array(z.string().min(1)).max(256).optional(),
458
+ follow_symlinks: z.boolean().optional(),
459
+ includes: z.array(z.string().min(1)).max(256).optional(),
460
+ path: z.string().min(1).optional(),
461
+ policies: z
462
+ .object({
463
+ delete: pathPolicy.optional(),
464
+ read: pathPolicy.optional(),
465
+ write: pathPolicy.optional(),
466
+ })
467
+ .strict()
468
+ .optional(),
469
+ })
470
+ .strict();
471
+
472
+ server.registerTool(
473
+ "config_core",
474
+ {
475
+ annotations: {
476
+ destructiveHint: true,
477
+ idempotentHint: false,
478
+ openWorldHint: false,
479
+ readOnlyHint: false,
480
+ },
481
+ description:
482
+ "Updates grouped core ast-mcp.toml sections (workspace, safety, files, formatting, http, dependencies, mcp.configuration). Does not rewrite the whole file or change [[paths]]. Configuration changes require user approval by default.",
483
+ inputSchema: z
484
+ .object({
485
+ dependencies: z
486
+ .object({
487
+ ast_bro_binary: z.string().min(1).optional(),
488
+ dprint_binary: z.string().min(1).optional(),
489
+ })
490
+ .strict()
491
+ .optional(),
492
+ files: z
493
+ .object({
494
+ patch: z
495
+ .object({
496
+ aider_matchers: z
497
+ .array(
498
+ z.enum([
499
+ "exact",
500
+ "whitespace",
501
+ "relative-indentation",
502
+ "diff-match-patch",
503
+ ]),
504
+ )
505
+ .max(4)
506
+ .optional(),
507
+ strategies: z
508
+ .array(z.enum(["ast", "aider_block"]))
509
+ .max(2)
510
+ .optional(),
511
+ })
512
+ .strict()
513
+ .optional(),
514
+ read: z
515
+ .object({
516
+ modes: z
517
+ .array(z.enum(["ast", "text"]))
518
+ .max(2)
519
+ .optional(),
520
+ })
521
+ .strict()
522
+ .optional(),
523
+ })
524
+ .strict()
525
+ .optional(),
526
+ formatting: z
527
+ .object({
528
+ dprint_config: z.string().min(1).optional(),
529
+ enabled: z.boolean().optional(),
530
+ fallback: z.enum(["preserve", "dprint", "reject"]).optional(),
531
+ })
532
+ .strict()
533
+ .optional(),
534
+ http: z
535
+ .object({
536
+ host: z.string().min(1).optional(),
537
+ port: z.number().int().min(1).max(65_535).optional(),
538
+ session_sweep_interval_ms: z.number().int().positive().optional(),
539
+ session_timeout_ms: z.number().int().positive().optional(),
540
+ })
541
+ .strict()
542
+ .optional(),
543
+ mcp: z
544
+ .object({
545
+ configuration: z
546
+ .object({
547
+ enabled: z.boolean().optional(),
548
+ require_approval: z.boolean().optional(),
549
+ })
550
+ .strict()
551
+ .optional(),
552
+ })
553
+ .strict()
554
+ .optional(),
555
+ safety: z
556
+ .object({
557
+ hook: z
558
+ .object({
559
+ allow_tools: z.array(z.string().min(1)).max(128).optional(),
560
+ block_tools: z.array(z.string().min(1)).max(128).optional(),
561
+ enabled: z.boolean().optional(),
562
+ })
563
+ .strict()
564
+ .optional(),
565
+ require_hash: z.boolean().optional(),
566
+ })
567
+ .strict()
568
+ .optional(),
569
+ target: configTarget,
570
+ workspace: z
571
+ .object({
572
+ roots: z.array(z.string().min(1)).min(1).optional(),
573
+ worktrees: z.enum(["include", "request", "ignore"]).optional(),
574
+ })
575
+ .strict()
576
+ .optional(),
577
+ })
578
+ .strict(),
579
+ outputSchema: toolOutputSchema,
580
+ title: "Update Core AST MCP Configuration",
581
+ },
582
+ async (args, context) => {
583
+ try {
584
+ return toolSuccess(
585
+ await execute(
586
+ args,
587
+ () => applyConfigCore(args),
588
+ context,
589
+ "config_core",
590
+ ),
591
+ );
592
+ } catch (error) {
593
+ return toolFailure(error);
594
+ }
595
+ },
596
+ );
597
+
598
+ server.registerTool(
599
+ "config_paths",
600
+ {
601
+ annotations: {
602
+ destructiveHint: true,
603
+ idempotentHint: false,
604
+ openWorldHint: false,
605
+ readOnlyHint: false,
606
+ },
607
+ description:
608
+ "Adds, updates, or removes [[paths]] rules in ast-mcp.toml as a batch. Does not change core sections. Configuration changes require user approval by default.",
609
+ inputSchema: z
610
+ .object({
611
+ operations: z
612
+ .array(
613
+ z.union([
614
+ z
615
+ .object({
616
+ op: z.literal("add"),
617
+ rule: pathRulePatch.extend({
618
+ id: z.string().min(1).max(128),
619
+ path: z.string().min(1),
620
+ policies: z
621
+ .object({
622
+ delete: pathPolicy.optional(),
623
+ read: pathPolicy,
624
+ write: pathPolicy,
625
+ })
626
+ .strict(),
627
+ }),
628
+ })
629
+ .strict(),
630
+ z
631
+ .object({
632
+ id: z.string().min(1).max(128),
633
+ op: z.literal("update"),
634
+ rule: pathRulePatch,
635
+ })
636
+ .strict(),
637
+ z
638
+ .object({
639
+ id: z.string().min(1).max(128),
640
+ op: z.literal("remove"),
641
+ })
642
+ .strict(),
643
+ ]),
644
+ )
645
+ .min(1)
646
+ .max(50),
647
+ target: configTarget,
648
+ })
649
+ .strict(),
650
+ outputSchema: toolOutputSchema,
651
+ title: "Update AST MCP Path Rules",
652
+ },
653
+ async (args, context) => {
654
+ try {
655
+ return toolSuccess(
656
+ await execute(
657
+ args,
658
+ () => applyConfigPaths(args),
659
+ context,
660
+ "config_paths",
661
+ ),
662
+ );
663
+ } catch (error) {
664
+ return toolFailure(error);
665
+ }
666
+ },
667
+ );
668
+ }