@mwillbanks/ast-mcp 0.2.1 → 0.2.2
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 +3 -1
- package/dist/ast-mcp.js +63 -63
- package/dist/ast-mcp.js.map +11 -11
- package/package.json +1 -1
- package/src/config.ts +32 -4
- package/src/helpers/config.ts +5 -3
- package/src/helpers/mcp-schema.ts +7 -0
- package/src/runtime/file-delete.ts +33 -4
- package/src/runtime/file-rename.ts +2 -4
- package/src/runtime/paths.ts +85 -22
- package/src/tools/ast-bro.ts +3 -3
- package/src/tools/files.ts +15 -18
- package/src/tools/lifecycle.ts +13 -13
- package/templates/AGENTS.md +5 -5
- package/templates/skills/ast-mcp/SKILL.md +31 -23
- package/templates/skills/ast-mcp/evals/batch.evals.json +9 -9
- package/templates/skills/ast-mcp/evals/measure.ts +27 -4
- package/templates/skills/ast-mcp/evals/score.test.ts +46 -3
- package/templates/skills/ast-mcp/evals/score.ts +7 -0
- package/templates/skills/ast-mcp/evals/semantic.test.ts +209 -28
- package/templates/skills/ast-mcp/evals/semantic.ts +148 -36
- package/templates/skills/ast-mcp/references/installation.md +1 -1
- package/templates/skills/ast-mcp/references/patch-state-machine.md +4 -4
- package/templates/skills/ast-mcp/references/tool-catalog.md +6 -6
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -81,7 +81,9 @@ const fileSchema = z
|
|
|
81
81
|
.optional(),
|
|
82
82
|
safety: z
|
|
83
83
|
.object({
|
|
84
|
+
allow_any_path: z.boolean().optional(),
|
|
84
85
|
allow_external_roots: z.boolean().optional(),
|
|
86
|
+
allow_temp_directory: z.boolean().optional(),
|
|
85
87
|
follow_symlinks: z.boolean().optional(),
|
|
86
88
|
hook: hookSchema.optional(),
|
|
87
89
|
require_hash: z.boolean().optional(),
|
|
@@ -120,7 +122,9 @@ export interface ResolvedConfig {
|
|
|
120
122
|
projectRoot: string;
|
|
121
123
|
provenance: Record<string, "default" | "global" | "project" | "environment">;
|
|
122
124
|
safety: {
|
|
125
|
+
allowAnyPath: boolean;
|
|
123
126
|
allowExternalRoots: boolean;
|
|
127
|
+
allowTempDirectory: boolean;
|
|
124
128
|
followSymlinks: boolean;
|
|
125
129
|
hook: { allowTools: string[]; blockTools: string[]; enabled: boolean };
|
|
126
130
|
requireHash: boolean;
|
|
@@ -170,7 +174,9 @@ interface InternalConfig {
|
|
|
170
174
|
session_sweep_interval_ms?: number;
|
|
171
175
|
};
|
|
172
176
|
safety?: {
|
|
177
|
+
allow_any_path?: boolean;
|
|
173
178
|
allow_external_roots?: boolean;
|
|
179
|
+
allow_temp_directory?: boolean;
|
|
174
180
|
follow_symlinks?: boolean;
|
|
175
181
|
hook?: {
|
|
176
182
|
allow_tools?: string[];
|
|
@@ -457,13 +463,29 @@ function environmentHttp(env: NodeJS.ProcessEnv, usage: EnvironmentUsage) {
|
|
|
457
463
|
}
|
|
458
464
|
|
|
459
465
|
function environmentSafety(env: NodeJS.ProcessEnv, usage: EnvironmentUsage) {
|
|
460
|
-
const
|
|
466
|
+
const allowAnyPath = usage.use(
|
|
467
|
+
"AST_MCP_ALLOW_ANY_PATH",
|
|
468
|
+
booleanEnvironment(env, "AST_MCP_ALLOW_ANY_PATH"),
|
|
469
|
+
);
|
|
470
|
+
const allowExternalRoots = usage.use(
|
|
461
471
|
"AST_MCP_ALLOW_EXTERNAL_ROOTS",
|
|
462
472
|
booleanEnvironment(env, "AST_MCP_ALLOW_EXTERNAL_ROOTS"),
|
|
463
473
|
);
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
474
|
+
const allowTempDirectory = usage.use(
|
|
475
|
+
"AST_MCP_ALLOW_TEMP_DIRECTORY",
|
|
476
|
+
booleanEnvironment(env, "AST_MCP_ALLOW_TEMP_DIRECTORY"),
|
|
477
|
+
);
|
|
478
|
+
if (
|
|
479
|
+
allowAnyPath === undefined &&
|
|
480
|
+
allowExternalRoots === undefined &&
|
|
481
|
+
allowTempDirectory === undefined
|
|
482
|
+
)
|
|
483
|
+
return undefined;
|
|
484
|
+
return {
|
|
485
|
+
allow_any_path: allowAnyPath,
|
|
486
|
+
allow_external_roots: allowExternalRoots,
|
|
487
|
+
allow_temp_directory: allowTempDirectory,
|
|
488
|
+
};
|
|
467
489
|
}
|
|
468
490
|
|
|
469
491
|
function environmentLayer(
|
|
@@ -491,7 +513,9 @@ function environmentLayer(
|
|
|
491
513
|
const leaves = [
|
|
492
514
|
"version",
|
|
493
515
|
"workspace.roots",
|
|
516
|
+
"safety.allow_any_path",
|
|
494
517
|
"safety.allow_external_roots",
|
|
518
|
+
"safety.allow_temp_directory",
|
|
495
519
|
"safety.follow_symlinks",
|
|
496
520
|
"safety.hook.allow_tools",
|
|
497
521
|
"safety.hook.block_tools",
|
|
@@ -615,7 +639,9 @@ function defaultInternalConfig(candidates: string[]): InternalConfig {
|
|
|
615
639
|
session_timeout_ms: 30 * 60 * 1000,
|
|
616
640
|
},
|
|
617
641
|
safety: {
|
|
642
|
+
allow_any_path: false,
|
|
618
643
|
allow_external_roots: false,
|
|
644
|
+
allow_temp_directory: true,
|
|
619
645
|
follow_symlinks: false,
|
|
620
646
|
hook: { allow_tools: [], block_tools: [], enabled: true },
|
|
621
647
|
require_hash: true,
|
|
@@ -679,7 +705,9 @@ function resolvedHook(value: InternalConfig["safety"]) {
|
|
|
679
705
|
|
|
680
706
|
function resolvedSafety(value: InternalConfig): ResolvedConfig["safety"] {
|
|
681
707
|
return {
|
|
708
|
+
allowAnyPath: withDefault(value.safety?.allow_any_path, false),
|
|
682
709
|
allowExternalRoots: withDefault(value.safety?.allow_external_roots, false),
|
|
710
|
+
allowTempDirectory: withDefault(value.safety?.allow_temp_directory, true),
|
|
683
711
|
followSymlinks: withDefault(value.safety?.follow_symlinks, false),
|
|
684
712
|
hook: resolvedHook(value.safety),
|
|
685
713
|
requireHash: withDefault(value.safety?.require_hash, true),
|
package/src/helpers/config.ts
CHANGED
|
@@ -139,11 +139,13 @@ function isKeyedBatchPath(
|
|
|
139
139
|
childKey: string,
|
|
140
140
|
child: unknown,
|
|
141
141
|
): boolean {
|
|
142
|
+
const isBatchEntry =
|
|
143
|
+
parentKey === "files" ||
|
|
144
|
+
(parentKey === undefined && !keyedBatchExclusions.has(childKey));
|
|
142
145
|
return (
|
|
143
|
-
|
|
146
|
+
isBatchEntry &&
|
|
144
147
|
Boolean(child) &&
|
|
145
148
|
typeof child === "object" &&
|
|
146
|
-
!Array.isArray(child)
|
|
147
|
-
!keyedBatchExclusions.has(childKey)
|
|
149
|
+
!Array.isArray(child)
|
|
148
150
|
);
|
|
149
151
|
}
|
|
@@ -18,6 +18,13 @@ export function boundedRecord<T extends z.ZodType>(schema: T, label: string) {
|
|
|
18
18
|
}, label);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
export function boundedFileBatch<T extends z.ZodType>(
|
|
22
|
+
schema: T,
|
|
23
|
+
label: string,
|
|
24
|
+
) {
|
|
25
|
+
return z.object({ files: boundedRecord(schema, label) }).strict();
|
|
26
|
+
}
|
|
27
|
+
|
|
21
28
|
export function toolFailure(error: unknown) {
|
|
22
29
|
return {
|
|
23
30
|
content: [
|
|
@@ -6,7 +6,11 @@ import { parseAstBroJson } from "../ast-bro/result";
|
|
|
6
6
|
import { detectAstLanguage } from "../patch/languages";
|
|
7
7
|
import { sha256File } from "./hash";
|
|
8
8
|
import { withFileLocks } from "./locks";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
configuredRootForPath,
|
|
11
|
+
resolveWritablePath,
|
|
12
|
+
rootForPath,
|
|
13
|
+
} from "./paths";
|
|
10
14
|
import { requireExpectedHash, verifyExpectedHash } from "./policy";
|
|
11
15
|
|
|
12
16
|
export interface FileDeleteRequest {
|
|
@@ -64,12 +68,30 @@ export async function deleteFilesSafely(requests: FileDeleteBatch) {
|
|
|
64
68
|
if (!metadata.isFile())
|
|
65
69
|
throw new Error(`file_delete accepts files only: ${inputPath}`);
|
|
66
70
|
const root = await rootForPath(filePath);
|
|
67
|
-
const
|
|
71
|
+
const referenceRoot = await configuredRootForPath(filePath);
|
|
72
|
+
const language = detectAstLanguage(filePath);
|
|
73
|
+
if (
|
|
74
|
+
!referenceRoot &&
|
|
75
|
+
(await astCapable(filePath, language)) &&
|
|
76
|
+
!request.forceReferences
|
|
77
|
+
)
|
|
78
|
+
throw new Error(
|
|
79
|
+
`file_delete rejected ${inputPath}: references cannot be verified outside configured file-operation roots; set forceReferences to override`,
|
|
80
|
+
);
|
|
81
|
+
const importers = referenceRoot
|
|
82
|
+
? await importersFor(filePath, referenceRoot)
|
|
83
|
+
: [];
|
|
68
84
|
if (importers.length > 0 && !request.forceReferences)
|
|
69
85
|
throw new Error(
|
|
70
86
|
`file_delete rejected ${inputPath}: referenced by ${importers.join(", ")}; set forceReferences to override`,
|
|
71
87
|
);
|
|
72
|
-
return {
|
|
88
|
+
return {
|
|
89
|
+
filePath,
|
|
90
|
+
importers,
|
|
91
|
+
referencesVerified: referenceRoot !== undefined,
|
|
92
|
+
request,
|
|
93
|
+
root,
|
|
94
|
+
};
|
|
73
95
|
}),
|
|
74
96
|
);
|
|
75
97
|
const files = await withFileLocks(
|
|
@@ -81,12 +103,19 @@ export async function deleteFilesSafely(requests: FileDeleteBatch) {
|
|
|
81
103
|
await requireExpectedHash(request.expectedSha256, "file_delete");
|
|
82
104
|
verifyExpectedHash(request.expectedSha256, actual);
|
|
83
105
|
}
|
|
84
|
-
for (const {
|
|
106
|
+
for (const {
|
|
107
|
+
filePath,
|
|
108
|
+
importers,
|
|
109
|
+
referencesVerified,
|
|
110
|
+
request,
|
|
111
|
+
} of entries) {
|
|
85
112
|
await rm(filePath);
|
|
86
113
|
deleted[filePath] = {
|
|
87
114
|
deleted: true,
|
|
88
115
|
forcedReferences:
|
|
89
116
|
importers.length > 0 && request.forceReferences === true,
|
|
117
|
+
referenceVerificationBypassed:
|
|
118
|
+
!referencesVerified && request.forceReferences === true,
|
|
90
119
|
};
|
|
91
120
|
}
|
|
92
121
|
return deleted;
|
|
@@ -4,7 +4,7 @@ import { dirname, join } from "node:path";
|
|
|
4
4
|
|
|
5
5
|
import { sha256File } from "./hash";
|
|
6
6
|
import { withFileLocks } from "./locks";
|
|
7
|
-
import {
|
|
7
|
+
import { pathsShareRoot, resolveWritablePath } from "./paths";
|
|
8
8
|
import { requireExpectedHash, verifyExpectedHash } from "./policy";
|
|
9
9
|
|
|
10
10
|
export interface FileRenameRequest {
|
|
@@ -112,9 +112,7 @@ export async function renameFilesSafely(requests: FileRenameBatch) {
|
|
|
112
112
|
throw new Error(
|
|
113
113
|
`file_rename source and destination must differ: ${inputPath}`,
|
|
114
114
|
);
|
|
115
|
-
if (
|
|
116
|
-
(await rootForPath(filePath)) !== (await rootForPath(destinationPath))
|
|
117
|
-
)
|
|
115
|
+
if (!(await pathsShareRoot(filePath, destinationPath)))
|
|
118
116
|
throw new Error(
|
|
119
117
|
`file_rename source and destination must share a root: ${inputPath}`,
|
|
120
118
|
);
|
package/src/runtime/paths.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { lstat, realpath } from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { currentConfig } from "../config";
|
|
4
5
|
|
|
@@ -13,7 +14,7 @@ function within(root: string, target: string): boolean {
|
|
|
13
14
|
);
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
async function
|
|
17
|
+
async function workspaceRoots(): Promise<string[]> {
|
|
17
18
|
const config = await currentConfig();
|
|
18
19
|
const roots = await Promise.all(
|
|
19
20
|
(await configuredRoots()).map(async (root) =>
|
|
@@ -35,29 +36,55 @@ async function allowedRoots(): Promise<string[]> {
|
|
|
35
36
|
return roots;
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
async function fileOperationRoots(): Promise<string[]> {
|
|
40
|
+
const roots = await workspaceRoots();
|
|
41
|
+
if (!(await currentConfig()).safety.allowTempDirectory) return roots;
|
|
42
|
+
const temporaryRoot = await realpath(os.tmpdir()).catch(() => os.tmpdir());
|
|
43
|
+
return roots.includes(temporaryRoot) ? roots : [...roots, temporaryRoot];
|
|
44
|
+
}
|
|
45
|
+
|
|
38
46
|
export async function primaryRoot(): Promise<string> {
|
|
39
|
-
return (await
|
|
47
|
+
return (await workspaceRoots())[0] as string;
|
|
40
48
|
}
|
|
41
49
|
|
|
42
|
-
export async function
|
|
43
|
-
|
|
50
|
+
export async function configuredRootForPath(
|
|
51
|
+
filePath: string,
|
|
52
|
+
): Promise<string | undefined> {
|
|
53
|
+
return (await fileOperationRoots()).find((candidate) =>
|
|
44
54
|
within(candidate, filePath),
|
|
45
55
|
);
|
|
46
|
-
if (!root) throw new Error(`Path is outside AST_MCP_ROOTS: ${filePath}`);
|
|
47
|
-
return root;
|
|
48
56
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const
|
|
57
|
+
|
|
58
|
+
export async function rootForPath(filePath: string): Promise<string> {
|
|
59
|
+
const root = await configuredRootForPath(filePath);
|
|
60
|
+
if (root) return root;
|
|
61
|
+
if ((await currentConfig()).safety.allowAnyPath)
|
|
62
|
+
return path.dirname(filePath);
|
|
63
|
+
throw new Error(
|
|
64
|
+
`Path is outside configured file-operation roots: ${filePath}`,
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function pathsShareRoot(
|
|
69
|
+
first: string,
|
|
70
|
+
second: string,
|
|
71
|
+
): Promise<boolean> {
|
|
72
|
+
if ((await currentConfig()).safety.allowAnyPath) return true;
|
|
73
|
+
return (await rootForPath(first)) === (await rootForPath(second));
|
|
74
|
+
}
|
|
75
|
+
async function canonicalCandidate(filePath: string, root: string) {
|
|
52
76
|
const absolute = path.isAbsolute(filePath)
|
|
53
77
|
? filePath
|
|
54
|
-
: path.resolve(
|
|
78
|
+
: path.resolve(root, filePath);
|
|
55
79
|
let existing = path.dirname(absolute);
|
|
56
80
|
const missing: string[] = [];
|
|
57
81
|
while (true) {
|
|
58
82
|
try {
|
|
59
|
-
|
|
60
|
-
|
|
83
|
+
return path.join(
|
|
84
|
+
await realpath(existing),
|
|
85
|
+
...missing,
|
|
86
|
+
path.basename(absolute),
|
|
87
|
+
);
|
|
61
88
|
} catch (error) {
|
|
62
89
|
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
63
90
|
const parent = path.dirname(existing);
|
|
@@ -66,22 +93,58 @@ export async function resolveWritablePath(filePath: string): Promise<string> {
|
|
|
66
93
|
existing = parent;
|
|
67
94
|
}
|
|
68
95
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function assertWithinBoundary(
|
|
99
|
+
target: string,
|
|
100
|
+
roots: string[],
|
|
101
|
+
allowAnyPath: boolean,
|
|
102
|
+
message: string,
|
|
103
|
+
) {
|
|
104
|
+
if (!allowAnyPath && !roots.some((root) => within(root, target)))
|
|
105
|
+
throw new Error(message);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function resolvePath(
|
|
109
|
+
filePath: string,
|
|
110
|
+
roots: string[],
|
|
111
|
+
allowAnyPath: boolean,
|
|
112
|
+
boundary: string,
|
|
113
|
+
): Promise<string> {
|
|
114
|
+
const resolved = await canonicalCandidate(filePath, roots[0] as string);
|
|
115
|
+
assertWithinBoundary(
|
|
116
|
+
resolved,
|
|
117
|
+
roots,
|
|
118
|
+
allowAnyPath,
|
|
119
|
+
`Path is outside ${boundary}: ${filePath}`,
|
|
120
|
+
);
|
|
74
121
|
const metadata = await lstat(resolved).catch(() => undefined);
|
|
75
122
|
if (!metadata?.isSymbolicLink()) return resolved;
|
|
76
|
-
if (!
|
|
123
|
+
if (!(await currentConfig()).safety.followSymlinks)
|
|
77
124
|
throw new Error(`Symbolic-link targets are not permitted: ${filePath}`);
|
|
78
125
|
const target = await realpath(resolved);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
126
|
+
assertWithinBoundary(
|
|
127
|
+
target,
|
|
128
|
+
roots,
|
|
129
|
+
allowAnyPath,
|
|
130
|
+
`Symbolic-link target is outside ${boundary}: ${filePath}`,
|
|
131
|
+
);
|
|
83
132
|
return target;
|
|
84
133
|
}
|
|
134
|
+
|
|
135
|
+
export async function resolveWritablePath(filePath: string): Promise<string> {
|
|
136
|
+
const config = await currentConfig();
|
|
137
|
+
return resolvePath(
|
|
138
|
+
filePath,
|
|
139
|
+
await fileOperationRoots(),
|
|
140
|
+
config.safety.allowAnyPath,
|
|
141
|
+
"configured file-operation roots; use the OS temporary directory, configure workspace.roots, or explicitly set safety.allow_any_path=true",
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export async function resolveWorkspacePath(filePath: string): Promise<string> {
|
|
146
|
+
return resolvePath(filePath, await workspaceRoots(), false, "AST_MCP_ROOTS");
|
|
147
|
+
}
|
|
85
148
|
export async function rootsForDisplay(): Promise<string[]> {
|
|
86
149
|
return configuredRoots();
|
|
87
150
|
}
|
package/src/tools/ast-bro.ts
CHANGED
|
@@ -14,7 +14,7 @@ import metadata from "../ast-bro/tools.json";
|
|
|
14
14
|
import { replaceFileAtomically } from "../runtime/atomic";
|
|
15
15
|
import { assertFormattable, formatFileAtomically } from "../runtime/format";
|
|
16
16
|
import { withFileLocks } from "../runtime/locks";
|
|
17
|
-
import { primaryRoot,
|
|
17
|
+
import { primaryRoot, resolveWorkspacePath } from "../runtime/paths";
|
|
18
18
|
import { type ConfiguredExecution, localExecution } from "./configured";
|
|
19
19
|
|
|
20
20
|
function upstreamSchema(
|
|
@@ -39,7 +39,7 @@ function upstreamSchema(
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
async function boundedPath(root: string, value: string): Promise<string> {
|
|
42
|
-
return
|
|
42
|
+
return resolveWorkspacePath(
|
|
43
43
|
path.isAbsolute(value) ? value : path.resolve(root, value),
|
|
44
44
|
);
|
|
45
45
|
}
|
|
@@ -147,7 +147,7 @@ export default function registerAstBroTools(
|
|
|
147
147
|
{
|
|
148
148
|
description:
|
|
149
149
|
toolName === "run"
|
|
150
|
-
? "AST structural search and rewrite. Use for bounded inspection and previews; direct write is a lower-level escape hatch for exceptional cases. Normal agent edits belong in
|
|
150
|
+
? "AST structural search and rewrite. Use for bounded inspection and previews; direct write is a lower-level escape hatch for exceptional cases. Normal agent edits belong in file_patch's declared files batch, which supports ordered AST rules and Aider blocks."
|
|
151
151
|
: definition.description,
|
|
152
152
|
inputSchema: upstreamSchema(definition.inputSchema),
|
|
153
153
|
title: `ast-bro ${toolName}`,
|
package/src/tools/files.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { McpServer } from "@modelcontextprotocol/server";
|
|
2
2
|
import * as z from "zod/v4";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
boundedFileBatch,
|
|
5
|
+
chattrSchema,
|
|
6
|
+
toolFailure,
|
|
7
|
+
} from "../helpers/mcp-schema";
|
|
4
8
|
import { patchFiles, writeFilesSafely } from "../patch/engine";
|
|
5
9
|
import {
|
|
6
10
|
FILE_READ_MAX_BATCH,
|
|
@@ -39,15 +43,6 @@ export default function registerFileTools(
|
|
|
39
43
|
content: z.string(),
|
|
40
44
|
expectedSha256: z.string().length(64).optional(),
|
|
41
45
|
});
|
|
42
|
-
const boundedBatch = <T extends z.ZodType>(schema: T, label: string) =>
|
|
43
|
-
z
|
|
44
|
-
.record(z.string().min(1), schema)
|
|
45
|
-
.refine(
|
|
46
|
-
(value) =>
|
|
47
|
-
Object.keys(value).length > 0 &&
|
|
48
|
-
Object.keys(value).length <= FILE_READ_MAX_BATCH,
|
|
49
|
-
label,
|
|
50
|
-
);
|
|
51
46
|
|
|
52
47
|
server.registerTool(
|
|
53
48
|
"file_read",
|
|
@@ -109,20 +104,20 @@ export default function registerFileTools(
|
|
|
109
104
|
"file_write",
|
|
110
105
|
{
|
|
111
106
|
description:
|
|
112
|
-
"Creates or replaces multiple files in one
|
|
113
|
-
inputSchema:
|
|
107
|
+
"Creates or replaces multiple files in one declared files batch. Existing files require a fresh expectedSha256 by default; safety.require_hash=false makes it optional, but any supplied hash is still verified.",
|
|
108
|
+
inputSchema: boundedFileBatch(
|
|
114
109
|
writeTarget,
|
|
115
110
|
"file_write requires between 1 and 50 files",
|
|
116
111
|
),
|
|
117
112
|
title: "Write Files Safely",
|
|
118
113
|
},
|
|
119
|
-
async (
|
|
114
|
+
async ({ files }) => {
|
|
120
115
|
try {
|
|
121
116
|
return {
|
|
122
117
|
content: [
|
|
123
118
|
{
|
|
124
119
|
text: JSON.stringify(
|
|
125
|
-
await execute(
|
|
120
|
+
await execute({ files }, () => writeFilesSafely(files)),
|
|
126
121
|
),
|
|
127
122
|
type: "text",
|
|
128
123
|
},
|
|
@@ -138,8 +133,8 @@ export default function registerFileTools(
|
|
|
138
133
|
"file_patch",
|
|
139
134
|
{
|
|
140
135
|
description:
|
|
141
|
-
"Patches multiple files in one
|
|
142
|
-
inputSchema:
|
|
136
|
+
"Patches multiple files in one declared files batch. Each value contains a patchStrategy, ordered aiderBlocks or astRules, and optional preview mode. A fresh expectedSha256 is required by default; safety.require_hash=false makes it optional, but supplied hashes remain enforced. Preview runs the complete formatted operation without committing.",
|
|
137
|
+
inputSchema: boundedFileBatch(
|
|
143
138
|
z.object({
|
|
144
139
|
aiderBlocks: z.array(aiderBlock).max(FILE_READ_MAX_BATCH).optional(),
|
|
145
140
|
astRules: z.array(astRule).max(FILE_READ_MAX_BATCH).optional(),
|
|
@@ -152,12 +147,14 @@ export default function registerFileTools(
|
|
|
152
147
|
),
|
|
153
148
|
title: "Patch Files Through the Enforced State Machine",
|
|
154
149
|
},
|
|
155
|
-
async (
|
|
150
|
+
async ({ files }) => {
|
|
156
151
|
try {
|
|
157
152
|
return {
|
|
158
153
|
content: [
|
|
159
154
|
{
|
|
160
|
-
text: JSON.stringify(
|
|
155
|
+
text: JSON.stringify(
|
|
156
|
+
await execute({ files }, () => patchFiles(files)),
|
|
157
|
+
),
|
|
161
158
|
type: "text",
|
|
162
159
|
},
|
|
163
160
|
],
|
package/src/tools/lifecycle.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { McpServer } from "@modelcontextprotocol/server";
|
|
2
2
|
import * as z from "zod/v4";
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
boundedFileBatch,
|
|
5
5
|
chattrSchema,
|
|
6
6
|
toolFailure,
|
|
7
7
|
} from "../helpers/mcp-schema";
|
|
@@ -25,8 +25,8 @@ export default function registerLifecycleTools(
|
|
|
25
25
|
"file_chattr",
|
|
26
26
|
{
|
|
27
27
|
description:
|
|
28
|
-
"Applies the shared chattr contract to multiple
|
|
29
|
-
inputSchema:
|
|
28
|
+
"Applies the shared chattr contract to multiple files in one declared files batch under deterministic locks.",
|
|
29
|
+
inputSchema: boundedFileBatch(
|
|
30
30
|
z.object({
|
|
31
31
|
chattr,
|
|
32
32
|
expectedSha256: z.string().length(64).optional(),
|
|
@@ -35,9 +35,9 @@ export default function registerLifecycleTools(
|
|
|
35
35
|
),
|
|
36
36
|
title: "Change File Attributes Safely",
|
|
37
37
|
},
|
|
38
|
-
async (requests) => {
|
|
38
|
+
async ({ files: requests }) => {
|
|
39
39
|
try {
|
|
40
|
-
const entries = await execute(requests, () =>
|
|
40
|
+
const entries = await execute({ files: requests }, () =>
|
|
41
41
|
Promise.all(
|
|
42
42
|
Object.entries(requests).map(async ([inputPath, request]) => ({
|
|
43
43
|
filePath: await resolveWritablePath(inputPath),
|
|
@@ -77,8 +77,8 @@ export default function registerLifecycleTools(
|
|
|
77
77
|
"file_delete",
|
|
78
78
|
{
|
|
79
79
|
description:
|
|
80
|
-
"Deletes files in one
|
|
81
|
-
inputSchema:
|
|
80
|
+
"Deletes files in one declared files batch after reference preflight and removes empty ancestor directories. A fresh expectedSha256 is required by default; safety.require_hash=false makes it optional, but supplied hashes remain enforced.",
|
|
81
|
+
inputSchema: boundedFileBatch(
|
|
82
82
|
z.object({
|
|
83
83
|
expectedSha256: z.string().length(64).optional(),
|
|
84
84
|
forceReferences: z.boolean().optional(),
|
|
@@ -87,13 +87,13 @@ export default function registerLifecycleTools(
|
|
|
87
87
|
),
|
|
88
88
|
title: "Delete Files Safely",
|
|
89
89
|
},
|
|
90
|
-
async (
|
|
90
|
+
async ({ files }) => {
|
|
91
91
|
try {
|
|
92
92
|
return {
|
|
93
93
|
content: [
|
|
94
94
|
{
|
|
95
95
|
text: JSON.stringify(
|
|
96
|
-
await execute(
|
|
96
|
+
await execute({ files }, () => deleteFilesSafely(files)),
|
|
97
97
|
),
|
|
98
98
|
type: "text",
|
|
99
99
|
},
|
|
@@ -108,8 +108,8 @@ export default function registerLifecycleTools(
|
|
|
108
108
|
"file_rename",
|
|
109
109
|
{
|
|
110
110
|
description:
|
|
111
|
-
"Renames files in one
|
|
112
|
-
inputSchema:
|
|
111
|
+
"Renames files in one declared files batch without overwriting destinations. A fresh expectedSha256 is required by default; safety.require_hash=false makes it optional, but supplied hashes remain enforced.",
|
|
112
|
+
inputSchema: boundedFileBatch(
|
|
113
113
|
z.object({
|
|
114
114
|
destination: z.string().min(1),
|
|
115
115
|
expectedSha256: z.string().length(64).optional(),
|
|
@@ -118,13 +118,13 @@ export default function registerLifecycleTools(
|
|
|
118
118
|
),
|
|
119
119
|
title: "Rename Files Safely",
|
|
120
120
|
},
|
|
121
|
-
async (
|
|
121
|
+
async ({ files }) => {
|
|
122
122
|
try {
|
|
123
123
|
return {
|
|
124
124
|
content: [
|
|
125
125
|
{
|
|
126
126
|
text: JSON.stringify(
|
|
127
|
-
await execute(
|
|
127
|
+
await execute({ files }, () => renameFilesSafely(files)),
|
|
128
128
|
),
|
|
129
129
|
type: "text",
|
|
130
130
|
},
|
package/templates/AGENTS.md
CHANGED
|
@@ -9,7 +9,7 @@ CRITICAL INSTRUCTION: You are operating in an AST-isolated environment.
|
|
|
9
9
|
- Use `file_read` only for bounded slices of non-AST content, and batch multiple files in one call.
|
|
10
10
|
- Use `file_hash` for fresh whole-file SHA-256 values without retrieving content.
|
|
11
11
|
- For new files, use only `file_write`.
|
|
12
|
-
- For existing files, call `file_hash` immediately before a guarded `file_patch`;
|
|
12
|
+
- For existing files, call `file_hash` immediately before a guarded `file_patch`; mutation tools declare a `files` property containing the path-keyed batch.
|
|
13
13
|
- Parseable rewrite-supported files use `file_patch` with `patchStrategy: "ast"` and ordered `astRules`; unsupported, unparseable, or inspection-only formats use `patchStrategy: "aider_block"` and ordered `aiderBlocks`.
|
|
14
14
|
|
|
15
15
|
## Available ast-mcp tools
|
|
@@ -18,7 +18,7 @@ File boundary: `file_hash`, `file_read`, `file_write`, `file_patch`, `file_chatt
|
|
|
18
18
|
|
|
19
19
|
Code intelligence: `digest`, `map`, `show`, `search`, `find_related`, `surface`, `deps`, `reverse_deps`, `cycles`, `graph`, `callers`, `callees`, `trace`, `impact`, `context`, `implements`, `index`, `run`, `squeeze`.
|
|
20
20
|
|
|
21
|
-
Call every intelligence tool directly by name. There is no proxy tool. Use `run` for bounded AST searches and previews. Direct `run` rewrites with `write: true` are a lower-level escape hatch for intentionally bounded cases; they remain first-match-per-file and are not the normal agent patch route. All
|
|
21
|
+
Call every intelligence tool directly by name. There is no proxy tool. Use `run` for bounded AST searches and previews. Direct `run` rewrites with `write: true` are a lower-level escape hatch for intentionally bounded cases; they remain first-match-per-file and are not the normal agent patch route. All mutation tools accept a declared `files` object, are file-operation-root bounded, SHA-guarded where required, and atomically committed per keyed path. The OS temporary directory is allowed by default; `safety.allow_temp_directory = false` disables it, while `safety.allow_any_path = true` explicitly enables unrestricted file paths. `file_write` and `file_patch` share the `file_chattr` contract rather than independent chmod/chown keys; `file_delete` is the only directory cleanup capability and only removes empty ancestors after a successful file deletion.
|
|
22
22
|
|
|
23
23
|
## Forbidden mutation paths
|
|
24
24
|
|
|
@@ -35,11 +35,11 @@ Use ast-mcp intelligence tools as the primary repository search surface: `digest
|
|
|
35
35
|
1. Explore AST-capable content with the smallest direct intelligence call; use `impact` before shared API changes. Use batched, bounded `file_read` slices only for non-AST content.
|
|
36
36
|
2. Preview structural matches with `run({ pattern, paths, lang?, json: true })`, bounded to explicit paths. Use `file_patch` with `preview: true` when you need the full guarded and formatted dry-run contract.
|
|
37
37
|
3. Call `file_hash({ filePaths })` immediately before a SHA-guarded patch.
|
|
38
|
-
4. Call one
|
|
38
|
+
4. Call one `file_patch({ files: { ... } })` batch with one fresh hash and ordered operations per path:
|
|
39
39
|
- AST targets: `{ expectedSha256, patchStrategy: "ast", astRules: [...] }`
|
|
40
40
|
- Unsupported targets: `{ expectedSha256, patchStrategy: "aider_block", aiderBlocks: [...] }`
|
|
41
41
|
Each keyed path is locked and atomically committed once; preview every AST rule before the batch.
|
|
42
|
-
5. Use one
|
|
42
|
+
5. Use one `file_write({ files: { ... } })` batch for new files or SHA-guarded replacement of existing non-structurally-rewritable files.
|
|
43
43
|
6. Use direct `run` with `rewrite` and `write: true` only when an intentionally bounded lower-level rewrite is required; do not use it instead of `file_patch` for normal agent edits.
|
|
44
44
|
7. Verify keyed results with `show`, `map`, `run`, or bounded `file_read` slices, then run repository validation and review the final diff without mutating through Git.
|
|
45
45
|
|
|
@@ -49,7 +49,7 @@ A stale hash, ambiguous Aider block, unexpected match count, capped run preview,
|
|
|
49
49
|
|
|
50
50
|
A JSON-RPC transport batch may contain requests and notifications. Stdio emits one framed response per request; live streamable HTTP uses SSE by default and emits one event per request. Notifications never receive responses. Preserve every request ID and do not assume the live HTTP response is a JSON array unless `enableJsonResponse` is configured.
|
|
51
51
|
|
|
52
|
-
`evals:measure` inventories direct MCP records and statically visible `tools.mcp__ast_mcp__*` calls inside top-level Codex `exec` source. Put exactly one `ast-mcp-eval:<id>` marker in the user evaluation prompt, or in a direct record input supplied by an evaluation harness, to associate following direct MCP records with that case. Marked nested `exec` evidence and multi-marker evidence fail closed because an outer result cannot prove each nested call. Scoring requires schema-relevant inputs, workspace-root compliance from transcript context, required sequencing, expected output evidence, fixture assertions, and a successful output bound to each direct call.
|
|
52
|
+
`evals:measure` inventories direct MCP records and statically visible `tools.mcp__ast_mcp__*` calls inside top-level Codex `exec` source. Put exactly one `ast-mcp-eval:<id>` marker in the user evaluation prompt, or in a direct record input supplied by an evaluation harness, to associate following direct MCP records with that case. Marked nested `exec` evidence and multi-marker evidence fail closed because an outer result cannot prove each nested call. Scoring requires schema-relevant inputs, workspace-root compliance from transcript context, required sequencing, expected output evidence, fixture assertions, and a successful output bound to each direct call. Pass `--allow-any-path` and/or `--no-temp-directory` when the measured run used non-default file safety; scorer options are validated rather than inferred from layered project configuration.
|
|
53
53
|
|
|
54
54
|
## Missing MCP
|
|
55
55
|
|