@mandujs/mcp 0.31.0 → 0.32.1
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 +3 -3
- package/src/tools/index.ts +4 -0
- package/src/tools/lint.ts +226 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mandujs/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.1",
|
|
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.
|
|
37
|
+
"@mandujs/core": "^0.44.0",
|
|
38
38
|
"@mandujs/ate": "^0.25.1",
|
|
39
|
-
"@mandujs/skills": "^0.
|
|
39
|
+
"@mandujs/skills": "^0.19.0",
|
|
40
40
|
"@modelcontextprotocol/sdk": "^1.25.3"
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|
package/src/tools/index.ts
CHANGED
|
@@ -67,6 +67,8 @@ export { aiBriefTools, aiBriefToolDefinitions } from "./ai-brief.js";
|
|
|
67
67
|
export { loopCloseTools, loopCloseToolDefinitions } from "./loop-close.js";
|
|
68
68
|
// #243 — docs search/get for agents grounding answers in real framework docs
|
|
69
69
|
export { docsTools, docsToolDefinitions } from "./docs.js";
|
|
70
|
+
// #240 guardrail-default — lint run + setup for existing projects
|
|
71
|
+
export { lintTools, lintToolDefinitions } from "./lint.js";
|
|
70
72
|
// Phase 18.ι — AI refactor MCP tools
|
|
71
73
|
export {
|
|
72
74
|
rewriteGeneratedBarrelTools,
|
|
@@ -138,6 +140,7 @@ import { deployPreviewTools, deployPreviewToolDefinitions } from "./deploy-previ
|
|
|
138
140
|
import { aiBriefTools, aiBriefToolDefinitions } from "./ai-brief.js";
|
|
139
141
|
import { loopCloseTools, loopCloseToolDefinitions } from "./loop-close.js";
|
|
140
142
|
import { docsTools, docsToolDefinitions } from "./docs.js";
|
|
143
|
+
import { lintTools, lintToolDefinitions } from "./lint.js";
|
|
141
144
|
// Phase 18.ι — AI refactor MCP tools
|
|
142
145
|
import {
|
|
143
146
|
rewriteGeneratedBarrelTools,
|
|
@@ -254,6 +257,7 @@ const TOOL_MODULES: ToolModule[] = [
|
|
|
254
257
|
{ category: "ai-brief", definitions: aiBriefToolDefinitions, handlers: aiBriefTools },
|
|
255
258
|
{ category: "loop-close", definitions: loopCloseToolDefinitions, handlers: loopCloseTools },
|
|
256
259
|
{ category: "docs", definitions: docsToolDefinitions, handlers: docsTools },
|
|
260
|
+
{ category: "lint", definitions: lintToolDefinitions, handlers: lintTools },
|
|
257
261
|
// Phase 18.ι — AI refactor tools (destructive writes; dry-run by default)
|
|
258
262
|
{
|
|
259
263
|
category: "refactor-barrel",
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP tools — `mandu.lint` + `mandu.lint.setup`
|
|
3
|
+
*
|
|
4
|
+
* Gives agents a first-class way to:
|
|
5
|
+
* 1. Run oxlint on a project and get structured error/warning counts
|
|
6
|
+
* (read-only, no side effects).
|
|
7
|
+
* 2. One-shot install oxlint + scaffold `.oxlintrc.json` + wire
|
|
8
|
+
* scripts on an existing project (destructive — writes files).
|
|
9
|
+
*
|
|
10
|
+
* The setup tool mirrors `mandu lint --setup`. We spawn the CLI as a
|
|
11
|
+
* subprocess rather than linking to the CLI source so MCP builds
|
|
12
|
+
* don't pull `packages/cli` into their import graph.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
import fs from "node:fs/promises";
|
|
18
|
+
|
|
19
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
20
|
+
// Shared helpers
|
|
21
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
22
|
+
|
|
23
|
+
async function oxlintAvailable(rootDir: string): Promise<boolean> {
|
|
24
|
+
const binName = process.platform === "win32" ? "oxlint.exe" : "oxlint";
|
|
25
|
+
const localBin = path.resolve(rootDir, "node_modules", ".bin", binName);
|
|
26
|
+
try {
|
|
27
|
+
await fs.access(localBin);
|
|
28
|
+
return true;
|
|
29
|
+
} catch {
|
|
30
|
+
// Not in local node_modules — probe PATH.
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const proc = Bun.spawn({
|
|
34
|
+
cmd: ["bun", "x", "oxlint", "--version"],
|
|
35
|
+
cwd: rootDir,
|
|
36
|
+
stdout: "ignore",
|
|
37
|
+
stderr: "ignore",
|
|
38
|
+
});
|
|
39
|
+
return (await proc.exited) === 0;
|
|
40
|
+
} catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface LintParsed {
|
|
46
|
+
errors: number;
|
|
47
|
+
warnings: number;
|
|
48
|
+
raw: string;
|
|
49
|
+
parseFailed: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function runOxlintOnce(rootDir: string, typeAware: boolean): Promise<LintParsed> {
|
|
53
|
+
const cmd = typeAware
|
|
54
|
+
? ["bun", "x", "oxlint", "--type-aware", "."]
|
|
55
|
+
: ["bun", "x", "oxlint", "."];
|
|
56
|
+
const proc = Bun.spawn({
|
|
57
|
+
cmd,
|
|
58
|
+
cwd: rootDir,
|
|
59
|
+
stdout: "pipe",
|
|
60
|
+
stderr: "pipe",
|
|
61
|
+
});
|
|
62
|
+
const [stdout, stderr] = await Promise.all([
|
|
63
|
+
new Response(proc.stdout).text(),
|
|
64
|
+
new Response(proc.stderr).text(),
|
|
65
|
+
]);
|
|
66
|
+
await proc.exited;
|
|
67
|
+
const raw = stderr + stdout;
|
|
68
|
+
const match = raw.match(/Found (\d+) warnings? and (\d+) errors?/);
|
|
69
|
+
if (!match) {
|
|
70
|
+
return { errors: 0, warnings: 0, raw, parseFailed: true };
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
errors: Number(match[2]),
|
|
74
|
+
warnings: Number(match[1]),
|
|
75
|
+
raw,
|
|
76
|
+
parseFailed: false,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
81
|
+
// mandu.lint — run oxlint, return counts
|
|
82
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
83
|
+
|
|
84
|
+
interface LintInput {
|
|
85
|
+
typeAware?: unknown;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
interface LintResult {
|
|
89
|
+
installed: boolean;
|
|
90
|
+
ran: boolean;
|
|
91
|
+
errors: number;
|
|
92
|
+
warnings: number;
|
|
93
|
+
passed: boolean;
|
|
94
|
+
hint?: string;
|
|
95
|
+
rawTail?: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function handleLint(projectRoot: string, input: LintInput): Promise<LintResult> {
|
|
99
|
+
const typeAware = input.typeAware === true;
|
|
100
|
+
const installed = await oxlintAvailable(projectRoot);
|
|
101
|
+
if (!installed) {
|
|
102
|
+
return {
|
|
103
|
+
installed: false,
|
|
104
|
+
ran: false,
|
|
105
|
+
errors: 0,
|
|
106
|
+
warnings: 0,
|
|
107
|
+
passed: false,
|
|
108
|
+
hint:
|
|
109
|
+
"oxlint is not installed in this project. Call `mandu.lint.setup` or run `mandu lint --setup` in the shell to install + configure.",
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const result = await runOxlintOnce(projectRoot, typeAware);
|
|
113
|
+
if (result.parseFailed) {
|
|
114
|
+
return {
|
|
115
|
+
installed: true,
|
|
116
|
+
ran: true,
|
|
117
|
+
errors: 0,
|
|
118
|
+
warnings: 0,
|
|
119
|
+
passed: false,
|
|
120
|
+
hint: "oxlint ran but output could not be parsed. See `rawTail` for the last 2 KB.",
|
|
121
|
+
rawTail: result.raw.slice(-2048),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
installed: true,
|
|
126
|
+
ran: true,
|
|
127
|
+
errors: result.errors,
|
|
128
|
+
warnings: result.warnings,
|
|
129
|
+
passed: result.errors === 0,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
134
|
+
// mandu.lint.setup — install oxlint + wire scripts + baseline
|
|
135
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
136
|
+
|
|
137
|
+
interface LintSetupInput {
|
|
138
|
+
dryRun?: unknown;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface LintSetupResult {
|
|
142
|
+
ok: boolean;
|
|
143
|
+
stdout: string;
|
|
144
|
+
stderr: string;
|
|
145
|
+
exitCode: number;
|
|
146
|
+
dryRun: boolean;
|
|
147
|
+
hint?: string;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function handleLintSetup(projectRoot: string, input: LintSetupInput): Promise<LintSetupResult> {
|
|
151
|
+
const dryRun = input.dryRun === true;
|
|
152
|
+
const args = ["run", "--cwd", projectRoot, "mandu", "lint", "--setup", "--yes"];
|
|
153
|
+
if (dryRun) args.push("--dry-run");
|
|
154
|
+
const proc = Bun.spawn({
|
|
155
|
+
cmd: ["bun", ...args],
|
|
156
|
+
cwd: projectRoot,
|
|
157
|
+
stdout: "pipe",
|
|
158
|
+
stderr: "pipe",
|
|
159
|
+
});
|
|
160
|
+
const [stdout, stderr] = await Promise.all([
|
|
161
|
+
new Response(proc.stdout).text(),
|
|
162
|
+
new Response(proc.stderr).text(),
|
|
163
|
+
]);
|
|
164
|
+
const exitCode = await proc.exited;
|
|
165
|
+
const ok = exitCode === 0;
|
|
166
|
+
return {
|
|
167
|
+
ok,
|
|
168
|
+
stdout,
|
|
169
|
+
stderr,
|
|
170
|
+
exitCode,
|
|
171
|
+
dryRun,
|
|
172
|
+
hint: ok
|
|
173
|
+
? dryRun
|
|
174
|
+
? "Dry-run completed. Re-run without `dryRun: true` to apply the changes."
|
|
175
|
+
: "Setup completed. Run `mandu.lint` to see the current baseline."
|
|
176
|
+
: "Setup command failed. See `stderr` for details. A frequent cause is `mandu` CLI not being installed — `bun add -D @mandujs/cli` in the project first.",
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
181
|
+
// MCP tool definitions + handler map
|
|
182
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
183
|
+
|
|
184
|
+
export const lintToolDefinitions: Tool[] = [
|
|
185
|
+
{
|
|
186
|
+
name: "mandu.lint",
|
|
187
|
+
description:
|
|
188
|
+
"Run oxlint on the project and return structured error/warning counts. Read-only — never modifies files. Pass `typeAware: true` to also run `oxlint --type-aware` (requires `oxlint-tsgolint`). Agents should call this after edits as part of the guardrail chain alongside `mandu.guard.check` and `mandu.doctor`.",
|
|
189
|
+
annotations: { readOnlyHint: true },
|
|
190
|
+
inputSchema: {
|
|
191
|
+
type: "object",
|
|
192
|
+
properties: {
|
|
193
|
+
typeAware: {
|
|
194
|
+
type: "boolean",
|
|
195
|
+
description:
|
|
196
|
+
"Run `oxlint --type-aware` in addition to the core pass (requires `oxlint-tsgolint`). Default false.",
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
required: [],
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
name: "mandu.lint.setup",
|
|
204
|
+
description:
|
|
205
|
+
"Install oxlint into an existing project: copies `.oxlintrc.json`, wires `lint`/`lint:fix` scripts, adds `oxlint` devDep, runs `bun install`. Idempotent — re-running produces no additional changes. Destructive — writes files. Set `dryRun: true` to print the plan only.",
|
|
206
|
+
annotations: { readOnlyHint: false, destructiveHint: true },
|
|
207
|
+
inputSchema: {
|
|
208
|
+
type: "object",
|
|
209
|
+
properties: {
|
|
210
|
+
dryRun: {
|
|
211
|
+
type: "boolean",
|
|
212
|
+
description: "Print the plan without writing files. Default false.",
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
required: [],
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
];
|
|
219
|
+
|
|
220
|
+
export function lintTools(projectRoot: string) {
|
|
221
|
+
const handlers: Record<string, (args: Record<string, unknown>) => Promise<unknown>> = {
|
|
222
|
+
"mandu.lint": async (args) => handleLint(projectRoot, args as LintInput),
|
|
223
|
+
"mandu.lint.setup": async (args) => handleLintSetup(projectRoot, args as LintSetupInput),
|
|
224
|
+
};
|
|
225
|
+
return handlers;
|
|
226
|
+
}
|