mcp-mat 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 (63) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +190 -0
  3. package/dist/src/config.d.ts +18 -0
  4. package/dist/src/config.js +173 -0
  5. package/dist/src/config.js.map +1 -0
  6. package/dist/src/logging.d.ts +23 -0
  7. package/dist/src/logging.js +76 -0
  8. package/dist/src/logging.js.map +1 -0
  9. package/dist/src/mat/artifacts.d.ts +20 -0
  10. package/dist/src/mat/artifacts.js +200 -0
  11. package/dist/src/mat/artifacts.js.map +1 -0
  12. package/dist/src/mat/commandBuilder.d.ts +25 -0
  13. package/dist/src/mat/commandBuilder.js +90 -0
  14. package/dist/src/mat/commandBuilder.js.map +1 -0
  15. package/dist/src/mat/errorClassifier.d.ts +3 -0
  16. package/dist/src/mat/errorClassifier.js +98 -0
  17. package/dist/src/mat/errorClassifier.js.map +1 -0
  18. package/dist/src/mat/launcher.d.ts +6 -0
  19. package/dist/src/mat/launcher.js +89 -0
  20. package/dist/src/mat/launcher.js.map +1 -0
  21. package/dist/src/mat/oqlSpec.d.ts +3 -0
  22. package/dist/src/mat/oqlSpec.js +78 -0
  23. package/dist/src/mat/oqlSpec.js.map +1 -0
  24. package/dist/src/mat/runner.d.ts +3 -0
  25. package/dist/src/mat/runner.js +80 -0
  26. package/dist/src/mat/runner.js.map +1 -0
  27. package/dist/src/mat/service.d.ts +57 -0
  28. package/dist/src/mat/service.js +415 -0
  29. package/dist/src/mat/service.js.map +1 -0
  30. package/dist/src/security/pathGuard.d.ts +2 -0
  31. package/dist/src/security/pathGuard.js +63 -0
  32. package/dist/src/security/pathGuard.js.map +1 -0
  33. package/dist/src/server.d.ts +1 -0
  34. package/dist/src/server.js +88 -0
  35. package/dist/src/server.js.map +1 -0
  36. package/dist/src/tools/dispatcher.d.ts +3 -0
  37. package/dist/src/tools/dispatcher.js +69 -0
  38. package/dist/src/tools/dispatcher.js.map +1 -0
  39. package/dist/src/tools/matHealthcheck.d.ts +3 -0
  40. package/dist/src/tools/matHealthcheck.js +19 -0
  41. package/dist/src/tools/matHealthcheck.js.map +1 -0
  42. package/dist/src/tools/matIndexStatus.d.ts +3 -0
  43. package/dist/src/tools/matIndexStatus.js +19 -0
  44. package/dist/src/tools/matIndexStatus.js.map +1 -0
  45. package/dist/src/tools/matOqlQuery.d.ts +3 -0
  46. package/dist/src/tools/matOqlQuery.js +19 -0
  47. package/dist/src/tools/matOqlQuery.js.map +1 -0
  48. package/dist/src/tools/matOqlSpec.d.ts +3 -0
  49. package/dist/src/tools/matOqlSpec.js +19 -0
  50. package/dist/src/tools/matOqlSpec.js.map +1 -0
  51. package/dist/src/tools/matParseReport.d.ts +3 -0
  52. package/dist/src/tools/matParseReport.js +19 -0
  53. package/dist/src/tools/matParseReport.js.map +1 -0
  54. package/dist/src/tools/matRunCommand.d.ts +3 -0
  55. package/dist/src/tools/matRunCommand.js +19 -0
  56. package/dist/src/tools/matRunCommand.js.map +1 -0
  57. package/dist/src/tools/schemas.d.ts +231 -0
  58. package/dist/src/tools/schemas.js +165 -0
  59. package/dist/src/tools/schemas.js.map +1 -0
  60. package/dist/src/types.d.ts +102 -0
  61. package/dist/src/types.js +41 -0
  62. package/dist/src/types.js.map +1 -0
  63. package/package.json +45 -0
