@codai/axiom-mcp 1.0.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/dist/postinstall.js +10 -0
- package/dist/server.js +86 -0
- package/package.json +23 -0
- package/src/postinstall.ts +12 -0
- package/src/server.ts +85 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
const mcpDir = path.join(os.homedir(), ".axiom");
|
|
5
|
+
fs.mkdirSync(mcpDir, { recursive: true });
|
|
6
|
+
fs.writeFileSync(path.join(mcpDir, "server.json"), JSON.stringify({
|
|
7
|
+
hint: "AXIOM MCP installed. Start with: npx axiom-mcp (or via host client auto-discovery).",
|
|
8
|
+
portEnv: "AXIOM_MCP_PORT",
|
|
9
|
+
defaultPort: 3411
|
|
10
|
+
}, null, 2));
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import http from "node:http";
|
|
2
|
+
import { parseAxiomSource } from "@codai/axiom-core/dist/parser.js";
|
|
3
|
+
import { validateIR } from "@codai/axiom-core/dist/validator.js";
|
|
4
|
+
import { AxiomIR } from "@codai/axiom-core/dist/ir.js";
|
|
5
|
+
import { generate } from "@codai/axiom-engine/dist/generate.js";
|
|
6
|
+
import { check } from "@codai/axiom-engine/dist/check.js";
|
|
7
|
+
import { reverseIR } from "@codai/axiom-engine/dist/reverse-ir.js";
|
|
8
|
+
import { diff } from "@codai/axiom-engine/dist/axpatch.js";
|
|
9
|
+
import { apply } from "@codai/axiom-engine/dist/apply.js";
|
|
10
|
+
const PORT = Number(process.env.AXIOM_MCP_PORT || 3411);
|
|
11
|
+
function send(res, code, obj) {
|
|
12
|
+
const body = JSON.stringify(obj, null, 2);
|
|
13
|
+
res.writeHead(code, { "content-type": "application/json" });
|
|
14
|
+
res.end(body);
|
|
15
|
+
}
|
|
16
|
+
const server = http.createServer(async (req, res) => {
|
|
17
|
+
try {
|
|
18
|
+
const chunks = [];
|
|
19
|
+
req.on("data", (c) => chunks.push(c));
|
|
20
|
+
req.on("end", async () => {
|
|
21
|
+
const input = chunks.length ? JSON.parse(Buffer.concat(chunks).toString("utf-8")) : {};
|
|
22
|
+
if (req.method === "POST" && req.url === "/parse") {
|
|
23
|
+
const { source } = input;
|
|
24
|
+
const { ir, diagnostics } = parseAxiomSource(String(source ?? ""));
|
|
25
|
+
return send(res, 200, { ir, diagnostics });
|
|
26
|
+
}
|
|
27
|
+
if (req.method === "POST" && req.url === "/validate") {
|
|
28
|
+
const parse = AxiomIR.safeParse(input.ir);
|
|
29
|
+
if (!parse.success)
|
|
30
|
+
return send(res, 400, { ok: false, diagnostics: parse.error.issues });
|
|
31
|
+
const result = validateIR(parse.data);
|
|
32
|
+
return send(res, 200, result);
|
|
33
|
+
}
|
|
34
|
+
if (req.method === "POST" && req.url === "/generate") {
|
|
35
|
+
const parse = AxiomIR.safeParse(input.ir);
|
|
36
|
+
if (!parse.success)
|
|
37
|
+
return send(res, 400, { error: parse.error.issues });
|
|
38
|
+
const { artifacts, manifest } = await generate(parse.data, process.cwd(), input.profile);
|
|
39
|
+
return send(res, 200, { artifacts, manifest });
|
|
40
|
+
}
|
|
41
|
+
if (req.method === "POST" && req.url === "/check") {
|
|
42
|
+
const parse = input.ir ? AxiomIR.safeParse(input.ir) : null;
|
|
43
|
+
const ir = parse?.success ? parse.data : undefined;
|
|
44
|
+
const result = await check(input.manifest, ir, input.outRoot || process.cwd());
|
|
45
|
+
return send(res, 200, result);
|
|
46
|
+
}
|
|
47
|
+
if (req.method === "POST" && req.url === "/reverse") {
|
|
48
|
+
const ir = await reverseIR({
|
|
49
|
+
repoPath: input.repoPath || process.cwd(),
|
|
50
|
+
outDir: input.outDir || "out",
|
|
51
|
+
});
|
|
52
|
+
return send(res, 200, { ir, diagnostics: [] });
|
|
53
|
+
}
|
|
54
|
+
if (req.method === "POST" && req.url === "/diff") {
|
|
55
|
+
const oldParse = AxiomIR.safeParse(input.oldIr);
|
|
56
|
+
const newParse = AxiomIR.safeParse(input.newIr);
|
|
57
|
+
if (!oldParse.success)
|
|
58
|
+
return send(res, 400, { error: "Invalid oldIr", details: oldParse.error.issues });
|
|
59
|
+
if (!newParse.success)
|
|
60
|
+
return send(res, 400, { error: "Invalid newIr", details: newParse.error.issues });
|
|
61
|
+
const patch = diff(oldParse.data, newParse.data);
|
|
62
|
+
return send(res, 200, { patch });
|
|
63
|
+
}
|
|
64
|
+
if (req.method === "POST" && req.url === "/apply") {
|
|
65
|
+
if (!input.manifest)
|
|
66
|
+
return send(res, 400, { error: "Missing manifest" });
|
|
67
|
+
const mode = input.mode || "fs";
|
|
68
|
+
const result = await apply({
|
|
69
|
+
manifest: input.manifest,
|
|
70
|
+
mode: mode,
|
|
71
|
+
repoPath: input.repoPath || process.cwd(),
|
|
72
|
+
branchName: input.branchName,
|
|
73
|
+
commitMessage: input.commitMessage,
|
|
74
|
+
});
|
|
75
|
+
return send(res, 200, result);
|
|
76
|
+
}
|
|
77
|
+
send(res, 404, { error: "Not found" });
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
send(res, 500, { error: String(e?.message || e) });
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
server.listen(PORT, () => {
|
|
85
|
+
console.log(`[axiom-mcp] listening on http://localhost:${PORT}`);
|
|
86
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@codai/axiom-mcp",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"bin": {
|
|
6
|
+
"axiom-mcp": "dist/server.js"
|
|
7
|
+
},
|
|
8
|
+
"main": "dist/server.js",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc -p tsconfig.json",
|
|
11
|
+
"dev": "tsx watch src/server.ts",
|
|
12
|
+
"postinstall": "node dist/postinstall.js"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@codai/axiom-core": "workspace:*",
|
|
16
|
+
"@codai/axiom-engine": "workspace:*"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^22.0.0",
|
|
20
|
+
"typescript": "^5.6.3",
|
|
21
|
+
"tsx": "^4.19.0"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
const mcpDir = path.join(os.homedir(), ".axiom");
|
|
7
|
+
fs.mkdirSync(mcpDir, { recursive: true });
|
|
8
|
+
fs.writeFileSync(path.join(mcpDir, "server.json"), JSON.stringify({
|
|
9
|
+
hint: "AXIOM MCP installed. Start with: npx axiom-mcp (or via host client auto-discovery).",
|
|
10
|
+
portEnv: "AXIOM_MCP_PORT",
|
|
11
|
+
defaultPort: 3411
|
|
12
|
+
}, null, 2));
|
package/src/server.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
|
|
2
|
+
import http from "node:http";
|
|
3
|
+
import { parseAxiomSource } from "@codai/axiom-core/dist/parser.js";
|
|
4
|
+
import { validateIR } from "@codai/axiom-core/dist/validator.js";
|
|
5
|
+
import { AxiomIR } from "@codai/axiom-core/dist/ir.js";
|
|
6
|
+
import { generate } from "@codai/axiom-engine/dist/generate.js";
|
|
7
|
+
import { check } from "@codai/axiom-engine/dist/check.js";
|
|
8
|
+
import { reverseIR } from "@codai/axiom-engine/dist/reverse-ir.js";
|
|
9
|
+
import { diff, applyPatch } from "@codai/axiom-engine/dist/axpatch.js";
|
|
10
|
+
import { apply } from "@codai/axiom-engine/dist/apply.js";
|
|
11
|
+
|
|
12
|
+
const PORT = Number(process.env.AXIOM_MCP_PORT || 3411);
|
|
13
|
+
|
|
14
|
+
function send(res: http.ServerResponse, code: number, obj: any) {
|
|
15
|
+
const body = JSON.stringify(obj, null, 2);
|
|
16
|
+
res.writeHead(code, { "content-type": "application/json" });
|
|
17
|
+
res.end(body);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const server = http.createServer(async (req, res) => {
|
|
21
|
+
try {
|
|
22
|
+
const chunks: Buffer[] = [];
|
|
23
|
+
req.on("data", (c) => chunks.push(c));
|
|
24
|
+
req.on("end", async () => {
|
|
25
|
+
const input = chunks.length ? JSON.parse(Buffer.concat(chunks).toString("utf-8")) : {};
|
|
26
|
+
if (req.method === "POST" && req.url === "/parse") {
|
|
27
|
+
const { source } = input;
|
|
28
|
+
const { ir, diagnostics } = parseAxiomSource(String(source ?? ""));
|
|
29
|
+
return send(res, 200, { ir, diagnostics });
|
|
30
|
+
}
|
|
31
|
+
if (req.method === "POST" && req.url === "/validate") {
|
|
32
|
+
const parse = AxiomIR.safeParse(input.ir);
|
|
33
|
+
if (!parse.success) return send(res, 400, { ok: false, diagnostics: parse.error.issues });
|
|
34
|
+
const result = validateIR(parse.data);
|
|
35
|
+
return send(res, 200, result);
|
|
36
|
+
}
|
|
37
|
+
if (req.method === "POST" && req.url === "/generate") {
|
|
38
|
+
const parse = AxiomIR.safeParse(input.ir);
|
|
39
|
+
if (!parse.success) return send(res, 400, { error: parse.error.issues });
|
|
40
|
+
const { artifacts, manifest } = await generate(parse.data, process.cwd(), input.profile);
|
|
41
|
+
return send(res, 200, { artifacts, manifest });
|
|
42
|
+
}
|
|
43
|
+
if (req.method === "POST" && req.url === "/check") {
|
|
44
|
+
const parse = input.ir ? AxiomIR.safeParse(input.ir) : null;
|
|
45
|
+
const ir = parse?.success ? parse.data : undefined;
|
|
46
|
+
const result = await check(input.manifest, ir, input.outRoot || process.cwd());
|
|
47
|
+
return send(res, 200, result);
|
|
48
|
+
}
|
|
49
|
+
if (req.method === "POST" && req.url === "/reverse") {
|
|
50
|
+
const ir = await reverseIR({
|
|
51
|
+
repoPath: input.repoPath || process.cwd(),
|
|
52
|
+
outDir: input.outDir || "out",
|
|
53
|
+
});
|
|
54
|
+
return send(res, 200, { ir, diagnostics: [] });
|
|
55
|
+
}
|
|
56
|
+
if (req.method === "POST" && req.url === "/diff") {
|
|
57
|
+
const oldParse = AxiomIR.safeParse(input.oldIr);
|
|
58
|
+
const newParse = AxiomIR.safeParse(input.newIr);
|
|
59
|
+
if (!oldParse.success) return send(res, 400, { error: "Invalid oldIr", details: oldParse.error.issues });
|
|
60
|
+
if (!newParse.success) return send(res, 400, { error: "Invalid newIr", details: newParse.error.issues });
|
|
61
|
+
const patch = diff(oldParse.data, newParse.data);
|
|
62
|
+
return send(res, 200, { patch });
|
|
63
|
+
}
|
|
64
|
+
if (req.method === "POST" && req.url === "/apply") {
|
|
65
|
+
if (!input.manifest) return send(res, 400, { error: "Missing manifest" });
|
|
66
|
+
const mode = input.mode || "fs";
|
|
67
|
+
const result = await apply({
|
|
68
|
+
manifest: input.manifest,
|
|
69
|
+
mode: mode as "fs" | "pr",
|
|
70
|
+
repoPath: input.repoPath || process.cwd(),
|
|
71
|
+
branchName: input.branchName,
|
|
72
|
+
commitMessage: input.commitMessage,
|
|
73
|
+
});
|
|
74
|
+
return send(res, 200, result);
|
|
75
|
+
}
|
|
76
|
+
send(res, 404, { error: "Not found" });
|
|
77
|
+
});
|
|
78
|
+
} catch (e: any) {
|
|
79
|
+
send(res, 500, { error: String(e?.message || e) });
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
server.listen(PORT, () => {
|
|
84
|
+
console.log(`[axiom-mcp] listening on http://localhost:${PORT}`);
|
|
85
|
+
});
|