@mustafagoksever/java-inspector 2.0.8 → 2.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/README.md +148 -174
- package/dist/analyzer/JavaClassAnalyzer.d.ts +0 -9
- package/dist/analyzer/JavaClassAnalyzer.d.ts.map +1 -1
- package/dist/analyzer/JavaClassAnalyzer.js +0 -30
- package/dist/analyzer/JavaClassAnalyzer.js.map +1 -1
- package/dist/cli.js +2 -2
- package/dist/cli.js.map +1 -1
- package/dist/decompiler/DecompilerService.d.ts +11 -8
- package/dist/decompiler/DecompilerService.d.ts.map +1 -1
- package/dist/decompiler/DecompilerService.js +91 -74
- package/dist/decompiler/DecompilerService.js.map +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +177 -154
- package/dist/index.js.map +1 -1
- package/dist/scanner/DependencyScanner.js +1 -1
- package/dist/scanner/DependencyScanner.js.map +1 -1
- package/dist/utils/Logger.d.ts.map +1 -1
- package/dist/utils/Logger.js +6 -0
- package/dist/utils/Logger.js.map +1 -1
- package/dist/utils/cachePaths.js +1 -1
- package/dist/utils/cachePaths.js.map +1 -1
- package/dist/utils/methodExtractor.d.ts +6 -0
- package/dist/utils/methodExtractor.d.ts.map +1 -0
- package/dist/utils/methodExtractor.js +122 -0
- package/dist/utils/methodExtractor.js.map +1 -0
- package/lib/vineflower-1.11.2.jar +0 -0
- package/package.json +7 -7
- package/lib/cfr-0.152.jar +0 -0
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextpro
|
|
|
4
4
|
import { JavaClassAnalyzer } from './analyzer/JavaClassAnalyzer.js';
|
|
5
5
|
import { DependencyScanner } from './scanner/DependencyScanner.js';
|
|
6
6
|
import { DecompilerService } from './decompiler/DecompilerService.js';
|
|
7
|
+
import { extractMethod } from './utils/methodExtractor.js';
|
|
7
8
|
import { fileURLToPath } from 'url';
|
|
8
9
|
import { readFileSync } from 'fs';
|
|
9
10
|
import * as path from 'path';
|
|
@@ -51,13 +52,19 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
51
52
|
description: 'Whether to force refresh index',
|
|
52
53
|
default: false,
|
|
53
54
|
},
|
|
55
|
+
format: {
|
|
56
|
+
type: 'string',
|
|
57
|
+
enum: ['text', 'json'],
|
|
58
|
+
description: 'Output format. Use json for structured machine-readable data.',
|
|
59
|
+
default: 'text',
|
|
60
|
+
},
|
|
54
61
|
},
|
|
55
62
|
required: ['projectPath'],
|
|
56
63
|
},
|
|
57
64
|
},
|
|
58
65
|
{
|
|
59
66
|
name: 'decompile_class',
|
|
60
|
-
description: 'Decompile a Java class from Maven dependencies.
|
|
67
|
+
description: 'Decompile a Java class from Maven dependencies into full Java source code using Vineflower. Returns the complete .java source file (method bodies included). Optionally extract a single method by name, or paginate with offset/limit. Use this when you need to read the actual implementation.',
|
|
61
68
|
inputSchema: {
|
|
62
69
|
type: 'object',
|
|
63
70
|
properties: {
|
|
@@ -74,9 +81,29 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
74
81
|
description: 'Whether to use cache, default true',
|
|
75
82
|
default: true,
|
|
76
83
|
},
|
|
77
|
-
|
|
84
|
+
decompilerPath: {
|
|
85
|
+
type: 'string',
|
|
86
|
+
description: 'JAR package path of Vineflower decompiler, optional',
|
|
87
|
+
},
|
|
88
|
+
methodName: {
|
|
89
|
+
type: 'string',
|
|
90
|
+
description: 'Optional method name to extract instead of the full class. When provided, only the method body is returned.',
|
|
91
|
+
},
|
|
92
|
+
offset: {
|
|
93
|
+
type: 'number',
|
|
94
|
+
description: 'Start line number (1-based, default: 1)',
|
|
95
|
+
default: 1,
|
|
96
|
+
},
|
|
97
|
+
limit: {
|
|
98
|
+
type: 'number',
|
|
99
|
+
description: 'Max lines to return (0 = all lines)',
|
|
100
|
+
default: 0,
|
|
101
|
+
},
|
|
102
|
+
format: {
|
|
78
103
|
type: 'string',
|
|
79
|
-
|
|
104
|
+
enum: ['text', 'json'],
|
|
105
|
+
description: 'Output format. Use json for structured machine-readable data.',
|
|
106
|
+
default: 'text',
|
|
80
107
|
},
|
|
81
108
|
},
|
|
82
109
|
required: ['className', 'projectPath'],
|
|
@@ -84,7 +111,7 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
84
111
|
},
|
|
85
112
|
{
|
|
86
113
|
name: 'analyze_class',
|
|
87
|
-
description: 'Analyze a Java class structure from Maven dependencies. Use
|
|
114
|
+
description: 'Analyze a Java class structure (signatures only, no method bodies) from Maven dependencies using javap. Returns fields, methods, constructors, superclass and interfaces. Use this for a lightweight overview when you do not need full source code.',
|
|
88
115
|
inputSchema: {
|
|
89
116
|
type: 'object',
|
|
90
117
|
properties: {
|
|
@@ -102,6 +129,12 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
102
129
|
description: 'Filter members by visibility or type',
|
|
103
130
|
default: 'all'
|
|
104
131
|
},
|
|
132
|
+
format: {
|
|
133
|
+
type: 'string',
|
|
134
|
+
enum: ['text', 'json'],
|
|
135
|
+
description: 'Output format. Use json for structured machine-readable data.',
|
|
136
|
+
default: 'text',
|
|
137
|
+
},
|
|
105
138
|
},
|
|
106
139
|
required: ['className', 'projectPath'],
|
|
107
140
|
},
|
|
@@ -125,6 +158,12 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
125
158
|
description: 'Maximum number of results to return',
|
|
126
159
|
default: 20,
|
|
127
160
|
},
|
|
161
|
+
format: {
|
|
162
|
+
type: 'string',
|
|
163
|
+
enum: ['text', 'json'],
|
|
164
|
+
description: 'Output format. Use json for structured machine-readable data.',
|
|
165
|
+
default: 'text',
|
|
166
|
+
},
|
|
128
167
|
},
|
|
129
168
|
required: ['query', 'projectPath'],
|
|
130
169
|
},
|
|
@@ -143,53 +182,16 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
143
182
|
type: 'string',
|
|
144
183
|
description: 'Maven project root directory path',
|
|
145
184
|
},
|
|
146
|
-
|
|
147
|
-
required: ['className', 'projectPath'],
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
name: 'find_implementations',
|
|
152
|
-
description: 'Find all classes inside the project\'s Maven dependencies that implement a given interface or extend a given class. Results may be partial while the background scan is in progress.',
|
|
153
|
-
inputSchema: {
|
|
154
|
-
type: 'object',
|
|
155
|
-
properties: {
|
|
156
|
-
className: {
|
|
185
|
+
format: {
|
|
157
186
|
type: 'string',
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
type: 'string',
|
|
162
|
-
description: 'Maven project root directory path',
|
|
187
|
+
enum: ['text', 'json'],
|
|
188
|
+
description: 'Output format. Use json for structured machine-readable data.',
|
|
189
|
+
default: 'text',
|
|
163
190
|
},
|
|
164
191
|
},
|
|
165
192
|
required: ['className', 'projectPath'],
|
|
166
193
|
},
|
|
167
194
|
},
|
|
168
|
-
{
|
|
169
|
-
name: 'get_observation_registry',
|
|
170
|
-
description: 'Get detailed information about a Micrometer ObservationRegistry. Use filter to narrow results.',
|
|
171
|
-
inputSchema: {
|
|
172
|
-
type: 'object',
|
|
173
|
-
properties: {
|
|
174
|
-
className: {
|
|
175
|
-
type: 'string',
|
|
176
|
-
description: 'Fully qualified name of the ObservationRegistry class',
|
|
177
|
-
default: 'io.micrometer.observation.ObservationRegistry'
|
|
178
|
-
},
|
|
179
|
-
projectPath: {
|
|
180
|
-
type: 'string',
|
|
181
|
-
description: 'Maven project root directory path',
|
|
182
|
-
},
|
|
183
|
-
filter: {
|
|
184
|
-
type: 'string',
|
|
185
|
-
enum: ['all', 'public', 'private', 'protected', 'fields', 'methods'],
|
|
186
|
-
description: 'Filter members by visibility or type',
|
|
187
|
-
default: 'all'
|
|
188
|
-
},
|
|
189
|
-
},
|
|
190
|
-
required: ['projectPath'],
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
195
|
],
|
|
194
196
|
};
|
|
195
197
|
});
|
|
@@ -227,12 +229,6 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
227
229
|
case 'get_inheritance_tree':
|
|
228
230
|
await this.validateProjectPath(args.projectPath);
|
|
229
231
|
return await this.handleGetInheritanceTree(args, sendProgress);
|
|
230
|
-
case 'find_implementations':
|
|
231
|
-
await this.validateProjectPath(args.projectPath);
|
|
232
|
-
return await this.handleFindImplementations(args, sendProgress);
|
|
233
|
-
case 'get_observation_registry':
|
|
234
|
-
await this.validateProjectPath(args.projectPath);
|
|
235
|
-
return await this.handleGetObservationRegistry(args, sendProgress);
|
|
236
232
|
default:
|
|
237
233
|
throw new Error(`Unknown tool: ${name}`);
|
|
238
234
|
}
|
|
@@ -245,7 +241,7 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
245
241
|
content: [
|
|
246
242
|
{
|
|
247
243
|
type: 'text',
|
|
248
|
-
text: `Tool call failed: ${errorMessage}
|
|
244
|
+
text: `Tool call failed: ${errorMessage}`,
|
|
249
245
|
},
|
|
250
246
|
],
|
|
251
247
|
};
|
|
@@ -253,7 +249,7 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
253
249
|
});
|
|
254
250
|
}
|
|
255
251
|
async handleScanDependencies(args, sendProgress) {
|
|
256
|
-
const { projectPath, forceRefresh = false } = args;
|
|
252
|
+
const { projectPath, forceRefresh = false, format = 'text' } = args;
|
|
257
253
|
const logger = Logger.get(projectPath);
|
|
258
254
|
const start = performance.now();
|
|
259
255
|
logger.info(`[TOOL:scan_dependencies] Request: forceRefresh=${forceRefresh}`);
|
|
@@ -264,6 +260,17 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
264
260
|
logger.info(`[TOOL:scan_dependencies] Complete in ${duration}s. Status: ${result.status}, JARs: ${result.jarCount}, Classes: ${result.classCount}`);
|
|
265
261
|
if (result.status === 'complete') {
|
|
266
262
|
await sendProgress?.(`Scan complete: ${result.jarCount} JARs, ${result.classCount} classes`, 100, 100);
|
|
263
|
+
if (format === 'json') {
|
|
264
|
+
return {
|
|
265
|
+
content: [{ type: 'text', text: 'Dependency scanning complete.' }],
|
|
266
|
+
structuredContent: {
|
|
267
|
+
status: result.status,
|
|
268
|
+
jarCount: result.jarCount,
|
|
269
|
+
classCount: result.classCount,
|
|
270
|
+
indexPath: result.indexPath,
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
}
|
|
267
274
|
return {
|
|
268
275
|
content: [
|
|
269
276
|
{
|
|
@@ -288,6 +295,17 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
288
295
|
text += `Index file path: ${result.indexPath}\n\n`;
|
|
289
296
|
text += `You can already use \`decompile_class\` and \`analyze_class\` — the server will resolve classes on-demand. `;
|
|
290
297
|
text += `Call \`scan_dependencies\` again later to check progress.`;
|
|
298
|
+
if (format === 'json') {
|
|
299
|
+
return {
|
|
300
|
+
content: [{ type: 'text', text: 'Background dependency scan is in progress.' }],
|
|
301
|
+
structuredContent: {
|
|
302
|
+
status: result.status,
|
|
303
|
+
jarCount: result.jarCount,
|
|
304
|
+
progress: result.progress,
|
|
305
|
+
indexPath: result.indexPath,
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
}
|
|
291
309
|
return {
|
|
292
310
|
content: [
|
|
293
311
|
{
|
|
@@ -298,36 +316,78 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
298
316
|
};
|
|
299
317
|
}
|
|
300
318
|
async handleDecompileClass(args, sendProgress) {
|
|
301
|
-
const { className, projectPath, useCache = true,
|
|
319
|
+
const { className, projectPath, useCache = true, decompilerPath, format = 'text', offset = 1, limit = 0 } = args;
|
|
302
320
|
const logger = Logger.get(projectPath);
|
|
303
321
|
const start = performance.now();
|
|
304
|
-
logger.info(`[TOOL:decompile_class] Request: className=${className}, useCache=${useCache},
|
|
305
|
-
this.logToolDebug(logger, 'decompile_class', projectPath, { className, useCache,
|
|
322
|
+
logger.info(`[TOOL:decompile_class] Request: className=${className}, useCache=${useCache}, decompilerPath=${decompilerPath || 'auto-detect'}`);
|
|
323
|
+
this.logToolDebug(logger, 'decompile_class', projectPath, { className, useCache, decompilerPath: decompilerPath || 'auto-detect' });
|
|
306
324
|
try {
|
|
307
325
|
await sendProgress?.(`Starting decompilation of class: ${className}`, 0, 100);
|
|
308
326
|
// Check if index exists, create if not
|
|
309
327
|
await sendProgress?.('Checking class index...', 10, 100);
|
|
310
328
|
await this.ensureScanStarted(projectPath, sendProgress);
|
|
311
329
|
await sendProgress?.('Decompiling class...', 50, 100);
|
|
312
|
-
const sourceCode = await this.decompiler.decompileClass(className, projectPath, useCache,
|
|
330
|
+
const sourceCode = await this.decompiler.decompileClass(className, projectPath, useCache, decompilerPath);
|
|
313
331
|
await sendProgress?.('Decompilation complete', 100, 100);
|
|
314
332
|
if (!sourceCode || sourceCode.trim() === '') {
|
|
315
333
|
return {
|
|
316
334
|
content: [
|
|
317
335
|
{
|
|
318
336
|
type: 'text',
|
|
319
|
-
text: `Warning: Decompilation result for class ${className} is empty, possibly due to
|
|
337
|
+
text: `Warning: Decompilation result for class ${className} is empty, possibly due to Vineflower decompiler issues or corrupted class file`,
|
|
320
338
|
},
|
|
321
339
|
],
|
|
322
340
|
};
|
|
323
341
|
}
|
|
342
|
+
// Apply method extraction or offset/limit slicing
|
|
343
|
+
let finalSourceCode = sourceCode;
|
|
344
|
+
let sliceInfo = '';
|
|
345
|
+
if (args.methodName) {
|
|
346
|
+
const extracted = extractMethod(sourceCode, args.methodName);
|
|
347
|
+
if (!extracted) {
|
|
348
|
+
return {
|
|
349
|
+
content: [{
|
|
350
|
+
type: 'text',
|
|
351
|
+
text: `Method "${args.methodName}" not found in class ${className}.`,
|
|
352
|
+
}],
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
finalSourceCode = extracted;
|
|
356
|
+
sliceInfo = ` (method: ${args.methodName})`;
|
|
357
|
+
}
|
|
358
|
+
else if (offset > 1 || limit > 0) {
|
|
359
|
+
const lines = sourceCode.split('\n');
|
|
360
|
+
const totalLines = lines.length;
|
|
361
|
+
const effectiveOffset = offset <= 0 ? 1 : offset;
|
|
362
|
+
if (effectiveOffset > totalLines) {
|
|
363
|
+
return {
|
|
364
|
+
content: [{
|
|
365
|
+
type: 'text',
|
|
366
|
+
text: `Offset ${effectiveOffset} exceeds total lines ${totalLines} for class ${className}.`,
|
|
367
|
+
}],
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
const effectiveLimit = limit < 0 ? 0 : limit;
|
|
371
|
+
const startIndex = effectiveOffset - 1;
|
|
372
|
+
const endIndex = effectiveLimit > 0
|
|
373
|
+
? Math.min(startIndex + effectiveLimit, totalLines)
|
|
374
|
+
: totalLines;
|
|
375
|
+
finalSourceCode = lines.slice(startIndex, endIndex).join('\n');
|
|
376
|
+
sliceInfo = ` (lines ${effectiveOffset}-${endIndex} of ${totalLines})`;
|
|
377
|
+
}
|
|
324
378
|
const duration = ((performance.now() - start) / 1000).toFixed(2);
|
|
325
379
|
logger.info(`[TOOL:decompile_class] Complete in ${duration}s. Source length: ${sourceCode.length} chars.`);
|
|
380
|
+
if (format === 'json') {
|
|
381
|
+
return {
|
|
382
|
+
content: [{ type: 'text', text: `Decompiled ${className}${sliceInfo}` }],
|
|
383
|
+
structuredContent: { className, sourceCode: finalSourceCode },
|
|
384
|
+
};
|
|
385
|
+
}
|
|
326
386
|
return {
|
|
327
387
|
content: [
|
|
328
388
|
{
|
|
329
389
|
type: 'text',
|
|
330
|
-
text: `Decompiled source code for class ${className}:\n\n\`\`\`java\n${
|
|
390
|
+
text: `Decompiled source code for class ${className}${sliceInfo}:\n\n\`\`\`java\n${finalSourceCode}\n\`\`\``,
|
|
331
391
|
},
|
|
332
392
|
],
|
|
333
393
|
};
|
|
@@ -341,14 +401,14 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
341
401
|
content: [
|
|
342
402
|
{
|
|
343
403
|
type: 'text',
|
|
344
|
-
text: `Decompilation failed: ${errorMessage}
|
|
404
|
+
text: `Decompilation failed: ${errorMessage}`,
|
|
345
405
|
},
|
|
346
406
|
],
|
|
347
407
|
};
|
|
348
408
|
}
|
|
349
409
|
}
|
|
350
410
|
async handleAnalyzeClass(args, sendProgress) {
|
|
351
|
-
const { className, projectPath, filter = 'all' } = args;
|
|
411
|
+
const { className, projectPath, filter = 'all', format = 'text' } = args;
|
|
352
412
|
const logger = Logger.get(projectPath);
|
|
353
413
|
const start = performance.now();
|
|
354
414
|
logger.info(`[TOOL:analyze_class] Request: className=${className}, filter=${filter}`);
|
|
@@ -363,6 +423,20 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
363
423
|
const duration = ((performance.now() - start) / 1000).toFixed(2);
|
|
364
424
|
logger.info(`[TOOL:analyze_class] Complete in ${duration}s. Fields: ${analysis.fields.length}, Methods: ${analysis.methods.length}`);
|
|
365
425
|
const { fields, methods } = this.applyFilter(analysis, filter);
|
|
426
|
+
if (format === 'json') {
|
|
427
|
+
return {
|
|
428
|
+
content: [{ type: 'text', text: `Analyzed ${className}` }],
|
|
429
|
+
structuredContent: {
|
|
430
|
+
className: analysis.className,
|
|
431
|
+
packageName: analysis.packageName,
|
|
432
|
+
modifiers: analysis.modifiers,
|
|
433
|
+
superClass: analysis.superClass,
|
|
434
|
+
interfaces: analysis.interfaces,
|
|
435
|
+
fields,
|
|
436
|
+
methods,
|
|
437
|
+
},
|
|
438
|
+
};
|
|
439
|
+
}
|
|
366
440
|
let result = `Analysis result for class ${className}:\n\n`;
|
|
367
441
|
result += `Package name: ${analysis.packageName}\n`;
|
|
368
442
|
result += `Class name: ${analysis.className}\n`;
|
|
@@ -393,7 +467,7 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
393
467
|
};
|
|
394
468
|
}
|
|
395
469
|
async handleSearchClass(args, sendProgress) {
|
|
396
|
-
const { query, projectPath, limit = 20 } = args;
|
|
470
|
+
const { query, projectPath, limit = 20, format = 'text' } = args;
|
|
397
471
|
const logger = Logger.get(projectPath);
|
|
398
472
|
const start = performance.now();
|
|
399
473
|
logger.info(`[TOOL:search_class] Request: query="${query}", limit=${limit}`);
|
|
@@ -406,6 +480,12 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
406
480
|
logger.info(`[TOOL:search_class] Complete in ${duration}s. Found ${results.length} results.`);
|
|
407
481
|
await sendProgress?.(`Found ${results.length} matches`, 100, 100);
|
|
408
482
|
if (results.length === 0) {
|
|
483
|
+
if (format === 'json') {
|
|
484
|
+
return {
|
|
485
|
+
content: [{ type: 'text', text: `No classes found matching "${query}".` }],
|
|
486
|
+
structuredContent: { query, results: [], isComplete: await this.scanner.isIndexComplete(projectPath) },
|
|
487
|
+
};
|
|
488
|
+
}
|
|
409
489
|
return {
|
|
410
490
|
content: [
|
|
411
491
|
{
|
|
@@ -415,6 +495,27 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
415
495
|
],
|
|
416
496
|
};
|
|
417
497
|
}
|
|
498
|
+
const isComplete = await this.scanner.isIndexComplete(projectPath);
|
|
499
|
+
const scanProgress = isComplete ? undefined : await this.scanner.getScanProgress(projectPath);
|
|
500
|
+
const pct = scanProgress ? Math.floor((scanProgress.processed / scanProgress.total) * 100) : undefined;
|
|
501
|
+
if (format === 'json') {
|
|
502
|
+
return {
|
|
503
|
+
content: [{ type: 'text', text: `Found ${results.length} matches.` }],
|
|
504
|
+
structuredContent: {
|
|
505
|
+
query,
|
|
506
|
+
results: results.map((r) => ({
|
|
507
|
+
className: `${r.packageName}.${r.simpleName}`,
|
|
508
|
+
packageName: r.packageName,
|
|
509
|
+
simpleName: r.simpleName,
|
|
510
|
+
jarPath: r.jarPath,
|
|
511
|
+
jarName: path.basename(r.jarPath),
|
|
512
|
+
score: r.score,
|
|
513
|
+
})),
|
|
514
|
+
isComplete,
|
|
515
|
+
scanProgressPct: pct,
|
|
516
|
+
},
|
|
517
|
+
};
|
|
518
|
+
}
|
|
418
519
|
let text = `Found ${results.length} class(es) matching "${query}":\n\n`;
|
|
419
520
|
text += '| # | Class Name | Package | JAR | Score |\n';
|
|
420
521
|
text += '|---|------------|---------|-----|-------|\n';
|
|
@@ -422,13 +523,8 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
422
523
|
text += `| ${idx + 1} | \`${entry.simpleName}\` | ${entry.packageName} | ${path.basename(entry.jarPath)} | ${entry.score} |\n`;
|
|
423
524
|
});
|
|
424
525
|
text += '\nUse the fully qualified class name with `decompile_class` or `analyze_class` to inspect it further.';
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
const progress = await this.scanner.getScanProgress(projectPath);
|
|
428
|
-
if (progress) {
|
|
429
|
-
const pct = Math.floor((progress.processed / progress.total) * 100);
|
|
430
|
-
text += `\n\n_Note: Background dependency scan is ${pct}% complete. Results may be partial._`;
|
|
431
|
-
}
|
|
526
|
+
if (!isComplete && pct !== undefined) {
|
|
527
|
+
text += `\n\n_Note: Background dependency scan is ${pct}% complete. Results may be partial._`;
|
|
432
528
|
}
|
|
433
529
|
return {
|
|
434
530
|
content: [
|
|
@@ -440,7 +536,7 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
440
536
|
};
|
|
441
537
|
}
|
|
442
538
|
async handleGetInheritanceTree(args, sendProgress) {
|
|
443
|
-
const { className, projectPath } = args;
|
|
539
|
+
const { className, projectPath, format = 'text' } = args;
|
|
444
540
|
const logger = Logger.get(projectPath);
|
|
445
541
|
const start = performance.now();
|
|
446
542
|
logger.info(`[TOOL:get_inheritance_tree] Request: className=${className}`);
|
|
@@ -452,6 +548,12 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
452
548
|
const duration = ((performance.now() - start) / 1000).toFixed(2);
|
|
453
549
|
logger.info(`[TOOL:get_inheritance_tree] Complete in ${duration}s. Hierarchy depth: ${hierarchy.length}`);
|
|
454
550
|
await sendProgress?.('Hierarchy complete', 100, 100);
|
|
551
|
+
if (format === 'json') {
|
|
552
|
+
return {
|
|
553
|
+
content: [{ type: 'text', text: `Inheritance hierarchy for ${className}` }],
|
|
554
|
+
structuredContent: { className, hierarchy },
|
|
555
|
+
};
|
|
556
|
+
}
|
|
455
557
|
let text = `Inheritance hierarchy for \`${className}\`:\n\n`;
|
|
456
558
|
hierarchy.forEach((cls, idx) => {
|
|
457
559
|
const indent = ' '.repeat(idx);
|
|
@@ -470,42 +572,6 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
470
572
|
],
|
|
471
573
|
};
|
|
472
574
|
}
|
|
473
|
-
async handleFindImplementations(args, sendProgress) {
|
|
474
|
-
const { className, projectPath } = args;
|
|
475
|
-
const logger = Logger.get(projectPath);
|
|
476
|
-
const start = performance.now();
|
|
477
|
-
logger.info(`[TOOL:find_implementations] Request: className=${className}`);
|
|
478
|
-
this.logToolDebug(logger, 'find_implementations', projectPath, { className });
|
|
479
|
-
await sendProgress?.(`Finding implementations of: ${className}`, 0, 100);
|
|
480
|
-
await this.ensureScanStarted(projectPath, sendProgress);
|
|
481
|
-
await sendProgress?.('Scanning all classes (this may take a while)...', 30, 100);
|
|
482
|
-
const implementations = await this.analyzer.findImplementations(className, projectPath);
|
|
483
|
-
const duration = ((performance.now() - start) / 1000).toFixed(2);
|
|
484
|
-
logger.info(`[TOOL:find_implementations] Complete in ${duration}s. Found ${implementations.length} implementations.`);
|
|
485
|
-
await sendProgress?.(`Found ${implementations.length} implementation(s)`, 100, 100);
|
|
486
|
-
if (implementations.length === 0) {
|
|
487
|
-
return {
|
|
488
|
-
content: [
|
|
489
|
-
{
|
|
490
|
-
type: 'text',
|
|
491
|
-
text: `No implementations found for \`${className}\`.\n\nPossible reasons:\n1. The class/interface is not implemented by any dependency in this project\n2. Implementations may be in your own project source code (not in dependencies)\n3. The class name may be incorrect`,
|
|
492
|
-
},
|
|
493
|
-
],
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
let text = `Found ${implementations.length} class(es) implementing/extending \`${className}\`:\n\n`;
|
|
497
|
-
implementations.forEach((cls, idx) => {
|
|
498
|
-
text += `${idx + 1}. \`${cls}\`\n`;
|
|
499
|
-
});
|
|
500
|
-
return {
|
|
501
|
-
content: [
|
|
502
|
-
{
|
|
503
|
-
type: 'text',
|
|
504
|
-
text,
|
|
505
|
-
},
|
|
506
|
-
],
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
575
|
applyFilter(analysis, filter) {
|
|
510
576
|
let fields = analysis.fields;
|
|
511
577
|
let methods = analysis.methods;
|
|
@@ -521,52 +587,9 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
521
587
|
}
|
|
522
588
|
return { fields, methods };
|
|
523
589
|
}
|
|
524
|
-
async handleGetObservationRegistry(args, sendProgress) {
|
|
525
|
-
const { className = 'io.micrometer.observation.ObservationRegistry', projectPath, filter = 'all' } = args;
|
|
526
|
-
const logger = Logger.get(projectPath);
|
|
527
|
-
const start = performance.now();
|
|
528
|
-
logger.info(`[TOOL:get_observation_registry] Request: className=${className}, filter=${filter}`);
|
|
529
|
-
this.logToolDebug(logger, 'get_observation_registry', projectPath, { className, filter });
|
|
530
|
-
await sendProgress?.(`Analyzing ObservationRegistry: ${className}`, 0, 100);
|
|
531
|
-
await this.ensureScanStarted(projectPath, sendProgress);
|
|
532
|
-
await sendProgress?.('Running javap analysis...', 50, 100);
|
|
533
|
-
const analysis = await this.analyzer.analyzeClass(className, projectPath);
|
|
534
|
-
const duration = ((performance.now() - start) / 1000).toFixed(2);
|
|
535
|
-
logger.info(`[TOOL:get_observation_registry] Complete in ${duration}s. Fields: ${analysis.fields.length}, Methods: ${analysis.methods.length}`);
|
|
536
|
-
await sendProgress?.('Analysis complete', 100, 100);
|
|
537
|
-
const { fields, methods } = this.applyFilter(analysis, filter);
|
|
538
|
-
let result = `ObservationRegistry analysis for \`${className}\`:\n\n`;
|
|
539
|
-
result += `Package: ${analysis.packageName}\n`;
|
|
540
|
-
result += `Class: ${analysis.className}\n`;
|
|
541
|
-
result += `Modifiers: ${analysis.modifiers.join(' ')}\n`;
|
|
542
|
-
result += `Super class: ${analysis.superClass || 'None'}\n`;
|
|
543
|
-
result += `Implemented interfaces: ${analysis.interfaces.join(', ') || 'None'}\n\n`;
|
|
544
|
-
if (fields.length > 0) {
|
|
545
|
-
result += `Fields (${fields.length}):\n`;
|
|
546
|
-
fields.forEach(field => {
|
|
547
|
-
result += ` - ${field.modifiers.join(' ')} ${field.type} ${field.name}\n`;
|
|
548
|
-
});
|
|
549
|
-
result += '\n';
|
|
550
|
-
}
|
|
551
|
-
if (methods.length > 0) {
|
|
552
|
-
result += `Methods (${methods.length}):\n`;
|
|
553
|
-
methods.forEach(method => {
|
|
554
|
-
result += ` - ${method.modifiers.join(' ')} ${method.returnType} ${method.name}(${method.parameters.join(', ')})\n`;
|
|
555
|
-
});
|
|
556
|
-
result += '\n';
|
|
557
|
-
}
|
|
558
|
-
return {
|
|
559
|
-
content: [
|
|
560
|
-
{
|
|
561
|
-
type: 'text',
|
|
562
|
-
text: result,
|
|
563
|
-
},
|
|
564
|
-
],
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
590
|
/**
|
|
568
|
-
|
|
569
|
-
|
|
591
|
+
* Validate that projectPath is a valid Maven project root.
|
|
592
|
+
*/
|
|
570
593
|
async validateProjectPath(projectPath) {
|
|
571
594
|
if (!projectPath || typeof projectPath !== 'string') {
|
|
572
595
|
throw new Error('projectPath is required and must be a string.');
|
|
@@ -618,7 +641,7 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
618
641
|
MAVEN_HOME: process.env.MAVEN_HOME,
|
|
619
642
|
MAVEN_CMD: process.env.MAVEN_CMD,
|
|
620
643
|
MAVEN_REPO: process.env.MAVEN_REPO,
|
|
621
|
-
|
|
644
|
+
DECOMPILER_PATH: process.env.DECOMPILER_PATH,
|
|
622
645
|
};
|
|
623
646
|
}
|
|
624
647
|
logServerStartup(logger) {
|
|
@@ -652,7 +675,6 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
652
675
|
return;
|
|
653
676
|
}
|
|
654
677
|
const logger = Logger.get(cwd);
|
|
655
|
-
this.logServerStartup(logger);
|
|
656
678
|
logger.info(`[AUTO-SCAN] Maven project detected at ${cwd}. Starting dependency scan...`);
|
|
657
679
|
try {
|
|
658
680
|
await this.validateProjectPath(cwd);
|
|
@@ -671,7 +693,8 @@ export class JavaClassAnalyzerMCPServer {
|
|
|
671
693
|
async run() {
|
|
672
694
|
const transport = new StdioServerTransport();
|
|
673
695
|
await this.server.connect(transport);
|
|
674
|
-
|
|
696
|
+
const startupLogger = Logger.get(process.cwd());
|
|
697
|
+
this.logServerStartup(startupLogger);
|
|
675
698
|
await this.tryAutoScan();
|
|
676
699
|
}
|
|
677
700
|
}
|