magento2-code-review-agent 0.0.0-stage → 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.
- package/LICENSE +15 -0
- package/README.md +1 -3
- package/dist/analyzers/php-heuristics.d.ts +13 -0
- package/dist/analyzers/php-heuristics.js +79 -0
- package/dist/analyzers/php-heuristics.js.map +1 -0
- package/dist/core/config.d.ts +6 -0
- package/dist/core/config.js +11 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/project.d.ts +23 -0
- package/dist/core/project.js +85 -0
- package/dist/core/project.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/register.d.ts +3 -0
- package/dist/tools/register.js +54 -0
- package/dist/tools/register.js.map +1 -0
- package/package.json +29 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Magento Architect AI contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
|
package/README.md
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ReviewFinding {
|
|
2
|
+
ruleId: string;
|
|
3
|
+
category: string;
|
|
4
|
+
severity: "critical" | "high" | "medium" | "low" | "info";
|
|
5
|
+
confidence: "high" | "medium" | "low";
|
|
6
|
+
title: string;
|
|
7
|
+
line: number;
|
|
8
|
+
evidence: string;
|
|
9
|
+
explanation: string;
|
|
10
|
+
recommendation: string;
|
|
11
|
+
requiresManualVerification: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function analyzePhp(source: string): ReviewFinding[];
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const rules = [
|
|
2
|
+
{
|
|
3
|
+
id: "MAGENTO.PHP.OBJECT_MANAGER",
|
|
4
|
+
category: "architecture",
|
|
5
|
+
severity: "medium",
|
|
6
|
+
confidence: "high",
|
|
7
|
+
title: "Direct ObjectManager usage detected",
|
|
8
|
+
pattern: /\bObjectManager\b|ObjectManager::getInstance\s*\(/,
|
|
9
|
+
explanation: "Direct ObjectManager usage can hide dependencies and make code harder to test. Some framework-level or generated-code contexts may be exceptions.",
|
|
10
|
+
recommendation: "Prefer constructor dependency injection or an appropriate Magento factory. Verify whether this occurrence is in an allowed framework context.",
|
|
11
|
+
manual: true
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
id: "PHP.DEBUG.OUTPUT",
|
|
15
|
+
category: "code-quality",
|
|
16
|
+
severity: "medium",
|
|
17
|
+
confidence: "high",
|
|
18
|
+
title: "Debug output or process termination detected",
|
|
19
|
+
pattern: /\b(var_dump|print_r|dd)\s*\(|\b(die|exit)\s*(\(|;)/,
|
|
20
|
+
explanation: "Debug output or forced termination may leak information or interrupt application execution.",
|
|
21
|
+
recommendation: "Remove debugging statements and use an appropriate logger or exception flow."
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
id: "PHP.FILE.WRITE",
|
|
25
|
+
category: "security",
|
|
26
|
+
severity: "low",
|
|
27
|
+
confidence: "medium",
|
|
28
|
+
title: "Direct file write detected",
|
|
29
|
+
pattern: /\bfile_put_contents\s*\(/,
|
|
30
|
+
explanation: "Direct file writes require careful path, permission and input validation.",
|
|
31
|
+
recommendation: "Validate and constrain file paths; consider Magento filesystem abstractions where appropriate.",
|
|
32
|
+
manual: true
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: "PHP.SUPERGLOBAL",
|
|
36
|
+
category: "security",
|
|
37
|
+
severity: "low",
|
|
38
|
+
confidence: "medium",
|
|
39
|
+
title: "Direct PHP superglobal access detected",
|
|
40
|
+
pattern: /\$_(GET|POST|REQUEST|COOKIE|FILES)\b/,
|
|
41
|
+
explanation: "Raw request data may be unvalidated or bypass framework request abstractions.",
|
|
42
|
+
recommendation: "Use the appropriate Magento request interface and validate/sanitize input according to its use.",
|
|
43
|
+
manual: true
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: "PHP.UNSAFE.DESERIALIZE",
|
|
47
|
+
category: "security",
|
|
48
|
+
severity: "high",
|
|
49
|
+
confidence: "medium",
|
|
50
|
+
title: "PHP unserialize call detected",
|
|
51
|
+
pattern: /\bunserialize\s*\(/,
|
|
52
|
+
explanation: "Untrusted serialized input can lead to object injection vulnerabilities.",
|
|
53
|
+
recommendation: "Avoid unserializing untrusted data. If unavoidable, strictly constrain allowed classes and validate the source."
|
|
54
|
+
}
|
|
55
|
+
];
|
|
56
|
+
export function analyzePhp(source) {
|
|
57
|
+
const findings = [];
|
|
58
|
+
const lines = source.split(/\r?\n/);
|
|
59
|
+
lines.forEach((line, index) => {
|
|
60
|
+
for (const rule of rules) {
|
|
61
|
+
if (rule.pattern.test(line)) {
|
|
62
|
+
findings.push({
|
|
63
|
+
ruleId: rule.id,
|
|
64
|
+
category: rule.category,
|
|
65
|
+
severity: rule.severity,
|
|
66
|
+
confidence: rule.confidence,
|
|
67
|
+
title: rule.title,
|
|
68
|
+
line: index + 1,
|
|
69
|
+
evidence: line.trim().slice(0, 300),
|
|
70
|
+
explanation: rule.explanation,
|
|
71
|
+
recommendation: rule.recommendation,
|
|
72
|
+
requiresManualVerification: Boolean(rule.manual)
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return findings;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=php-heuristics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"php-heuristics.js","sourceRoot":"","sources":["../../src/analyzers/php-heuristics.ts"],"names":[],"mappings":"AAyBA,MAAM,KAAK,GAAW;IACpB;QACE,EAAE,EAAE,4BAA4B;QAChC,QAAQ,EAAE,cAAc;QACxB,QAAQ,EAAE,QAAQ;QAClB,UAAU,EAAE,MAAM;QAClB,KAAK,EAAE,qCAAqC;QAC5C,OAAO,EAAE,mDAAmD;QAC5D,WAAW,EAAE,mJAAmJ;QAChK,cAAc,EAAE,+IAA+I;QAC/J,MAAM,EAAE,IAAI;KACb;IACD;QACE,EAAE,EAAE,kBAAkB;QACtB,QAAQ,EAAE,cAAc;QACxB,QAAQ,EAAE,QAAQ;QAClB,UAAU,EAAE,MAAM;QAClB,KAAK,EAAE,8CAA8C;QACrD,OAAO,EAAE,oDAAoD;QAC7D,WAAW,EAAE,6FAA6F;QAC1G,cAAc,EAAE,8EAA8E;KAC/F;IACD;QACE,EAAE,EAAE,gBAAgB;QACpB,QAAQ,EAAE,UAAU;QACpB,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE,QAAQ;QACpB,KAAK,EAAE,4BAA4B;QACnC,OAAO,EAAE,0BAA0B;QACnC,WAAW,EAAE,2EAA2E;QACxF,cAAc,EAAE,gGAAgG;QAChH,MAAM,EAAE,IAAI;KACb;IACD;QACE,EAAE,EAAE,iBAAiB;QACrB,QAAQ,EAAE,UAAU;QACpB,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE,QAAQ;QACpB,KAAK,EAAE,wCAAwC;QAC/C,OAAO,EAAE,sCAAsC;QAC/C,WAAW,EAAE,+EAA+E;QAC5F,cAAc,EAAE,iGAAiG;QACjH,MAAM,EAAE,IAAI;KACb;IACD;QACE,EAAE,EAAE,wBAAwB;QAC5B,QAAQ,EAAE,UAAU;QACpB,QAAQ,EAAE,MAAM;QAChB,UAAU,EAAE,QAAQ;QACpB,KAAK,EAAE,+BAA+B;QACtC,OAAO,EAAE,oBAAoB;QAC7B,WAAW,EAAE,0EAA0E;QACvF,cAAc,EAAE,iHAAiH;KAClI;CACF,CAAC;AAEF,MAAM,UAAU,UAAU,CAAC,MAAc;IACvC,MAAM,QAAQ,GAAoB,EAAE,CAAC;IACrC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACpC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAC5B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC5B,QAAQ,CAAC,IAAI,CAAC;oBACZ,MAAM,EAAE,IAAI,CAAC,EAAE;oBACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;oBACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;oBACvB,UAAU,EAAE,IAAI,CAAC,UAAU;oBAC3B,KAAK,EAAE,IAAI,CAAC,KAAK;oBACjB,IAAI,EAAE,KAAK,GAAG,CAAC;oBACf,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC;oBACnC,WAAW,EAAE,IAAI,CAAC,WAAW;oBAC7B,cAAc,EAAE,IAAI,CAAC,cAAc;oBACnC,0BAA0B,EAAE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;iBACjD,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
export function loadConfig() {
|
|
3
|
+
const projectRoot = path.resolve(process.env.MAGENTO_PROJECT_ROOT?.trim() || process.cwd());
|
|
4
|
+
const parsedMax = Number.parseInt(process.env.MAGENTO_MAX_FILE_BYTES || "500000", 10);
|
|
5
|
+
return {
|
|
6
|
+
projectRoot,
|
|
7
|
+
reviewProfile: process.env.MAGENTO_REVIEW_PROFILE || "standard",
|
|
8
|
+
maxFileBytes: Number.isFinite(parsedMax) && parsedMax > 0 ? parsedMax : 500000
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAQ7B,MAAM,UAAU,UAAU;IACxB,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAC9B,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,IAAI,EAAE,IAAI,OAAO,CAAC,GAAG,EAAE,CAC1D,CAAC;IACF,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,QAAQ,EAAE,EAAE,CAAC,CAAC;IAEtF,OAAO;QACL,WAAW;QACX,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,UAAU;QAC/D,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM;KAC/E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AppConfig } from "./config.js";
|
|
2
|
+
export declare function resolveProjectPath(config: AppConfig, requestedPath?: string): string;
|
|
3
|
+
export declare function exists(filePath: string): Promise<boolean>;
|
|
4
|
+
export declare function readJson(filePath: string): Promise<Record<string, unknown> | null>;
|
|
5
|
+
export declare function detectProject(config: AppConfig): Promise<{
|
|
6
|
+
isMagentoProject: boolean;
|
|
7
|
+
projectRoot: string;
|
|
8
|
+
composerJsonFound: boolean;
|
|
9
|
+
editionHint: string;
|
|
10
|
+
phpConstraint: string;
|
|
11
|
+
magentoPackages: {
|
|
12
|
+
name: string;
|
|
13
|
+
version: string;
|
|
14
|
+
}[];
|
|
15
|
+
appCodeExists: boolean;
|
|
16
|
+
envPhpExists: boolean;
|
|
17
|
+
note: string;
|
|
18
|
+
}>;
|
|
19
|
+
export declare function listCustomModules(config: AppConfig): Promise<{
|
|
20
|
+
vendor: string;
|
|
21
|
+
module: string;
|
|
22
|
+
path: string;
|
|
23
|
+
}[]>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
export function resolveProjectPath(config, requestedPath = ".") {
|
|
4
|
+
const root = path.resolve(config.projectRoot);
|
|
5
|
+
const target = path.resolve(root, requestedPath);
|
|
6
|
+
if (target !== root && !target.startsWith(root + path.sep)) {
|
|
7
|
+
throw new Error("Requested path is outside MAGENTO_PROJECT_ROOT.");
|
|
8
|
+
}
|
|
9
|
+
return target;
|
|
10
|
+
}
|
|
11
|
+
export async function exists(filePath) {
|
|
12
|
+
try {
|
|
13
|
+
await fs.access(filePath);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export async function readJson(filePath) {
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(await fs.readFile(filePath, "utf8"));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export async function detectProject(config) {
|
|
29
|
+
const root = config.projectRoot;
|
|
30
|
+
const composerPath = path.join(root, "composer.json");
|
|
31
|
+
const appCodePath = path.join(root, "app", "code");
|
|
32
|
+
const composer = await readJson(composerPath);
|
|
33
|
+
const isMagento = Boolean(composer &&
|
|
34
|
+
(await exists(path.join(root, "app", "bootstrap.php")) ||
|
|
35
|
+
await exists(path.join(root, "bin", "magento")) ||
|
|
36
|
+
(composer.require && typeof composer.require === "object" &&
|
|
37
|
+
Object.keys(composer.require).some(k => k.startsWith("magento/")))));
|
|
38
|
+
const require = (composer?.require ?? {});
|
|
39
|
+
const requireDev = (composer?.["require-dev"] ?? {});
|
|
40
|
+
const magentoPackages = Object.entries({ ...require, ...requireDev })
|
|
41
|
+
.filter(([name]) => name.startsWith("magento/") || name.startsWith("magento2/"))
|
|
42
|
+
.map(([name, version]) => ({ name, version }));
|
|
43
|
+
return {
|
|
44
|
+
isMagentoProject: isMagento,
|
|
45
|
+
projectRoot: root,
|
|
46
|
+
composerJsonFound: Boolean(composer),
|
|
47
|
+
editionHint: require["magento/product-enterprise-edition"]
|
|
48
|
+
? "Adobe Commerce (enterprise package detected)"
|
|
49
|
+
: require["magento/product-community-edition"]
|
|
50
|
+
? "Magento Open Source (community package detected)"
|
|
51
|
+
: "Not determined from root Composer requirements",
|
|
52
|
+
phpConstraint: require.php ?? requireDev.php ?? null,
|
|
53
|
+
magentoPackages,
|
|
54
|
+
appCodeExists: await exists(appCodePath),
|
|
55
|
+
envPhpExists: await exists(path.join(root, "app", "etc", "env.php")),
|
|
56
|
+
note: "For security, app/etc/env.php is checked for existence only; its contents are never read."
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export async function listCustomModules(config) {
|
|
60
|
+
const appCode = resolveProjectPath(config, "app/code");
|
|
61
|
+
if (!(await exists(appCode)))
|
|
62
|
+
return [];
|
|
63
|
+
const vendors = await fs.readdir(appCode, { withFileTypes: true });
|
|
64
|
+
const modules = [];
|
|
65
|
+
for (const vendor of vendors) {
|
|
66
|
+
if (!vendor.isDirectory())
|
|
67
|
+
continue;
|
|
68
|
+
const vendorPath = path.join(appCode, vendor.name);
|
|
69
|
+
const entries = await fs.readdir(vendorPath, { withFileTypes: true });
|
|
70
|
+
for (const entry of entries) {
|
|
71
|
+
if (entry.isDirectory()) {
|
|
72
|
+
const modulePath = path.join(vendorPath, entry.name);
|
|
73
|
+
if (await exists(path.join(modulePath, "registration.php"))) {
|
|
74
|
+
modules.push({
|
|
75
|
+
vendor: vendor.name,
|
|
76
|
+
module: entry.name,
|
|
77
|
+
path: path.relative(config.projectRoot, modulePath).split(path.sep).join("/")
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return modules;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=project.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project.js","sourceRoot":"","sources":["../../src/core/project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,MAAM,UAAU,kBAAkB,CAAC,MAAiB,EAAE,aAAa,GAAG,GAAG;IACvE,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IACjD,IAAI,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3D,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,QAAgB;IAC3C,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,QAAgB;IAC7C,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM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M,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QACnD,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;QACtE,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC5B,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;gBACxB,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;gBACrD,IAAI,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC;oBAC5D,OAAO,CAAC,IAAI,CAAC;wBACX,MAAM,EAAE,MAAM,CAAC,IAAI;wBACnB,MAAM,EAAE,KAAK,CAAC,IAAI;wBAClB,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;qBAC9E,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { loadConfig } from "./core/config.js";
|
|
5
|
+
import { registerTools } from "./tools/register.js";
|
|
6
|
+
async function main() {
|
|
7
|
+
const config = loadConfig();
|
|
8
|
+
const server = new McpServer({
|
|
9
|
+
name: "magento-architect-ai",
|
|
10
|
+
version: "0.1.0"
|
|
11
|
+
});
|
|
12
|
+
registerTools(server, config);
|
|
13
|
+
const transport = new StdioServerTransport();
|
|
14
|
+
await server.connect(transport);
|
|
15
|
+
}
|
|
16
|
+
main().catch((error) => {
|
|
17
|
+
// MCP stdio protocol uses stdout; diagnostics must go to stderr.
|
|
18
|
+
console.error("Magento Architect AI failed to start:", error);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;QAC3B,IAAI,EAAE,sBAAsB;QAC5B,OAAO,EAAE,OAAO;KACjB,CAAC,CAAC;IAEH,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC9B,iEAAiE;IACjE,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAC;IAC9D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { detectProject, listCustomModules, resolveProjectPath } from "../core/project.js";
|
|
5
|
+
import { analyzePhp } from "../analyzers/php-heuristics.js";
|
|
6
|
+
function result(data) {
|
|
7
|
+
return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
|
|
8
|
+
}
|
|
9
|
+
export function registerTools(server, config) {
|
|
10
|
+
server.registerTool("detect_magento_project", {
|
|
11
|
+
title: "Detect Magento Project",
|
|
12
|
+
description: "Detect Magento edition hints, PHP constraints, Composer packages and project markers. Does not read env.php contents."
|
|
13
|
+
}, async () => result(await detectProject(config)));
|
|
14
|
+
server.registerTool("get_project_context", {
|
|
15
|
+
title: "Get Magento Project Context",
|
|
16
|
+
description: "Return safe, high-level project context from composer.json and known project markers."
|
|
17
|
+
}, async () => {
|
|
18
|
+
const detected = await detectProject(config);
|
|
19
|
+
return result({
|
|
20
|
+
...detected,
|
|
21
|
+
reviewProfile: config.reviewProfile,
|
|
22
|
+
reviewScope: "Local source inspection; no production database or remote service access."
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
server.registerTool("list_custom_modules", {
|
|
26
|
+
title: "List Custom Magento Modules",
|
|
27
|
+
description: "List modules under app/code that contain registration.php."
|
|
28
|
+
}, async () => result(await listCustomModules(config)));
|
|
29
|
+
server.registerTool("review_file", {
|
|
30
|
+
title: "Review PHP File",
|
|
31
|
+
description: "Run initial deterministic PHP heuristics against a PHP file inside the configured Magento project. This is not a complete security or quality audit.",
|
|
32
|
+
inputSchema: {
|
|
33
|
+
filePath: z.string().min(1).describe("Path relative to the Magento project root")
|
|
34
|
+
}
|
|
35
|
+
}, async ({ filePath }) => {
|
|
36
|
+
const absolute = resolveProjectPath(config, filePath);
|
|
37
|
+
if (path.extname(absolute).toLowerCase() !== ".php") {
|
|
38
|
+
throw new Error("Only PHP files are supported by this initial analyzer.");
|
|
39
|
+
}
|
|
40
|
+
const stat = await fs.stat(absolute);
|
|
41
|
+
if (!stat.isFile())
|
|
42
|
+
throw new Error("Requested path is not a file.");
|
|
43
|
+
if (stat.size > config.maxFileBytes) {
|
|
44
|
+
throw new Error(`File exceeds configured size limit (${config.maxFileBytes} bytes).`);
|
|
45
|
+
}
|
|
46
|
+
const source = await fs.readFile(absolute, "utf8");
|
|
47
|
+
return result({
|
|
48
|
+
filePath: path.relative(config.projectRoot, absolute).split(path.sep).join("/"),
|
|
49
|
+
findings: analyzePhp(source),
|
|
50
|
+
summary: "Initial heuristic scan only. Validate findings in context; PHPCS, PHPStan, Semgrep and advanced Magento rules are not yet integrated."
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/tools/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC1F,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAE5D,SAAS,MAAM,CAAC,IAAa;IAC3B,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AACvF,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,MAAiB,EAAE,MAAiB;IAChE,MAAM,CAAC,YAAY,CACjB,wBAAwB,EACxB;QACE,KAAK,EAAE,wBAAwB;QAC/B,WAAW,EAAE,uHAAuH;KACrI,EACD,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC,MAAM,aAAa,CAAC,MAAM,CAAC,CAAC,CAChD,CAAC;IAEF,MAAM,CA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,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,uCAAuC,MAAM,CAAC,YAAY,UAAU,CAAC,CAAC;QACxF,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACnD,OAAO,MAAM,CAAC;YACZ,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;YAC/E,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC;YAC5B,OAAO,EAAE,uIAAuI;SACjJ,CAAC,CAAC;IACL,CAAC,CACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "magento2-code-review-agent",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Local-first MCP server for Adobe Commerce and Magento 2 project inspection and code review.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"magento2-code-review-agent": "dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=20"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc -p tsconfig.json",
|
|
15
|
+
"start": "node dist/index.js",
|
|
16
|
+
"dev": "tsx src/index.ts",
|
|
17
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
18
|
+
"prepare": "npm run build"
|
|
19
|
+
},
|
|
20
|
+
"keywords": ["mcp", "magento", "adobe-commerce", "code-review", "cursor"],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
24
|
+
"zod": "^3.25.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^22.0.0",
|
|
28
|
+
"tsx": "^4.19.0",
|
|
29
|
+
"typescript": "^5.7.0"
|
|
30
|
+
}
|
|
31
|
+
}
|