@mwillbanks/ast-mcp 0.1.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 (61) hide show
  1. package/CONTRIBUTING.md +60 -0
  2. package/LICENSE +21 -0
  3. package/README.md +109 -0
  4. package/dist/ast-mcp-hook.js +7 -0
  5. package/dist/ast-mcp-hook.js.map +11 -0
  6. package/dist/ast-mcp-install.js +22 -0
  7. package/dist/ast-mcp-install.js.map +12 -0
  8. package/dist/ast-mcp.js +115 -0
  9. package/dist/ast-mcp.js.map +89 -0
  10. package/dprint.json +37 -0
  11. package/logo.svg +1 -0
  12. package/package.json +89 -0
  13. package/src/ast-bro/capability.ts +21 -0
  14. package/src/ast-bro/client.ts +47 -0
  15. package/src/ast-bro/result.ts +42 -0
  16. package/src/ast-bro/rewrite-capability.ts +9 -0
  17. package/src/ast-bro/tools.json +603 -0
  18. package/src/hook.ts +79 -0
  19. package/src/http-entry.ts +3 -0
  20. package/src/http.ts +138 -0
  21. package/src/index.ts +8 -0
  22. package/src/installer.ts +501 -0
  23. package/src/lifecycle.ts +10 -0
  24. package/src/managed-hook.ts +4 -0
  25. package/src/patch/aider.ts +224 -0
  26. package/src/patch/engine.ts +446 -0
  27. package/src/patch/languages.ts +36 -0
  28. package/src/runtime/atomic.ts +26 -0
  29. package/src/runtime/attributes.ts +70 -0
  30. package/src/runtime/file-delete.ts +96 -0
  31. package/src/runtime/file-read.ts +178 -0
  32. package/src/runtime/format.ts +56 -0
  33. package/src/runtime/hash.ts +11 -0
  34. package/src/runtime/locks.ts +87 -0
  35. package/src/runtime/paths.ts +73 -0
  36. package/src/runtime/process-input.ts +25 -0
  37. package/src/runtime/signals.ts +47 -0
  38. package/src/server.ts +13 -0
  39. package/src/stdio.ts +154 -0
  40. package/src/tools/ast-bro.ts +172 -0
  41. package/src/tools/files.ts +173 -0
  42. package/src/tools/index.ts +11 -0
  43. package/src/tools/lifecycle.ts +124 -0
  44. package/templates/AGENTS.md +56 -0
  45. package/templates/skills/ast-mcp/SKILL.md +96 -0
  46. package/templates/skills/ast-mcp/agents/openai.yaml +4 -0
  47. package/templates/skills/ast-mcp/evals/batch.evals.json +274 -0
  48. package/templates/skills/ast-mcp/evals/evals.json +1209 -0
  49. package/templates/skills/ast-mcp/evals/file-hash.evals.json +50 -0
  50. package/templates/skills/ast-mcp/evals/measure.ts +18 -0
  51. package/templates/skills/ast-mcp/evals/results.md +17 -0
  52. package/templates/skills/ast-mcp/evals/score.ts +417 -0
  53. package/templates/skills/ast-mcp/evals/semantic.ts +332 -0
  54. package/templates/skills/ast-mcp/evals/trigger-queries.json +22 -0
  55. package/templates/skills/ast-mcp/evals/validate.ts +99 -0
  56. package/templates/skills/ast-mcp/references/installation.md +40 -0
  57. package/templates/skills/ast-mcp/references/managed-hook.ts +3 -0
  58. package/templates/skills/ast-mcp/references/patch-state-machine.md +39 -0
  59. package/templates/skills/ast-mcp/references/tool-catalog.md +46 -0
  60. package/templates/skills/ast-mcp/scripts/check-install.ts +269 -0
  61. package/templates/skills/ast-mcp/scripts/managed-hook.ts +22 -0