@@ -0,0 +1,76 @@
1
+ // Copyright 2025 Penghui Li
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import crypto from "node:crypto";
15
+ import fs from "node:fs";
16
+ import path from "node:path";
17
+ export function createRequestContext(tool, heapPath, privacyMode) {
18
+ const requestId = crypto.randomUUID();
19
+ const heapPathDisplay = heapPath
20
+ ? privacyMode
21
+ ? `sha256:${crypto.createHash("sha256").update(heapPath).digest("hex")}`
22
+ : heapPath
23
+ : undefined;
24
+ return {
25
+ requestId,
26
+ tool,
27
+ heapPathDisplay,
28
+ startedAtMs: Date.now(),
29
+ };
30
+ }
31
+ export function logRequestStart(context) {
32
+ process.stderr.write(`${JSON.stringify({
33
+ event: "request_start",
34
+ request_id: context.requestId,
35
+ tool: context.tool,
36
+ heap: context.heapPathDisplay,
37
+ ts: new Date().toISOString(),
38
+ })}\n`);
39
+ }
40
+ export function logRequestEnd(context, params) {
41
+ process.stderr.write(`${JSON.stringify({
42
+ event: "request_end",
43
+ request_id: context.requestId,
44
+ tool: context.tool,
45
+ heap: context.heapPathDisplay,
46
+ status: params.status,
47
+ category: params.category,
48
+ exit_code: params.exitCode ?? null,
49
+ elapsed_ms: params.elapsedMs,
50
+ artifacts: params.artifacts ?? [],
51
+ ts: new Date().toISOString(),
52
+ })}\n`);
53
+ }
54
+ export function persistDebugLog(params) {
55
+ if (!params.enabled) {
56
+ return;
57
+ }
58
+ fs.mkdirSync(params.logDir, { recursive: true });
59
+ const logPath = path.join(params.logDir, `${params.context.requestId}.log`);
60
+ const payload = {
61
+ request_id: params.context.requestId,
62
+ tool: params.context.tool,
63
+ heap: params.context.heapPathDisplay,
64
+ started_at: new Date(params.context.startedAtMs).toISOString(),
65
+ duration_ms: params.run.durationMs,
66
+ exit_code: params.run.exitCode,
67
+ signal: params.run.signal,
68
+ timed_out: params.run.timedOut,
69
+ command: params.privacyMode ? "[redacted]" : params.run.command,
70
+ args: params.privacyMode ? ["[redacted]"] : params.run.args,
71
+ stdout: params.run.stdout,
72
+ stderr: params.run.stderr,
73
+ };
74
+ fs.writeFileSync(logPath, JSON.stringify(payload, null, 2));
75
+ }
76
+ //# sourceMappingURL=logging.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logging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CAAC,GAAG,CAAC,QAAQ;QAC9B,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO;QAC/D,IAAI,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI;QAC3D,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM;QACzB,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM;KAC1B,CAAC;IACF,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,20 @@
1
+ export interface QueryArtifacts {
2
+ queryDir: string | null;
3
+ queryZip: string | null;
4
+ resultTxt: string | null;
5
+ generatedFiles: string[];
6
+ }
7
+ export interface ReportArtifacts {
8
+ reportDir: string | null;
9
+ reportZip: string | null;
10
+ generatedFiles: string[];
11
+ }
12
+ export interface IndexArtifacts {
13
+ indexPresent: boolean;
14
+ indexFiles: string[];
15
+ threadsFile: string | null;
16
+ lastModified: string | null;
17
+ }
18
+ export declare function resolveQueryArtifacts(heapPath: string, startedAtMs?: number): QueryArtifacts;
19
+ export declare function resolveReportArtifacts(heapPath: string, startedAtMs?: number): ReportArtifacts;
20
+ export declare function resolveIndexArtifacts(heapPath: string): IndexArtifacts;
@@ -0,0 +1,200 @@
1
+ // Copyright 2025 Penghui Li
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import fs from "node:fs";
15
+ import path from "node:path";
16
+ function heapBases(heapPath) {
17
+ const base = path.basename(heapPath);
18
+ const stem = path.parse(heapPath).name;
19
+ return [...new Set([base, stem])];
20
+ }
21
+ function safeReadDir(directory) {
22
+ try {
23
+ return fs.readdirSync(directory, { withFileTypes: true });
24
+ }
25
+ catch {
26
+ return [];
27
+ }
28
+ }
29
+ function latestByMtime(paths) {
30
+ if (paths.length === 0)
31
+ return null;
32
+ const entries = paths
33
+ .map((p) => {
34
+ try {
35
+ return { p, mtime: fs.statSync(p).mtimeMs };
36
+ }
37
+ catch {
38
+ return null;
39
+ }
40
+ })
41
+ .filter((entry) => entry !== null);
42
+ if (entries.length === 0)
43
+ return null;
44
+ return entries.sort((a, b) => b.mtime - a.mtime)[0].p;
45
+ }
46
+ function isRecentEnough(fullPath, startedAtMs) {
47
+ if (startedAtMs === undefined)
48
+ return true;
49
+ try {
50
+ return fs.statSync(fullPath).mtimeMs >= startedAtMs - 2000;
51
+ }
52
+ catch {
53
+ return false;
54
+ }
55
+ }
56
+ function discoverGeneratedNearHeap(heapPath, startedAtMs) {
57
+ const parent = path.dirname(heapPath);
58
+ const bases = heapBases(heapPath);
59
+ const entries = safeReadDir(parent);
60
+ return entries
61
+ .filter((entry) => {
62
+ const matchesBase = bases.some((base) => entry.name.startsWith(base));
63
+ if (!matchesBase) {
64
+ return false;
65
+ }
66
+ if (entry.name === path.basename(heapPath)) {
67
+ return false;
68
+ }
69
+ const fullPath = path.join(parent, entry.name);
70
+ return isRecentEnough(fullPath, startedAtMs);
71
+ })
72
+ .map((entry) => path.join(parent, entry.name))
73
+ .sort();
74
+ }
75
+ function findQueryCommandText(queryDir, startedAtMs) {
76
+ const pagesDir = path.join(queryDir, "pages");
77
+ if (!fs.existsSync(pagesDir) || !fs.statSync(pagesDir).isDirectory()) {
78
+ return null;
79
+ }
80
+ const candidates = safeReadDir(pagesDir)
81
+ .filter((entry) => entry.isFile() && /^Query_Command[_\d]*\d+\.txt$/.test(entry.name))
82
+ .map((entry) => path.join(pagesDir, entry.name))
83
+ .filter((fullPath) => isRecentEnough(fullPath, startedAtMs));
84
+ return latestByMtime(candidates);
85
+ }
86
+ export function resolveQueryArtifacts(heapPath, startedAtMs) {
87
+ const parent = path.dirname(heapPath);
88
+ const bases = heapBases(heapPath);
89
+ const queryDirCandidates = [];
90
+ const queryZipCandidates = [];
91
+ // Directories whose own mtime is stale but may contain recently-updated files
92
+ const staleDirCandidates = [];
93
+ for (const entry of safeReadDir(parent)) {
94
+ const fullPath = path.join(parent, entry.name);
95
+ const isMatchingQuery = bases.some((base) => entry.name === `${base}_Query` || entry.name.startsWith(`${base}_Query`));
96
+ if (!isMatchingQuery) {
97
+ continue;
98
+ }
99
+ if (entry.isDirectory()) {
100
+ if (isRecentEnough(fullPath, startedAtMs)) {
101
+ queryDirCandidates.push(fullPath);
102
+ }
103
+ else {
104
+ staleDirCandidates.push(fullPath);
105
+ }
106
+ }
107
+ if (entry.isFile() && entry.name.endsWith(".zip")) {
108
+ if (isRecentEnough(fullPath, startedAtMs)) {
109
+ queryZipCandidates.push(fullPath);
110
+ }
111
+ }
112
+ }
113
+ const queryDir = latestByMtime(queryDirCandidates);
114
+ const queryZip = latestByMtime(queryZipCandidates);
115
+ // Look for result txt in a recent directory first, then fall back to stale
116
+ // directories whose individual files may have been updated (overwriting an
117
+ // existing file does not bump the parent directory mtime on macOS/Linux).
118
+ let resultTxt = queryDir ? findQueryCommandText(queryDir, startedAtMs) : null;
119
+ if (!resultTxt) {
120
+ for (const staleDir of staleDirCandidates) {
121
+ resultTxt = findQueryCommandText(staleDir, startedAtMs);
122
+ if (resultTxt)
123
+ break;
124
+ }
125
+ }
126
+ const generated = discoverGeneratedNearHeap(heapPath, startedAtMs);
127
+ if (resultTxt && !generated.includes(resultTxt)) {
128
+ generated.push(resultTxt);
129
+ generated.sort();
130
+ }
131
+ return {
132
+ queryDir: queryDir ?? (resultTxt ? path.dirname(path.dirname(resultTxt)) : null),
133
+ queryZip,
134
+ resultTxt,
135
+ generatedFiles: generated,
136
+ };
137
+ }
138
+ export function resolveReportArtifacts(heapPath, startedAtMs) {
139
+ const generated = discoverGeneratedNearHeap(heapPath, startedAtMs);
140
+ const dirs = generated.filter((item) => {
141
+ try {
142
+ return fs.statSync(item).isDirectory();
143
+ }
144
+ catch {
145
+ return false;
146
+ }
147
+ });
148
+ const zips = generated.filter((item) => item.endsWith(".zip"));
149
+ return {
150
+ reportDir: latestByMtime(dirs),
151
+ reportZip: latestByMtime(zips),
152
+ generatedFiles: generated,
153
+ };
154
+ }
155
+ export function resolveIndexArtifacts(heapPath) {
156
+ const parent = path.dirname(heapPath);
157
+ // MAT names index files using the heap stem (without extension):
158
+ // heap.hprof -> heap.index, heap.idx.index, heap.threads, etc.
159
+ const heapStem = path.parse(heapPath).name;
160
+ const indexFiles = [];
161
+ let threadsFile = null;
162
+ let lastModifiedMs = 0;
163
+ for (const entry of safeReadDir(parent)) {
164
+ if (!entry.isFile()) {
165
+ continue;
166
+ }
167
+ const fullPath = path.join(parent, entry.name);
168
+ if (!entry.name.startsWith(heapStem)) {
169
+ continue;
170
+ }
171
+ const isIndex = entry.name.includes(".index");
172
+ const isThreads = entry.name.endsWith(".threads") || entry.name.includes("threads");
173
+ if (!isIndex && !isThreads) {
174
+ continue;
175
+ }
176
+ let mtimeMs;
177
+ try {
178
+ mtimeMs = fs.statSync(fullPath).mtimeMs;
179
+ }
180
+ catch {
181
+ continue;
182
+ }
183
+ if (mtimeMs > lastModifiedMs) {
184
+ lastModifiedMs = mtimeMs;
185
+ }
186
+ if (isIndex) {
187
+ indexFiles.push(fullPath);
188
+ }
189
+ if (isThreads && threadsFile === null) {
190
+ threadsFile = fullPath;
191
+ }
192
+ }
193
+ return {
194
+ indexPresent: indexFiles.length > 0,
195
+ indexFiles: indexFiles.sort(),
196
+ threadsFile,
197
+ lastModified: lastModifiedMs > 0 ? new Date(lastModifiedMs).toISOString() : null,
198
+ };
199
+ }
200
+ //# sourceMappingURL=artifacts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"artifacts.js","sourceRoot":"","sources":["../../../src/mat/artifacts.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAsB7B,SAAS,SAAS,CAAC,QAAgB;IACjC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACrC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC;IACvC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,WAAW,CAAC,SAAiB;IACpC,IAAI,CAAC;QACH,OAAO,EAAE,CAAC,WAAW,CAAC,SAAS,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,KAAe;IACpC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACpC,MAAM,OAAO,GAAG,KAAK;SAClB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACT,IAAI,CAAC;YACH,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QAC9C,CAAC;QAAC,MAAM,CAAC;YACP,O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OAAe,CAAC;QACpB,IAAI,CAAC;YACH,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC;QAC1C,CAAC;QAAC,MAAM,CAAC;YACP,SAAS;QACX,CAAC;QACD,IAAI,OAAO,GAAG,cAAc,EAAE,CAAC;YAC7B,cAAc,GAAG,OAAO,CAAC;QAC3B,CAAC;QAED,IAAI,OAAO,EAAE,CAAC;YACZ,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC5B,CAAC;QAED,IAAI,SAAS,IAAI,WAAW,KAAK,IAAI,EAAE,CAAC;YACtC,WAAW,GAAG,QAAQ,CAAC;QACzB,CAAC;IACH,CAAC;IAED,OAAO;QACL,YAAY,EAAE,UAAU,CAAC,MAAM,GAAG,CAAC;QACnC,UAAU,EAAE,UAAU,CAAC,IAAI,EAAE;QAC7B,WAAW;QACX,YAAY,EAAE,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI;KACjF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { RunCommand } from "../types.js";
2
+ export interface BaseMatCommandArgs {
3
+ javaPath: string;
4
+ launcherPath: string;
5
+ heapPath: string;
6
+ configDir: string;
7
+ dataDir: string;
8
+ xmxMb: number;
9
+ timeoutSec: number;
10
+ }
11
+ export declare function formatOqlForMatCommand(oql: string): string;
12
+ export declare function buildParseReportCommand(base: BaseMatCommandArgs, reportId: string, options?: Record<string, string | number | boolean>): RunCommand;
13
+ export declare function buildOqlCommand(base: BaseMatCommandArgs, params: {
14
+ oql: string;
15
+ format: "txt" | "html" | "csv";
16
+ unzip: boolean;
17
+ limit?: number;
18
+ }): RunCommand;
19
+ export declare function buildGenericCommand(base: BaseMatCommandArgs, params: {
20
+ commandName: string;
21
+ commandArgs?: string;
22
+ format: "txt" | "html" | "csv";
23
+ unzip: boolean;
24
+ limit?: number;
25
+ }): RunCommand;
@@ -0,0 +1,90 @@
1
+ // Copyright 2025 Penghui Li
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ const ASM_EXPORT = "--add-exports=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED";
15
+ const PARSE_APP_ID = "org.eclipse.mat.api.parse";
16
+ function buildCommonArgs(base) {
17
+ return [
18
+ `-Xmx${base.xmxMb}m`,
19
+ ASM_EXPORT,
20
+ "-jar",
21
+ base.launcherPath,
22
+ "-consolelog",
23
+ "-nosplash",
24
+ "-configuration",
25
+ base.configDir,
26
+ "-data",
27
+ base.dataDir,
28
+ "-application",
29
+ PARSE_APP_ID,
30
+ base.heapPath,
31
+ ];
32
+ }
33
+ function optionToArg(key, value) {
34
+ if (typeof value === "boolean") {
35
+ return value ? `-${key}` : `-${key}=false`;
36
+ }
37
+ if (typeof value === "number") {
38
+ return `-${key}=${value}`;
39
+ }
40
+ if (value.trim().length === 0) {
41
+ return null;
42
+ }
43
+ return `-${key}=${value}`;
44
+ }
45
+ export function formatOqlForMatCommand(oql) {
46
+ const escaped = oql.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
47
+ return `"${escaped}"`;
48
+ }
49
+ export function buildParseReportCommand(base, reportId, options) {
50
+ const args = buildCommonArgs(base);
51
+ for (const [key, value] of Object.entries(options ?? {})) {
52
+ const arg = optionToArg(key, value);
53
+ if (arg) {
54
+ args.push(arg);
55
+ }
56
+ }
57
+ args.push(reportId);
58
+ return {
59
+ command: base.javaPath,
60
+ args,
61
+ timeoutSec: base.timeoutSec,
62
+ };
63
+ }
64
+ function buildQueryStyleCommand(base, commandStr, params) {
65
+ const args = buildCommonArgs(base);
66
+ args.push(`-command=${commandStr}`);
67
+ args.push(`-format=${params.format}`);
68
+ if (params.unzip) {
69
+ args.push("-unzip");
70
+ }
71
+ if (params.limit !== undefined) {
72
+ args.push(`-limit=${params.limit}`);
73
+ }
74
+ args.push("org.eclipse.mat.api:query");
75
+ return {
76
+ command: base.javaPath,
77
+ args,
78
+ timeoutSec: base.timeoutSec,
79
+ };
80
+ }
81
+ export function buildOqlCommand(base, params) {
82
+ return buildQueryStyleCommand(base, `oql ${formatOqlForMatCommand(params.oql)}`, params);
83
+ }
84
+ export function buildGenericCommand(base, params) {
85
+ const commandStr = params.commandArgs
86
+ ? `${params.commandName} ${params.commandArgs}`
87
+ : params.commandName;
88
+ return buildQueryStyleCommand(base, commandStr, params);
89
+ }
90
+ //# sourceMappingURL=commandBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commandBuilder.js","sourceRoot":"","sources":["../../../src/mat/commandBuilder.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,MAAM,UAAU,GAAG,oEAAoE,CAAC;AACxF,MAAM,YAAY,GAAG,2BAA2B,CAAC;AAYjD,SAAS,eAAe,CAAC,IAAwB;IAC/C,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,GAAG;QACpB,UAAU;QACV,MAAM;QACN,IAAI,CAAC,YAAY;QACjB,aAAa;QACb,WAAW;QACX,gBAAgB;QAChB,IAAI,CAAC,SAAS;QACd,OAAO;QACP,IAAI,CAAC,OAAO;QACZ,cAAc;QACd,YAAY;QACZ,IAAI,CAAC,QAAQ;KACd,CAAC;AACJ,CAAC;AAED,SAAS,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C;AACJ,CAAC;AAED,SAAS,sBAAsB,CAC7B,IAAwB,EACxB,UAAkB,EAClB,MAA0E;IAE1E,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,CAAC,IAAI,CAAC,YAAY,UAAU,EAAE,CAAC,CAAC;IACpC,IAAI,CAAC,IAAI,CAAC,WAAW,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IACtC,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtB,CAAC;IACD,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAC/B,IAAI,CAAC,IAAI,CAAC,UAAU,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IACtC,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;IAEvC,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,QAAQ;QACtB,IAAI;QACJ,UAAU,EAAE,IAAI,CAAC,UAAU;KAC5B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,IAAwB,EACxB,MAKC;IAED,OAAO,sBAAsB,CAC3B,IAAI,EACJ,OAAO,sBAAsB,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAC3C,MAAM,CACP,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,IAAwB,EACxB,MAMC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW;QACnC,CAAC,CAAC,GAAG,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC,WAAW,EAAE;QAC/C,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC;IACvB,OAAO,sBAAsB,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { MatMcpError, type RunResult } from "../types.js";
2
+ export declare function classifyRunFailure(run: RunResult, tailChars: number, timeoutSec?: number): MatMcpError;
3
+ export declare function classifySpawnError(error: unknown): MatMcpError;
@@ -0,0 +1,98 @@
1
+ // Copyright 2025 Penghui Li
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import { tail } from "./runner.js";
15
+ import { MatMcpError } from "../types.js";
16
+ const WRITE_PERMISSION_PATTERNS = [
17
+ /permission denied/i,
18
+ /access is denied/i,
19
+ /read-only file system/i,
20
+ /cannot create/i,
21
+ /failed to create/i,
22
+ /lock\.index/i,
23
+ ];
24
+ const INVALID_QUERY_PATTERNS = [
25
+ /syntax/i,
26
+ /parse error/i,
27
+ /unexpected token/i,
28
+ /invalid query/i,
29
+ /query command/i,
30
+ ];
31
+ function includesPattern(text, patterns) {
32
+ return patterns.some((pattern) => pattern.test(text));
33
+ }
34
+ export function classifyRunFailure(run, tailChars, timeoutSec) {
35
+ const stdoutTail = tail(run.stdout, tailChars);
36
+ const stderrTail = tail(run.stderr, tailChars);
37
+ const merged = `${stdoutTail}\n${stderrTail}`;
38
+ if (run.timedOut) {
39
+ const durationStr = `${Math.round(run.durationMs / 1000)}s`;
40
+ const limitStr = timeoutSec !== undefined ? `, limit ${timeoutSec}s` : "";
41
+ return new MatMcpError({
42
+ category: "MAT_TIMEOUT",
43
+ message: `MAT process exceeded timeout (ran ${durationStr}${limitStr}).`,
44
+ hint: "Increase timeout_sec or run a smaller report/query.",
45
+ stdoutTail,
46
+ stderrTail,
47
+ exitCode: run.exitCode,
48
+ });
49
+ }
50
+ if (includesPattern(merged, WRITE_PERMISSION_PATTERNS)) {
51
+ return new MatMcpError({
52
+ category: "WRITE_PERMISSION_DENIED",
53
+ message: "MAT could not write lock/index/report artifacts near the heap dump.",
54
+ hint: "Grant write permission on the heap directory or analyze a copy in writable storage.",
55
+ stdoutTail,
56
+ stderrTail,
57
+ exitCode: run.exitCode,
58
+ });
59
+ }
60
+ const likelyInvalidQuery = includesPattern(merged, INVALID_QUERY_PATTERNS) && /oql/i.test(merged);
61
+ if (likelyInvalidQuery) {
62
+ return new MatMcpError({
63
+ category: "INVALID_QUERY",
64
+ message: "MAT rejected the OQL query.",
65
+ hint: "Validate OQL syntax and use mat_oql_spec for parser-mode-safe query patterns.",
66
+ stdoutTail,
67
+ stderrTail,
68
+ exitCode: run.exitCode,
69
+ });
70
+ }
71
+ return new MatMcpError({
72
+ category: "MAT_PARSE_FAILED",
73
+ message: "MAT exited with a non-zero status.",
74
+ hint: "Inspect stderr_tail for MAT diagnostics.",
75
+ stdoutTail,
76
+ stderrTail,
77
+ exitCode: run.exitCode,
78
+ });
79
+ }
80
+ export function classifySpawnError(error) {
81
+ const message = error instanceof Error ? error.message : String(error);
82
+ const code = error instanceof Error ? error.code : undefined;
83
+ if (code === "EACCES") {
84
+ return new MatMcpError({
85
+ category: "MAT_NOT_FOUND",
86
+ message: `Permission denied launching MAT process: ${message}`,
87
+ hint: "Ensure JAVA_PATH points to an executable file with proper permissions.",
88
+ });
89
+ }
90
+ return new MatMcpError({
91
+ category: "MAT_NOT_FOUND",
92
+ message: `Failed to launch MAT process: ${message}`,
93
+ hint: code === "ENOENT"
94
+ ? "Java binary not found. Install Java or set JAVA_PATH to a valid java executable."
95
+ : "Verify JAVA_PATH and MAT_LAUNCHER are valid and executable.",
96
+ });
97
+ }
98
+ //# sourceMappingURL=errorClassifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errorClassifier.js","sourceRoot":"","sources":["../../../src/mat/errorClassifier.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,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ExF,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtB,OAAO,IAAI,WAAW,CAAC;YACrB,QAAQ,EAAE,eAAe;YACzB,OAAO,EAAE,4CAA4C,OAAO,EAAE;YAC9D,IAAI,EAAE,wEAAwE;SAC/E,CAAC,CAAC;IACL,CAAC;IAED,OAAO,IAAI,WAAW,CAAC;QACrB,QAAQ,EAAE,eAAe;QACzB,OAAO,EAAE,iCAAiC,OAAO,EAAE;QACnD,IAAI,EAAE,IAAI,KAAK,QAAQ;YACrB,CAAC,CAAC,kFAAkF;YACpF,CAAC,CAAC,6DAA6D;KAClE,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,6 @@
1
+ export interface LauncherOptions {
2
+ matLauncher?: string;
3
+ matHome?: string;
4
+ }
5
+ export declare function resolveMatLauncher(options: LauncherOptions): string;
6
+ export declare function detectJavaVersion(javaPath: string): string;
@@ -0,0 +1,89 @@
1
+ // Copyright 2025 Penghui Li
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import fs from "node:fs";
15
+ import path from "node:path";
16
+ import { spawnSync } from "node:child_process";
17
+ import { MatMcpError } from "../types.js";
18
+ export function resolveMatLauncher(options) {
19
+ if (options.matLauncher) {
20
+ const absolute = path.resolve(options.matLauncher);
21
+ try {
22
+ return fs.realpathSync(absolute);
23
+ }
24
+ catch {
25
+ throw new MatMcpError({
26
+ category: "MAT_NOT_FOUND",
27
+ message: `MAT launcher not found: ${absolute}`,
28
+ hint: "Set MAT_LAUNCHER to a valid org.eclipse.equinox.launcher_*.jar path.",
29
+ });
30
+ }
31
+ }
32
+ if (!options.matHome) {
33
+ throw new MatMcpError({
34
+ category: "MAT_NOT_FOUND",
35
+ message: "MAT launcher is not configured.",
36
+ hint: "Set MAT_LAUNCHER or MAT_HOME before starting the server.",
37
+ });
38
+ }
39
+ const pluginDir = path.join(path.resolve(options.matHome), "plugins");
40
+ if (!fs.existsSync(pluginDir) || !fs.statSync(pluginDir).isDirectory()) {
41
+ throw new MatMcpError({
42
+ category: "MAT_NOT_FOUND",
43
+ message: `MAT plugins directory missing: ${pluginDir}`,
44
+ hint: "Verify MAT_HOME points to the Eclipse MAT installation root.",
45
+ });
46
+ }
47
+ const launcherCandidate = fs
48
+ .readdirSync(pluginDir)
49
+ .filter((name) => /^org\.eclipse\.equinox\.launcher_.*\.jar$/.test(name))
50
+ .sort()
51
+ .at(-1);
52
+ if (!launcherCandidate) {
53
+ throw new MatMcpError({
54
+ category: "MAT_NOT_FOUND",
55
+ message: `No launcher jar found in: ${pluginDir}`,
56
+ hint: "Install Eclipse MAT or configure MAT_LAUNCHER explicitly.",
57
+ });
58
+ }
59
+ return path.join(pluginDir, launcherCandidate);
60
+ }
61
+ export function detectJavaVersion(javaPath) {
62
+ const result = spawnSync(javaPath, ["-version"], {
63
+ encoding: "utf8",
64
+ timeout: 10_000,
65
+ });
66
+ if (result.error) {
67
+ throw new MatMcpError({
68
+ category: "MAT_NOT_FOUND",
69
+ message: `Failed to run Java: ${result.error.message}`,
70
+ hint: "Set JAVA_PATH to a valid java executable.",
71
+ });
72
+ }
73
+ if (result.status !== 0) {
74
+ throw new MatMcpError({
75
+ category: "MAT_NOT_FOUND",
76
+ message: "Java runtime is unavailable.",
77
+ hint: "Install Java and ensure JAVA_PATH points to the java binary.",
78
+ stdoutTail: result.stdout ?? "",
79
+ stderrTail: result.stderr ?? "",
80
+ exitCode: result.status,
81
+ });
82
+ }
83
+ const versionLine = `${result.stderr ?? ""}\n${result.stdout ?? ""}`
84
+ .split("\n")
85
+ .map((line) => line.trim())
86
+ .find((line) => line.length > 0);
87
+ return versionLine ?? "unknown";
88
+ }
89
+ //# sourceMappingURL=launcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launcher.js","sourceRoot":"","sources":["../../../src/mat/launcher.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAO1C,MAAM,UAAU,kBAAkB,CAAC,OAAwB;IACzD,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;QACxB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACnD,IAAI,CAAC;YACH,OAAO,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QACnC,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,WAAW,CAAC;gBACpB,QAAQ,EAAE,eAAe;gBACzB,OAAO,EAAE,2BAA2B,QAAQ,EAAE;gBAC9C,IAAI,EAAE,sEAAsE;aAC7E,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACrB,MAAM,IAAI,WAAW,CAAC;YACpB,QAAQ,EAAE,eAAe;YACzB,OAAO,EAAE,iCAAiC;YAC1C,IAAI,EAAE,0DAA0D;SACjE,CAAC,CAAC;IACL,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE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ACxB,MAAM,IAAI,WAAW,CAAC;YACpB,QAAQ,EAAE,eAAe;YACzB,OAAO,EAAE,8BAA8B;YACvC,IAAI,EAAE,8DAA8D;YACpE,UAAU,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE;YAC/B,UAAU,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE;YAC/B,QAAQ,EAAE,MAAM,CAAC,MAAM;SACxB,CAAC,CAAC;IACL,CAAC;IAED,MAAM,WAAW,GAAG,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,KAAK,MAAM,CAAC,MAAM,IAAI,EAAE,EAAE;SACjE,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SAC1B,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAEnC,OAAO,WAAW,IAAI,SAAS,CAAC;AAClC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type MatOqlSpecSuccess } from "../types.js";
2
+ export declare const MAT_OQL_SPEC: Omit<MatOqlSpecSuccess, "status">;
3
+ export declare function normalizeOqlInput(oql: string): string;