magector 2.6.2 → 2.6.4
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 +5 -5
- package/src/mcp-server.js +46 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "magector",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.4",
|
|
4
4
|
"description": "Semantic code search for Magento 2 — index, search, MCP server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/mcp-server.js",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"ruvector": "^0.1.96"
|
|
34
34
|
},
|
|
35
35
|
"optionalDependencies": {
|
|
36
|
-
"@magector/cli-darwin-arm64": "2.6.
|
|
37
|
-
"@magector/cli-linux-x64": "2.6.
|
|
38
|
-
"@magector/cli-linux-arm64": "2.6.
|
|
39
|
-
"@magector/cli-win32-x64": "2.6.
|
|
36
|
+
"@magector/cli-darwin-arm64": "2.6.4",
|
|
37
|
+
"@magector/cli-linux-x64": "2.6.4",
|
|
38
|
+
"@magector/cli-linux-arm64": "2.6.4",
|
|
39
|
+
"@magector/cli-win32-x64": "2.6.4"
|
|
40
40
|
},
|
|
41
41
|
"keywords": [
|
|
42
42
|
"magento",
|
package/src/mcp-server.js
CHANGED
|
@@ -4156,6 +4156,52 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
4156
4156
|
);
|
|
4157
4157
|
results = results.concat(pathFallback);
|
|
4158
4158
|
}
|
|
4159
|
+
// Filesystem fallback: use grep to find method definition across all PHP files
|
|
4160
|
+
if (results.length === 0 && config.magentoRoot) {
|
|
4161
|
+
try {
|
|
4162
|
+
const methodSig = `function ${args.methodName}(`;
|
|
4163
|
+
// Use className to narrow search if provided, otherwise grep all PHP
|
|
4164
|
+
const classShort = args.className ? args.className.split('\\').pop() : null;
|
|
4165
|
+
let files = [];
|
|
4166
|
+
if (classShort) {
|
|
4167
|
+
files = await glob(`**/${classShort}.php`, { cwd: config.magentoRoot, absolute: false, nodir: true });
|
|
4168
|
+
} else {
|
|
4169
|
+
// Use grep -rl for fast search across all PHP files (much faster than reading each file)
|
|
4170
|
+
try {
|
|
4171
|
+
const grepResult = execFileSync('grep', ['-rl', '--include=*.php', methodSig, '.'],
|
|
4172
|
+
{ cwd: config.magentoRoot, encoding: 'utf-8', timeout: 15000, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
4173
|
+
files = grepResult.trim().split('\n').filter(Boolean).map(f => f.replace(/^\.\//, ''));
|
|
4174
|
+
} catch {
|
|
4175
|
+
// grep returns exit code 1 when no matches — fall through with empty files
|
|
4176
|
+
}
|
|
4177
|
+
}
|
|
4178
|
+
for (const f of files.slice(0, 20)) {
|
|
4179
|
+
const absPath = f.startsWith('/') ? f : path.join(config.magentoRoot, f);
|
|
4180
|
+
let content;
|
|
4181
|
+
try { content = readFileSync(absPath, 'utf-8'); } catch { continue; }
|
|
4182
|
+
if (!content.includes(methodSig)) continue;
|
|
4183
|
+
let className = null;
|
|
4184
|
+
const nsMatch = content.match(/namespace\s+([\w\\]+)/);
|
|
4185
|
+
const classMatch = content.match(/class\s+(\w+)/);
|
|
4186
|
+
if (nsMatch && classMatch) className = nsMatch[1] + '\\' + classMatch[1];
|
|
4187
|
+
const methodsFound = [];
|
|
4188
|
+
const mRegex = /public\s+function\s+(\w+)\s*\(/g;
|
|
4189
|
+
let mm;
|
|
4190
|
+
while ((mm = mRegex.exec(content)) !== null) methodsFound.push(mm[1]);
|
|
4191
|
+
const body = readFullMethodBody(absPath, args.methodName);
|
|
4192
|
+
results.push({
|
|
4193
|
+
path: f,
|
|
4194
|
+
className,
|
|
4195
|
+
methods: methodsFound,
|
|
4196
|
+
methodName: args.methodName,
|
|
4197
|
+
score: 0.5,
|
|
4198
|
+
searchText: content.slice(0, 300),
|
|
4199
|
+
fullMethodBody: body || undefined
|
|
4200
|
+
});
|
|
4201
|
+
if (results.length >= 5) break;
|
|
4202
|
+
}
|
|
4203
|
+
} catch {}
|
|
4204
|
+
}
|
|
4159
4205
|
// Boost exact method matches to top
|
|
4160
4206
|
results = results.map(r => {
|
|
4161
4207
|
let bonus = 0;
|