mcp-multitool 0.1.12 → 0.1.13
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 +2 -0
- package/dist/tools/astGrepSearch.js +33 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -75,6 +75,8 @@ Search code using AST patterns. Matches code structure, not text. Use `$VAR` for
|
|
|
75
75
|
|
|
76
76
|
**Response:** JSON object with `results` array (each with `file`, `range`, `text`) and `errors` array.
|
|
77
77
|
|
|
78
|
+
**Pattern Validation:** Patterns are validated before search. Invalid patterns (e.g., `class X` without a body, `function foo` without parentheses) return an error explaining the issue. Patterns must be syntactically complete code fragments.
|
|
79
|
+
|
|
78
80
|
**Examples:**
|
|
79
81
|
|
|
80
82
|
```
|
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { findInFiles } from "@ast-grep/napi";
|
|
2
|
+
import { findInFiles, parse } from "@ast-grep/napi";
|
|
3
|
+
function validatePattern(lang, pattern) {
|
|
4
|
+
const tree = parse(lang, pattern);
|
|
5
|
+
const root = tree.root();
|
|
6
|
+
function findErrors(node) {
|
|
7
|
+
const errors = [];
|
|
8
|
+
if (node.kind() === "ERROR") {
|
|
9
|
+
errors.push(`"${node.text().slice(0, 50)}"`);
|
|
10
|
+
}
|
|
11
|
+
for (const child of node.children()) {
|
|
12
|
+
errors.push(...findErrors(child));
|
|
13
|
+
}
|
|
14
|
+
return errors;
|
|
15
|
+
}
|
|
16
|
+
const errors = findErrors(root);
|
|
17
|
+
if (errors.length > 0) {
|
|
18
|
+
return {
|
|
19
|
+
valid: false,
|
|
20
|
+
error: `Pattern "${pattern}" is not valid ${lang} syntax.\n` +
|
|
21
|
+
`Invalid syntax near: ${errors.join(", ")}\n\n` +
|
|
22
|
+
`Tip: Patterns must be syntactically complete code fragments. ` +
|
|
23
|
+
`For example, "class X" is invalid (needs body), use "class X { $$$BODY }" instead.`,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return { valid: true };
|
|
27
|
+
}
|
|
3
28
|
const builtinLangs = [
|
|
4
29
|
"javascript",
|
|
5
30
|
"typescript",
|
|
@@ -38,6 +63,13 @@ export function register(server) {
|
|
|
38
63
|
try {
|
|
39
64
|
const lang = langMap[input.lang];
|
|
40
65
|
const paths = Array.isArray(input.paths) ? input.paths : [input.paths];
|
|
66
|
+
const validation = validatePattern(lang, input.pattern);
|
|
67
|
+
if (!validation.valid) {
|
|
68
|
+
return {
|
|
69
|
+
isError: true,
|
|
70
|
+
content: [{ type: "text", text: validation.error }],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
41
73
|
const results = [];
|
|
42
74
|
const errors = [];
|
|
43
75
|
await findInFiles(lang, {
|