package/dprint.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "$schema": "https://dprint.dev/schemas/v0.json",
3
+ "biome": {
4
+ "indentStyle": "space",
5
+ "indentWidth": 2,
6
+ "javascript.quoteStyle": "double",
7
+ "jsxQuoteStyle": "double",
8
+ "lineEnding": "lf",
9
+ "lineWidth": 80,
10
+ "semicolons": "always",
11
+ "trailingCommas": "all"
12
+ },
13
+ "excludes": ["**/node_modules/**", "**/dist/**", "**/build/**", "**/.git/**"],
14
+ "includes": [
15
+ "**/*.{c,cc,cpp,cs,css,go,graphql,html,java,js,json,jsonc,jsx,kt,md,php,py,rb,rs,scala,sql,swift,toml,ts,tsx,yaml,yml}"
16
+ ],
17
+ "plugins": [
18
+ "https://plugins.dprint.dev/biome-0.13.2.wasm",
19
+ "https://plugins.dprint.dev/typescript-0.96.1.wasm",
20
+ "https://plugins.dprint.dev/json-0.23.0.wasm",
21
+ "https://plugins.dprint.dev/markdown-0.22.1.wasm",
22
+ "https://plugins.dprint.dev/toml-0.7.0.wasm",
23
+ "https://plugins.dprint.dev/dockerfile-0.4.1.wasm",
24
+ "https://plugins.dprint.dev/mago-0.21.1.wasm",
25
+ "https://plugins.dprint.dev/ruff-0.7.22.wasm",
26
+ "https://plugins.dprint.dev/jupyter-0.3.1.wasm",
27
+ "https://plugins.dprint.dev/jakebailey/gofumpt-v0.0.13.wasm",
28
+ "https://plugins.dprint.dev/g-plane/malva-v0.16.0.wasm",
29
+ "https://plugins.dprint.dev/g-plane/markup_fmt-v0.27.3.wasm",
30
+ "https://plugins.dprint.dev/g-plane/pretty_yaml-v0.6.0.wasm",
31
+ "https://plugins.dprint.dev/g-plane/pretty_graphql-v0.2.3.wasm",
32
+ "https://plugins.dprint.dev/bartlomieju/lax-sql-0.3.0.wasm",
33
+ "https://plugins.dprint.dev/prettier-0.72.0.json@6e7af2cb2182a5a11358d3adde9ae0ef3b94b7d2e5dcfdd252e3f7c3916541fe",
34
+ "https://plugins.dprint.dev/roslyn-0.21.0.json@c1429e04de13cff489025e8739f76a476fce6513128366f30feecef2bec0848d",
35
+ "https://plugins.dprint.dev/exec-0.7.3.json@a7898d5f1897e77bff474cec3d948c3ec3a7f455e32de2cc60c8adb9a5dd24aa"
36
+ ]
37
+ }
package/logo.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" role="img" aria-labelledby="title desc"><title id="title">AST MCP</title><desc id="desc">A geometric emblem combining an abstract syntax tree with structured code transformation and patching.</desc><defs><linearGradient id="frame" x1="86" y1="96" x2="426" y2="416" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#27c2f3"/><stop offset=".48" stop-color="#2878e8"/><stop offset="1" stop-color="#8a3ffc"/></linearGradient><linearGradient id="tree" x1="142" y1="150" x2="286" y2="372" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#51d7f7"/><stop offset=".55" stop-color="#2587e8"/><stop offset="1" stop-color="#6254e8"/></linearGradient><linearGradient id="patch" x1="276" y1="170" x2="405" y2="350" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#9b5cff"/><stop offset="1" stop-color="#6f32d8"/></linearGradient><filter id="soft" x="-20%" y="-20%" width="140%" height="140%"><feGaussianBlur stdDeviation="7"/></filter></defs><path d="M256 45 421 140v232L256 467 91 372V140L256 45Z" fill="none" stroke="url(#frame)" stroke-width="14" opacity=".16" filter="url(#soft)"/><path d="M246 56 98 141v118" fill="none" stroke="url(#frame)" stroke-width="18" stroke-linecap="round" stroke-linejoin="round"/><path d="M98 259 67 290l31 31v50l148 85" fill="none" stroke="url(#frame)" stroke-width="18" stroke-linecap="round" stroke-linejoin="round"/><path d="M266 56 414 141v102" fill="none" stroke="url(#frame)" stroke-width="18" stroke-linecap="round" stroke-linejoin="round"/><path d="M414 337v34l-148 85" fill="none" stroke="url(#frame)" stroke-width="18" stroke-linecap="round" stroke-linejoin="round"/><path d="M256 117v278" fill="none" stroke="url(#tree)" stroke-width="13" stroke-linecap="round"/><path d="M256 169 205 132h-43" fill="none" stroke="url(#tree)" stroke-width="11" stroke-linecap="round" stroke-linejoin="round"/><path d="M256 214 196 252h-50" fill="none" stroke="url(#tree)" stroke-width="11" stroke-linecap="round" stroke-linejoin="round"/><path d="M256 260 206 299l-38 55" fill="none" stroke="url(#tree)" stroke-width="11" stroke-linecap="round" stroke-linejoin="round"/><path d="M256 321 210 350v33" fill="none" stroke="url(#tree)" stroke-width="11" stroke-linecap="round" stroke-linejoin="round"/><g fill="#0e1831" stroke="url(#tree)" stroke-width="9"><circle cx="148" cy="132" r="14"/><circle cx="132" cy="252" r="14"/><circle cx="158" cy="367" r="14"/><circle cx="210" cy="397" r="14"/></g><path d="m302 174-31 31 31 31" fill="none" stroke="url(#patch)" stroke-width="13" stroke-linecap="round" stroke-linejoin="round"/><path d="m350 174 31 31-31 31" fill="none" stroke="url(#patch)" stroke-width="13" stroke-linecap="round" stroke-linejoin="round"/><circle cx="326" cy="193" r="6" fill="#8d48f2"/><circle cx="326" cy="217" r="6" fill="#8d48f2"/><g fill="none" stroke="url(#patch)" stroke-width="11" stroke-linecap="round"><path d="M293 279h111"/><path d="M312 313h92" opacity=".9"/><path d="M282 347h63" opacity=".82"/><path d="M363 347h41" opacity=".55"/></g><path d="M256 365 297 338" fill="none" stroke="url(#patch)" stroke-width="11" stroke-linecap="round"/><path d="m297 338 13 13 24-27" fill="none" stroke="url(#patch)" stroke-width="10" stroke-linecap="round" stroke-linejoin="round"/></svg>
package/package.json ADDED
@@ -0,0 +1,89 @@
1
+ {
2
+ "author": "Mike Willbanks",
3
+ "bin": {
4
+ "ast-mcp": "dist/ast-mcp.js",
5
+ "ast-mcp-hook": "dist/ast-mcp-hook.js",
6
+ "ast-mcp-install": "dist/ast-mcp-install.js"
7
+ },
8
+ "bugs": {
9
+ "url": "https://github.com/mwillbanks/ast-mcp/issues"
10
+ },
11
+ "dependencies": {
12
+ "@ast-bro/cli": "3.0.0",
13
+ "@modelcontextprotocol/client": "2.0.0-beta.5",
14
+ "@modelcontextprotocol/server": "^2.0.0-beta.5",
15
+ "diff-match-patch-ts": "^2.0.0",
16
+ "dprint": "0.55.2",
17
+ "zod": "^4.4.3"
18
+ },
19
+ "description": "Zero-trust MCP file writes, AST edits, ast-bro intelligence, hooks, and agent skills",
20
+ "devDependencies": {
21
+ "@biomejs/biome": "^2.5.5",
22
+ "@modelcontextprotocol/inspector": "^1.0.0",
23
+ "@types/bun": "^1.3.14",
24
+ "@types/node": "^26.1.1",
25
+ "fallow": "^3.7.1",
26
+ "typescript": "^7.0.2"
27
+ },
28
+ "engines": {
29
+ "bun": ">=1.3.0"
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "src",
34
+ "templates",
35
+ "dprint.json",
36
+ "README.md",
37
+ "CONTRIBUTING.md",
38
+ "logo.svg",
39
+ "LICENSE"
40
+ ],
41
+ "homepage": "https://mwillbanks.github.io/ast-mcp/",
42
+ "keywords": [
43
+ "ast",
44
+ "ast-grep",
45
+ "coding-agents",
46
+ "mcp",
47
+ "model-context-protocol",
48
+ "secure-code-editing"
49
+ ],
50
+ "license": "MIT",
51
+ "name": "@mwillbanks/ast-mcp",
52
+ "packageManager": "bun@1.3.14",
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "repository": {
57
+ "type": "git",
58
+ "url": "git+https://github.com/mwillbanks/ast-mcp.git"
59
+ },
60
+ "scripts": {
61
+ "build": "bun build ./bin/ast-mcp.ts ./bin/ast-mcp-hook.ts ./bin/ast-mcp-install.ts --outdir ./dist --target bun --format esm --sourcemap=external --minify",
62
+ "check": "bun run tools:check && bun run format:check && bun run typecheck && bun run test",
63
+ "dev": "bun run --watch src/index.ts",
64
+ "dev:http": "bun run --watch src/http-entry.ts",
65
+ "evals:check": "bun run templates/skills/ast-mcp/evals/validate.ts",
66
+ "evals:measure": "bun run templates/skills/ast-mcp/evals/measure.ts",
67
+ "evals:score": "bun run templates/skills/ast-mcp/evals/measure.ts --strict",
68
+ "fallow": "fallow --skip health",
69
+ "fallow:health": "fallow health",
70
+ "format": "biome check . --write --unsafe --reporter concise --error-on-warnings",
71
+ "format:check": "biome check . --reporter concise --error-on-warnings",
72
+ "inspect": "bunx @modelcontextprotocol/inspector bun run src/index.ts",
73
+ "inspect:http": "bunx @modelcontextprotocol/inspector",
74
+ "lint": "biome check . --reporter concise --error-on-warnings",
75
+ "prepack": "bun run build",
76
+ "skill:check": "bunx skills-ref validate templates/skills/ast-mcp",
77
+ "start": "bun run src/index.ts",
78
+ "start:http": "bun run src/http-entry.ts",
79
+ "test": "bun test --bail --max-concurrency=1",
80
+ "tools:check": "ast-bro --version && dprint --version && dprint check README.md",
81
+ "typecheck": "bunx tsc --noEmit"
82
+ },
83
+ "sideEffects": false,
84
+ "trustedDependencies": [
85
+ "@ast-bro/cli"
86
+ ],
87
+ "type": "module",
88
+ "version": "0.1.0"
89
+ }
@@ -0,0 +1,21 @@
1
+ import path from "node:path";
2
+
3
+ import { callAstBro } from "./client";
4
+ import { parseAstBroJson } from "./result";
5
+
6
+ export async function astCapable(
7
+ filePath: string,
8
+ language?: string,
9
+ ): Promise<boolean> {
10
+ if (!language) return false;
11
+ const result = await callAstBro(
12
+ "map",
13
+ { json: true, paths: [filePath] },
14
+ path.dirname(filePath),
15
+ );
16
+ const payload = parseAstBroJson(result);
17
+ const file = (payload.files ?? []).find(
18
+ (candidate: { path?: unknown }) => candidate.path === filePath,
19
+ );
20
+ return file?.error_count === 0;
21
+ }
@@ -0,0 +1,47 @@
1
+ import path from "node:path";
2
+ import { Client } from "@modelcontextprotocol/client";
3
+ import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
4
+
5
+ const binary = path.resolve(import.meta.dir, "../../node_modules/.bin/ast-bro");
6
+ export const AST_BRO_TOOLS = [
7
+ "map",
8
+ "digest",
9
+ "show",
10
+ "implements",
11
+ "surface",
12
+ "deps",
13
+ "reverse_deps",
14
+ "cycles",
15
+ "graph",
16
+ "search",
17
+ "find_related",
18
+ "index",
19
+ "callers",
20
+ "callees",
21
+ "trace",
22
+ "impact",
23
+ "context",
24
+ "run",
25
+ "squeeze",
26
+ ] as const;
27
+ export async function callAstBro(
28
+ toolName: (typeof AST_BRO_TOOLS)[number],
29
+ args: Record<string, unknown>,
30
+ root: string,
31
+ ) {
32
+ const client = new Client({ name: "ast-mcp", version: "1.0.0" });
33
+ const transport = new StdioClientTransport({
34
+ args: ["mcp"],
35
+ command: binary,
36
+ cwd: root,
37
+ stderr: "pipe",
38
+ });
39
+ try {
40
+ await client.connect(transport);
41
+ return await client.callTool({ arguments: args, name: toolName });
42
+ } finally {
43
+ try {
44
+ await client.close();
45
+ } catch {}
46
+ }
47
+ }
@@ -0,0 +1,42 @@
1
+ export interface AstBroResult {
2
+ content: Array<{ type: string; text?: string }>;
3
+ isError?: boolean;
4
+ }
5
+
6
+ // biome-ignore lint/suspicious/noExplicitAny: Upstream JSON schemas are intentionally dynamic at this boundary.
7
+ export function parseAstBroJson(result: AstBroResult): Record<string, any> {
8
+ const text = result.content
9
+ .filter((item) => item.type === "text" && typeof item.text === "string")
10
+ .map((item) => item.text)
11
+ .join("\n");
12
+ if (result.isError) throw new Error(text || "ast-bro MCP call failed");
13
+ if (!text) throw new Error("ast-bro MCP returned no JSON text");
14
+ try {
15
+ return JSON.parse(text);
16
+ } catch (error) {
17
+ throw new Error(`Invalid ast-bro MCP JSON: ${text}`, { cause: error });
18
+ }
19
+ }
20
+
21
+ export function astBroMatchFiles(result: AstBroResult): string[] {
22
+ const payload = parseAstBroJson(result);
23
+ return [
24
+ ...new Set<string>(
25
+ (payload.matches ?? [])
26
+ .map((match: { file?: unknown }) => match.file)
27
+ .filter((file: unknown): file is string => typeof file === "string"),
28
+ ),
29
+ ];
30
+ }
31
+
32
+ export function astBroRewrittenFiles(result: AstBroResult): string[] {
33
+ const payload = parseAstBroJson(result);
34
+ return [
35
+ ...new Set<string>(
36
+ (payload.files ?? [])
37
+ .filter((file: { status?: unknown }) => file.status === "rewritten")
38
+ .map((file: { file?: unknown }) => file.file)
39
+ .filter((file: unknown): file is string => typeof file === "string"),
40
+ ),
41
+ ];
42
+ }
@@ -0,0 +1,9 @@
1
+ import { astCapable } from "./capability";
2
+
3
+ export async function astRewritable(
4
+ filePath: string,
5
+ language?: string,
6
+ ): Promise<boolean> {
7
+ if (language === "markdown") return false;
8
+ return astCapable(filePath, language);
9
+ }