@mandujs/mcp 0.24.0 → 0.27.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.
- package/package.json +4 -4
- package/src/tools/ate-boundary-probe.ts +109 -0
- package/src/tools/ate-context.ts +173 -96
- package/src/tools/ate-coverage.ts +71 -0
- package/src/tools/ate-mutate.ts +103 -0
- package/src/tools/ate-mutation-report.ts +64 -0
- package/src/tools/ate-oracle-pending.ts +49 -0
- package/src/tools/ate-oracle-replay.ts +44 -0
- package/src/tools/ate-oracle-verdict.ts +70 -0
- package/src/tools/ate-recall.ts +85 -0
- package/src/tools/ate-remember.ts +79 -0
- package/src/tools/ate-save.ts +160 -139
- package/src/tools/ate.ts +34 -7
- package/src/tools/index.ts +82 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mandujs/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "Mandu MCP Server - Agent-native interface for Mandu framework operations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@mandujs/core": "^0.
|
|
38
|
-
"@mandujs/ate": "^0.
|
|
39
|
-
"@mandujs/skills": "^
|
|
37
|
+
"@mandujs/core": "^0.39.0",
|
|
38
|
+
"@mandujs/ate": "^0.24.0",
|
|
39
|
+
"@mandujs/skills": "^17.0.0",
|
|
40
40
|
"@modelcontextprotocol/sdk": "^1.25.3"
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `mandu_ate_boundary_probe` — Phase B.1 deterministic boundary-value
|
|
3
|
+
* generator for Zod contracts.
|
|
4
|
+
*
|
|
5
|
+
* See docs/ate/phase-b-spec.md §B.1 for the full I/O shape. Agents
|
|
6
|
+
* feed the returned probe set into `mandu_ate_prompt({ kind:
|
|
7
|
+
* "property_based" })` to produce adversarial specs.
|
|
8
|
+
*
|
|
9
|
+
* Snake_case tool name (§11 decision #4). Read-only.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
13
|
+
import { generateBoundaryProbes } from "@mandujs/ate";
|
|
14
|
+
|
|
15
|
+
export const ateBoundaryProbeToolDefinitions: Tool[] = [
|
|
16
|
+
{
|
|
17
|
+
name: "mandu_ate_boundary_probe",
|
|
18
|
+
annotations: {
|
|
19
|
+
readOnlyHint: true,
|
|
20
|
+
},
|
|
21
|
+
description:
|
|
22
|
+
"Phase B.1 deterministic boundary probe for Zod contracts. Reads a " +
|
|
23
|
+
"*.contract.ts file, parses request-body schemas per HTTP method, and " +
|
|
24
|
+
"returns a deterministic set of probe values per field — one per " +
|
|
25
|
+
"category (valid / invalid_format / boundary_min / boundary_max / " +
|
|
26
|
+
"empty / null / type_mismatch / enum_reject / missing_required). " +
|
|
27
|
+
"Every probe also carries the expectedStatus code derived from the " +
|
|
28
|
+
"contract's response map (400/422 for invalid, 200/201 for valid). " +
|
|
29
|
+
"The output is stamped with graphVersion for agent cache " +
|
|
30
|
+
"invalidation. No LLM. No runtime Zod evaluation — source text is " +
|
|
31
|
+
"parsed directly. Default depth 1, max 3.",
|
|
32
|
+
inputSchema: {
|
|
33
|
+
type: "object",
|
|
34
|
+
properties: {
|
|
35
|
+
repoRoot: {
|
|
36
|
+
type: "string",
|
|
37
|
+
description: "Absolute path to the Mandu project root.",
|
|
38
|
+
},
|
|
39
|
+
contractName: {
|
|
40
|
+
type: "string",
|
|
41
|
+
description:
|
|
42
|
+
"Contract identifier. Usually the basename of the contract file (e.g. 'SignupContract' or 'api-signup').",
|
|
43
|
+
},
|
|
44
|
+
contractFile: {
|
|
45
|
+
type: "string",
|
|
46
|
+
description: "Direct absolute path to the contract file (bypasses name resolution).",
|
|
47
|
+
},
|
|
48
|
+
method: {
|
|
49
|
+
type: "string",
|
|
50
|
+
enum: ["GET", "POST", "PUT", "PATCH", "DELETE"],
|
|
51
|
+
description: "Optional HTTP method filter. Omit to probe every declared method.",
|
|
52
|
+
},
|
|
53
|
+
depth: {
|
|
54
|
+
type: "number",
|
|
55
|
+
description: "Recursion depth for nested z.object() fields. Default 1, max 3.",
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
required: ["repoRoot"],
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
export function ateBoundaryProbeTools(_projectRoot: string) {
|
|
64
|
+
return {
|
|
65
|
+
mandu_ate_boundary_probe: async (args: Record<string, unknown>) => {
|
|
66
|
+
const repoRoot = args.repoRoot as string | undefined;
|
|
67
|
+
const contractName = args.contractName as string | undefined;
|
|
68
|
+
const contractFile = args.contractFile as string | undefined;
|
|
69
|
+
const method = args.method as
|
|
70
|
+
| "GET"
|
|
71
|
+
| "POST"
|
|
72
|
+
| "PUT"
|
|
73
|
+
| "PATCH"
|
|
74
|
+
| "DELETE"
|
|
75
|
+
| undefined;
|
|
76
|
+
const depth = typeof args.depth === "number" ? args.depth : undefined;
|
|
77
|
+
|
|
78
|
+
if (!repoRoot || typeof repoRoot !== "string") {
|
|
79
|
+
return { ok: false, error: "repoRoot is required" };
|
|
80
|
+
}
|
|
81
|
+
if (!contractName && !contractFile) {
|
|
82
|
+
return { ok: false, error: "contractName or contractFile is required" };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
const result = await generateBoundaryProbes({
|
|
87
|
+
repoRoot,
|
|
88
|
+
contractName,
|
|
89
|
+
contractFile,
|
|
90
|
+
...(method ? { method } : {}),
|
|
91
|
+
...(depth !== undefined ? { depth } : {}),
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
ok: true,
|
|
95
|
+
contractName: result.contractName,
|
|
96
|
+
contractFile: result.contractFile,
|
|
97
|
+
graphVersion: result.graphVersion,
|
|
98
|
+
probes: result.probes,
|
|
99
|
+
warnings: result.warnings,
|
|
100
|
+
};
|
|
101
|
+
} catch (err) {
|
|
102
|
+
return {
|
|
103
|
+
ok: false,
|
|
104
|
+
error: err instanceof Error ? err.message : String(err),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
package/src/tools/ate-context.ts
CHANGED
|
@@ -1,96 +1,173 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `mandu_ate_context` — Phase A.1 agent-native context tool.
|
|
3
|
-
*
|
|
4
|
-
* See `docs/ate/roadmap-v2-agent-native.md` §4.1 for the full design
|
|
5
|
-
* and §11 decision 4 for the naming convention (snake_case).
|
|
6
|
-
*
|
|
7
|
-
* Semantics: return a single JSON blob that an LLM-driven agent
|
|
8
|
-
* (Cursor / Claude Code / Codex) can read *before* generating a test.
|
|
9
|
-
* The blob fuses:
|
|
10
|
-
*
|
|
11
|
-
* 1. Route metadata (pattern, file, isRedirect, static params)
|
|
12
|
-
* 2. Contract surface (request/response schemas + examples)
|
|
13
|
-
* 3. Middleware chain (canonical name + options + file)
|
|
14
|
-
* 4. Guard preset + suggested data-route-id selectors
|
|
15
|
-
* 5. Fixture recommendations (createTestSession, createTestDb, ...)
|
|
16
|
-
* 6. Existing specs (user-written vs ate-generated, last-run status)
|
|
17
|
-
* 7. Related routes (siblings + ui-entry-point pairing)
|
|
18
|
-
*
|
|
19
|
-
* The handler itself is deliberately thin — almost all work is done
|
|
20
|
-
* inside `@mandujs/ate`'s `buildContext` so the same logic is
|
|
21
|
-
* importable from non-MCP callers (CLI, tests).
|
|
22
|
-
*/
|
|
23
|
-
import type { Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
type: "string",
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* `mandu_ate_context` — Phase A.1 agent-native context tool.
|
|
3
|
+
*
|
|
4
|
+
* See `docs/ate/roadmap-v2-agent-native.md` §4.1 for the full design
|
|
5
|
+
* and §11 decision 4 for the naming convention (snake_case).
|
|
6
|
+
*
|
|
7
|
+
* Semantics: return a single JSON blob that an LLM-driven agent
|
|
8
|
+
* (Cursor / Claude Code / Codex) can read *before* generating a test.
|
|
9
|
+
* The blob fuses:
|
|
10
|
+
*
|
|
11
|
+
* 1. Route metadata (pattern, file, isRedirect, static params)
|
|
12
|
+
* 2. Contract surface (request/response schemas + examples)
|
|
13
|
+
* 3. Middleware chain (canonical name + options + file)
|
|
14
|
+
* 4. Guard preset + suggested data-route-id selectors
|
|
15
|
+
* 5. Fixture recommendations (createTestSession, createTestDb, ...)
|
|
16
|
+
* 6. Existing specs (user-written vs ate-generated, last-run status)
|
|
17
|
+
* 7. Related routes (siblings + ui-entry-point pairing)
|
|
18
|
+
*
|
|
19
|
+
* The handler itself is deliberately thin — almost all work is done
|
|
20
|
+
* inside `@mandujs/ate`'s `buildContext` so the same logic is
|
|
21
|
+
* importable from non-MCP callers (CLI, tests).
|
|
22
|
+
*/
|
|
23
|
+
import type { Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
24
|
+
import {
|
|
25
|
+
ateContext,
|
|
26
|
+
appendMemoryEvent,
|
|
27
|
+
nowTimestamp,
|
|
28
|
+
readMemoryEvents,
|
|
29
|
+
buildRpcContext,
|
|
30
|
+
} from "@mandujs/ate";
|
|
31
|
+
|
|
32
|
+
export const ateContextToolDefinitions: Tool[] = [
|
|
33
|
+
{
|
|
34
|
+
name: "mandu_ate_context",
|
|
35
|
+
annotations: {
|
|
36
|
+
readOnlyHint: true,
|
|
37
|
+
},
|
|
38
|
+
description:
|
|
39
|
+
"Phase A.1 agent-native context. Returns a single JSON blob containing the " +
|
|
40
|
+
"Mandu-specific semantic context an LLM needs to write a correct test: " +
|
|
41
|
+
"route metadata, contract (with examples), middleware chain, guard preset + " +
|
|
42
|
+
"suggested [data-route-id] selectors, recommended @mandujs/core/testing fixtures, " +
|
|
43
|
+
"existing specs (with last-run status when .mandu/ate-last-run.json is present), " +
|
|
44
|
+
"and related routes (sibling + ui-entry-point pairing). " +
|
|
45
|
+
"Scope values: " +
|
|
46
|
+
"'project' = repo summary with route + coverage counts; " +
|
|
47
|
+
"'route' = single-route deep view (requires id or route); " +
|
|
48
|
+
"'filling' = server-handler view with middleware + actions (requires id); " +
|
|
49
|
+
"'contract' = request/response + examples for a contract definition. " +
|
|
50
|
+
"Run mandu.ate.extract first — this tool reads .mandu/interaction-graph.json.",
|
|
51
|
+
inputSchema: {
|
|
52
|
+
type: "object",
|
|
53
|
+
properties: {
|
|
54
|
+
repoRoot: {
|
|
55
|
+
type: "string",
|
|
56
|
+
description: "Absolute path to the Mandu project root",
|
|
57
|
+
},
|
|
58
|
+
scope: {
|
|
59
|
+
type: "string",
|
|
60
|
+
enum: ["project", "route", "filling", "contract", "rpc"],
|
|
61
|
+
description:
|
|
62
|
+
"project (summary) | route (single route deep view) | filling (handler view) | contract (contract definition view) | rpc (typed RPC procedure view — Phase C.3)",
|
|
63
|
+
},
|
|
64
|
+
id: {
|
|
65
|
+
type: "string",
|
|
66
|
+
description:
|
|
67
|
+
"Route id ('api-signup'), filling id ('filling:api-signup'), or contract name. Optional — supply id OR route.",
|
|
68
|
+
},
|
|
69
|
+
route: {
|
|
70
|
+
type: "string",
|
|
71
|
+
description:
|
|
72
|
+
"Route pattern match (e.g. '/api/signup'). Optional — supply id OR route.",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
required: ["repoRoot", "scope"],
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
export function ateContextTools(_projectRoot: string) {
|
|
81
|
+
return {
|
|
82
|
+
mandu_ate_context: async (args: Record<string, unknown>) => {
|
|
83
|
+
const { repoRoot, scope, id, route } = args as {
|
|
84
|
+
repoRoot: string;
|
|
85
|
+
scope: "project" | "route" | "filling" | "contract" | "rpc";
|
|
86
|
+
id?: string;
|
|
87
|
+
route?: string;
|
|
88
|
+
};
|
|
89
|
+
// Minimal validation — the MCP SDK already enforces the schema,
|
|
90
|
+
// but we guard repoRoot explicitly so mis-invocations surface a
|
|
91
|
+
// loud error rather than a cascading filesystem failure.
|
|
92
|
+
if (!repoRoot || typeof repoRoot !== "string") {
|
|
93
|
+
return { ok: false, error: "repoRoot is required" };
|
|
94
|
+
}
|
|
95
|
+
if (!scope) {
|
|
96
|
+
return { ok: false, error: "scope is required" };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Phase C.3 — `scope: "rpc"` delegates to the RPC extractor + context builder.
|
|
100
|
+
if (scope === "rpc") {
|
|
101
|
+
if (!id) {
|
|
102
|
+
return {
|
|
103
|
+
ok: false,
|
|
104
|
+
error: "scope='rpc' requires `id` (e.g. 'users.signup' or 'signup')",
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const blob = await buildRpcContext({ repoRoot, id });
|
|
108
|
+
return { ok: true, context: blob };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const blob = await ateContext({ repoRoot, scope, id, route });
|
|
112
|
+
|
|
113
|
+
// Phase B.2 — first `mandu_ate_context` call of the day writes a
|
|
114
|
+
// `coverage_snapshot` event (best-effort). The snapshot is derived
|
|
115
|
+
// from the `project`-scope blob summary; for other scopes we still
|
|
116
|
+
// fire the snapshot (using scope==='project' would require an
|
|
117
|
+
// extra call — the project summary's field presence is enough).
|
|
118
|
+
try {
|
|
119
|
+
if (!snapshottedToday(repoRoot)) {
|
|
120
|
+
const withSpec = countWithSpec(blob);
|
|
121
|
+
const withProperty = 0; // Phase B — property-test detection is part of `mandu_ate_coverage`.
|
|
122
|
+
const totalRoutes = countTotalRoutes(blob);
|
|
123
|
+
appendMemoryEvent(repoRoot, {
|
|
124
|
+
kind: "coverage_snapshot",
|
|
125
|
+
timestamp: nowTimestamp(),
|
|
126
|
+
routes: totalRoutes,
|
|
127
|
+
withSpec,
|
|
128
|
+
withProperty,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
} catch {
|
|
132
|
+
// swallow — snapshot is best-effort.
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return { ok: true, context: blob };
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function snapshottedToday(repoRoot: string): boolean {
|
|
141
|
+
try {
|
|
142
|
+
const events = readMemoryEvents(repoRoot);
|
|
143
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
144
|
+
return events.some(
|
|
145
|
+
(e) => e.kind === "coverage_snapshot" && e.timestamp.slice(0, 10) === today,
|
|
146
|
+
);
|
|
147
|
+
} catch {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function countTotalRoutes(blob: unknown): number {
|
|
153
|
+
if (!blob || typeof blob !== "object") return 0;
|
|
154
|
+
const b = blob as { scope?: string; summary?: { routes?: number }; route?: unknown };
|
|
155
|
+
if (b.scope === "project" && b.summary && typeof b.summary.routes === "number") {
|
|
156
|
+
return b.summary.routes;
|
|
157
|
+
}
|
|
158
|
+
// Non-project scope — we can't meaningfully count; leave 0 so the snapshot
|
|
159
|
+
// still records the timestamp without lying about totals.
|
|
160
|
+
return 0;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function countWithSpec(blob: unknown): number {
|
|
164
|
+
if (!blob || typeof blob !== "object") return 0;
|
|
165
|
+
const b = blob as {
|
|
166
|
+
scope?: string;
|
|
167
|
+
routes?: Array<{ existingSpecCount: number }>;
|
|
168
|
+
};
|
|
169
|
+
if (b.scope === "project" && Array.isArray(b.routes)) {
|
|
170
|
+
return b.routes.filter((r) => (r.existingSpecCount ?? 0) > 0).length;
|
|
171
|
+
}
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `mandu_ate_coverage` — Phase B.4 quantified gap report.
|
|
3
|
+
*
|
|
4
|
+
* See docs/ate/phase-b-spec.md §B.5 for the output shape. Agents call
|
|
5
|
+
* this to discover `topGaps` and prioritize spec generation work.
|
|
6
|
+
*
|
|
7
|
+
* Snake_case (§11 decision #4). Read-only.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
11
|
+
import { computeCoverage } from "@mandujs/ate";
|
|
12
|
+
|
|
13
|
+
export const ateCoverageToolDefinitions: Tool[] = [
|
|
14
|
+
{
|
|
15
|
+
name: "mandu_ate_coverage",
|
|
16
|
+
annotations: {
|
|
17
|
+
readOnlyHint: true,
|
|
18
|
+
},
|
|
19
|
+
description:
|
|
20
|
+
"Phase B.4 coverage metrics. Returns the 3-axis coverage report: " +
|
|
21
|
+
"(1) routes with unit / integration / e2e spec; (2) contracts with " +
|
|
22
|
+
"full / partial / no boundary-probe coverage; (3) middleware " +
|
|
23
|
+
"invariants (csrf / rate-limit / session / auth / i18n) tagged as " +
|
|
24
|
+
"covered / partial / missing. Also returns a `topGaps` list sorted " +
|
|
25
|
+
"high → medium → low severity. Stamped with graphVersion for " +
|
|
26
|
+
"agent cache invalidation.",
|
|
27
|
+
inputSchema: {
|
|
28
|
+
type: "object",
|
|
29
|
+
properties: {
|
|
30
|
+
repoRoot: {
|
|
31
|
+
type: "string",
|
|
32
|
+
description: "Absolute path to the Mandu project root.",
|
|
33
|
+
},
|
|
34
|
+
scope: {
|
|
35
|
+
type: "string",
|
|
36
|
+
enum: ["project", "route", "contract"],
|
|
37
|
+
description:
|
|
38
|
+
"Default 'project'. Use 'route' (with target=routeId) or 'contract' (with target=contractName) for narrow scans.",
|
|
39
|
+
},
|
|
40
|
+
target: {
|
|
41
|
+
type: "string",
|
|
42
|
+
description: "Route id or contract basename when scope is not 'project'.",
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
required: ["repoRoot"],
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
export function ateCoverageTools(_projectRoot: string) {
|
|
51
|
+
return {
|
|
52
|
+
mandu_ate_coverage: async (args: Record<string, unknown>) => {
|
|
53
|
+
const repoRoot = args.repoRoot as string | undefined;
|
|
54
|
+
if (!repoRoot || typeof repoRoot !== "string") {
|
|
55
|
+
return { ok: false, error: "repoRoot is required" };
|
|
56
|
+
}
|
|
57
|
+
const scope = args.scope as "project" | "route" | "contract" | undefined;
|
|
58
|
+
const target = typeof args.target === "string" ? args.target : undefined;
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const metrics = await computeCoverage(repoRoot, {
|
|
62
|
+
scope: scope ?? "project",
|
|
63
|
+
...(target ? { target } : {}),
|
|
64
|
+
});
|
|
65
|
+
return { ok: true, ...metrics };
|
|
66
|
+
} catch (err) {
|
|
67
|
+
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `mandu_ate_mutate` — Phase C.2 contract-semantic mutation runner.
|
|
3
|
+
*
|
|
4
|
+
* Runs up to 9 mutation operators on a single target file and executes
|
|
5
|
+
* the repo's test command against each mutation. Classifies results as
|
|
6
|
+
* killed / survived / timeout / error and persists
|
|
7
|
+
* `.mandu/ate-mutations/last-run.json` for `mandu_ate_mutation_report`.
|
|
8
|
+
*
|
|
9
|
+
* Spec: docs/ate/phase-c-spec.md §C.2.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
13
|
+
import { runMutations } from "@mandujs/ate";
|
|
14
|
+
|
|
15
|
+
export const ateMutateToolDefinitions: Tool[] = [
|
|
16
|
+
{
|
|
17
|
+
name: "mandu_ate_mutate",
|
|
18
|
+
annotations: {
|
|
19
|
+
readOnlyHint: false,
|
|
20
|
+
},
|
|
21
|
+
description:
|
|
22
|
+
"Phase C.2 — run contract-semantic mutation testing on a target file. " +
|
|
23
|
+
"9 operators: remove_required_field, narrow_type, widen_enum, flip_nullable, " +
|
|
24
|
+
"rename_field, swap_sibling_type, skip_middleware, early_return, bypass_validation. " +
|
|
25
|
+
"Each mutation is written to the target file, the repo's test command runs " +
|
|
26
|
+
"against it, and the result is classified killed / survived / timeout / error. " +
|
|
27
|
+
"Default cap 50 mutations per invocation; pass `--all` or maxMutations to lift. " +
|
|
28
|
+
"The original file is always restored. Persists .mandu/ate-mutations/last-run.json.",
|
|
29
|
+
inputSchema: {
|
|
30
|
+
type: "object",
|
|
31
|
+
properties: {
|
|
32
|
+
repoRoot: {
|
|
33
|
+
type: "string",
|
|
34
|
+
description: "Absolute path to the Mandu project root.",
|
|
35
|
+
},
|
|
36
|
+
targetFile: {
|
|
37
|
+
type: "string",
|
|
38
|
+
description:
|
|
39
|
+
"Absolute or repo-relative path to the file to mutate (contract, handler, or filling).",
|
|
40
|
+
},
|
|
41
|
+
testCommand: {
|
|
42
|
+
type: "array",
|
|
43
|
+
items: { type: "string" },
|
|
44
|
+
description:
|
|
45
|
+
"Optional override for the test command (argv form). Default: resolved from spec-indexer.",
|
|
46
|
+
},
|
|
47
|
+
timeoutMs: {
|
|
48
|
+
type: "number",
|
|
49
|
+
description: "Per-mutation timeout in ms. Default 120000.",
|
|
50
|
+
},
|
|
51
|
+
maxMutations: {
|
|
52
|
+
type: "number",
|
|
53
|
+
description: "Cap on the number of mutations executed. Default 50.",
|
|
54
|
+
},
|
|
55
|
+
operators: {
|
|
56
|
+
type: "array",
|
|
57
|
+
items: { type: "string" },
|
|
58
|
+
description:
|
|
59
|
+
"Optional subset of operator names. Default = all 9. Pass [] to skip execution.",
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
required: ["repoRoot", "targetFile"],
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
export function ateMutateTools(_projectRoot: string) {
|
|
68
|
+
return {
|
|
69
|
+
mandu_ate_mutate: async (args: Record<string, unknown>) => {
|
|
70
|
+
const repoRoot = args.repoRoot as string | undefined;
|
|
71
|
+
const targetFile = args.targetFile as string | undefined;
|
|
72
|
+
if (!repoRoot || typeof repoRoot !== "string") {
|
|
73
|
+
return { ok: false, error: "repoRoot is required" };
|
|
74
|
+
}
|
|
75
|
+
if (!targetFile || typeof targetFile !== "string") {
|
|
76
|
+
return { ok: false, error: "targetFile is required" };
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const result = await runMutations({
|
|
80
|
+
repoRoot,
|
|
81
|
+
targetFile,
|
|
82
|
+
...(Array.isArray(args.testCommand) ? { testCommand: args.testCommand as string[] } : {}),
|
|
83
|
+
...(typeof args.timeoutMs === "number" ? { timeoutMs: args.timeoutMs } : {}),
|
|
84
|
+
...(typeof args.maxMutations === "number" ? { maxMutations: args.maxMutations } : {}),
|
|
85
|
+
...(Array.isArray(args.operators) ? { operators: args.operators as never } : {}),
|
|
86
|
+
});
|
|
87
|
+
return {
|
|
88
|
+
ok: true,
|
|
89
|
+
targetFile: result.targetFile,
|
|
90
|
+
totalGenerated: result.totalGenerated,
|
|
91
|
+
totalExecuted: result.totalExecuted,
|
|
92
|
+
reportPath: result.reportPath,
|
|
93
|
+
results: result.results,
|
|
94
|
+
};
|
|
95
|
+
} catch (err) {
|
|
96
|
+
return {
|
|
97
|
+
ok: false,
|
|
98
|
+
error: err instanceof Error ? err.message : String(err),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `mandu_ate_mutation_report` — Phase C.2.
|
|
3
|
+
*
|
|
4
|
+
* Read the persisted last mutation run and compute an aggregate report:
|
|
5
|
+
* killed / survived / timeout counts, mutationScore, survivors ranked by
|
|
6
|
+
* severity + reason.
|
|
7
|
+
*
|
|
8
|
+
* Read-only. Never spawns a child process.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
12
|
+
import { computeMutationReport, loadLastMutationRun } from "@mandujs/ate";
|
|
13
|
+
|
|
14
|
+
export const ateMutationReportToolDefinitions: Tool[] = [
|
|
15
|
+
{
|
|
16
|
+
name: "mandu_ate_mutation_report",
|
|
17
|
+
annotations: {
|
|
18
|
+
readOnlyHint: true,
|
|
19
|
+
},
|
|
20
|
+
description:
|
|
21
|
+
"Phase C.2 — aggregate the last `mandu_ate_mutate` run into a summary report. " +
|
|
22
|
+
"Returns { totalMutations, killed, survived, timeout, mutationScore, " +
|
|
23
|
+
"survivorsBySeverity, byOperator }. Severity: skip_middleware + " +
|
|
24
|
+
"bypass_validation = high; narrow_type / swap_sibling_type / rename_field = " +
|
|
25
|
+
"medium; everything else = low.",
|
|
26
|
+
inputSchema: {
|
|
27
|
+
type: "object",
|
|
28
|
+
properties: {
|
|
29
|
+
repoRoot: {
|
|
30
|
+
type: "string",
|
|
31
|
+
description: "Absolute path to the Mandu project root.",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
required: ["repoRoot"],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
export function ateMutationReportTools(_projectRoot: string) {
|
|
40
|
+
return {
|
|
41
|
+
mandu_ate_mutation_report: async (args: Record<string, unknown>) => {
|
|
42
|
+
const repoRoot = args.repoRoot as string | undefined;
|
|
43
|
+
if (!repoRoot || typeof repoRoot !== "string") {
|
|
44
|
+
return { ok: false, error: "repoRoot is required" };
|
|
45
|
+
}
|
|
46
|
+
const loaded = loadLastMutationRun(repoRoot);
|
|
47
|
+
if (!loaded) {
|
|
48
|
+
return {
|
|
49
|
+
ok: false,
|
|
50
|
+
error:
|
|
51
|
+
"No mutation run found. Run mandu_ate_mutate first — the persisted report lives at .mandu/ate-mutations/last-run.json.",
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const report = computeMutationReport(loaded.results);
|
|
55
|
+
return {
|
|
56
|
+
ok: true,
|
|
57
|
+
targetFile: loaded.targetFile,
|
|
58
|
+
generatedAt: loaded.generatedAt,
|
|
59
|
+
totalGenerated: loaded.totalGenerated,
|
|
60
|
+
report,
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|