jarp-mcp 1.0.1

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.
@@ -0,0 +1,238 @@
1
+ import { exec } from 'child_process';
2
+ import { promisify } from 'util';
3
+ import * as fs from 'fs-extra';
4
+ import { readFile, readdir } from 'fs/promises';
5
+ import * as path from 'path';
6
+ import * as yauzl from 'yauzl';
7
+ import { fileURLToPath } from 'url';
8
+ import { createWriteStream } from 'fs';
9
+ import { DependencyScanner } from '../scanner/DependencyScanner.js';
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = path.dirname(__filename);
12
+ const execAsync = promisify(exec);
13
+ export class DecompilerService {
14
+ scanner;
15
+ cfrPath;
16
+ constructor() {
17
+ this.scanner = new DependencyScanner();
18
+ this.cfrPath = '';
19
+ }
20
+ async initializeCfrPath() {
21
+ if (!this.cfrPath) {
22
+ this.cfrPath = await this.findCfrJar();
23
+ if (!this.cfrPath) {
24
+ throw new Error('CFR decompiler tool not found. Please download CFR jar to lib directory or set CFR_PATH environment variable');
25
+ }
26
+ console.error(`CFR tool path: ${this.cfrPath}`);
27
+ }
28
+ }
29
+ /**
30
+ * Decompile specified Java class file
31
+ */
32
+ async decompileClass(className, projectPath, useCache = true, cfrPath) {
33
+ try {
34
+ // If external CFR path is specified, use external path
35
+ if (cfrPath) {
36
+ this.cfrPath = cfrPath;
37
+ console.error(`Using externally specified CFR tool path: ${this.cfrPath}`);
38
+ }
39
+ else {
40
+ await this.initializeCfrPath();
41
+ }
42
+ // 1. Check cache
43
+ const cachePath = this.getCachePath(className, projectPath);
44
+ if (useCache && await fs.pathExists(cachePath)) {
45
+ console.error(`Using cached decompilation result: ${cachePath}`);
46
+ return await readFile(cachePath, 'utf-8');
47
+ }
48
+ // 2. Find corresponding JAR package for class
49
+ console.error(`Finding JAR package for class ${className}...`);
50
+ // Add timeout handling
51
+ const jarPath = await Promise.race([
52
+ this.scanner.findJarForClass(className, projectPath),
53
+ new Promise((_, reject) => setTimeout(() => reject(new Error('JAR package lookup timeout')), 10000))
54
+ ]);
55
+ if (!jarPath) {
56
+ throw new Error(`JAR package for class ${className} not found, please run scan_dependencies first to build class index`);
57
+ }
58
+ console.error(`Found JAR package: ${jarPath}`);
59
+ // 3. Extract .class file from JAR package
60
+ const classFilePath = await this.extractClassFile(jarPath, className);
61
+ // 4. Use CFR to decompile
62
+ const sourceCode = await this.decompileWithCfr(classFilePath);
63
+ // 5. Save to cache
64
+ if (useCache) {
65
+ await fs.ensureDir(path.dirname(cachePath));
66
+ await fs.outputFile(cachePath, sourceCode, 'utf-8');
67
+ console.error(`Decompilation result cached: ${cachePath}`);
68
+ }
69
+ // 6. Clean up temporary files (only when not using cache)
70
+ if (!useCache) {
71
+ try {
72
+ await fs.remove(classFilePath);
73
+ console.error(`Cleaning up temporary file: ${classFilePath}`);
74
+ }
75
+ catch (cleanupError) {
76
+ console.warn(`Failed to clean up temporary file: ${cleanupError}`);
77
+ }
78
+ }
79
+ return sourceCode;
80
+ }
81
+ catch (error) {
82
+ console.error(`Failed to decompile class ${className}:`, error);
83
+ throw error; // Re-throw error for upper layer handling
84
+ }
85
+ }
86
+ /**
87
+ * Get cache file path
88
+ */
89
+ getCachePath(className, projectPath) {
90
+ const packagePath = className.substring(0, className.lastIndexOf('.'));
91
+ const simpleName = className.substring(className.lastIndexOf('.') + 1);
92
+ const cacheDir = path.join(projectPath, '.mcp-decompile-cache');
93
+ const packageDir = path.join(cacheDir, packagePath.replace(/\./g, path.sep));
94
+ return path.join(packageDir, `${simpleName}.java`);
95
+ }
96
+ /**
97
+ * Extract specified .class file from JAR package
98
+ */
99
+ async extractClassFile(jarPath, className) {
100
+ const classFileName = className.replace(/\./g, '/') + '.class';
101
+ const tempDir = path.join(process.cwd(), '.mcp-class-temp');
102
+ // Create directory structure by full package name path
103
+ const packagePath = className.substring(0, className.lastIndexOf('.'));
104
+ const packageDir = path.join(tempDir, packagePath.replace(/\./g, path.sep));
105
+ const classFilePath = path.join(packageDir, `${className.substring(className.lastIndexOf('.') + 1)}.class`);
106
+ await fs.ensureDir(packageDir);
107
+ console.error(`Extracting class file from JAR package: ${jarPath} -> ${classFileName}`);
108
+ return new Promise((resolve, reject) => {
109
+ yauzl.open(jarPath, { lazyEntries: true }, (err, zipfile) => {
110
+ if (err) {
111
+ reject(new Error(`Unable to open JAR package ${jarPath}: ${err.message}`));
112
+ return;
113
+ }
114
+ let found = false;
115
+ zipfile.readEntry();
116
+ zipfile.on('entry', (entry) => {
117
+ if (entry.fileName === classFileName) {
118
+ found = true;
119
+ zipfile.openReadStream(entry, (err, readStream) => {
120
+ if (err) {
121
+ reject(new Error(`Unable to read class file ${classFileName} from JAR package: ${err.message}`));
122
+ return;
123
+ }
124
+ const writeStream = createWriteStream(classFilePath);
125
+ readStream.pipe(writeStream);
126
+ writeStream.on('close', () => {
127
+ console.error(`Class file extracted successfully: ${classFilePath}`);
128
+ resolve(classFilePath);
129
+ });
130
+ writeStream.on('error', (err) => {
131
+ reject(new Error(`Failed to write temporary file: ${err.message}`));
132
+ });
133
+ });
134
+ }
135
+ else {
136
+ zipfile.readEntry();
137
+ }
138
+ });
139
+ zipfile.on('end', () => {
140
+ if (!found) {
141
+ reject(new Error(`Class file ${classFileName} not found in JAR package ${jarPath}`));
142
+ }
143
+ });
144
+ zipfile.on('error', (err) => {
145
+ reject(new Error(`Failed to read JAR package: ${err.message}`));
146
+ });
147
+ });
148
+ });
149
+ }
150
+ /**
151
+ * Use CFR to decompile .class file
152
+ */
153
+ async decompileWithCfr(classFilePath) {
154
+ if (!this.cfrPath) {
155
+ throw new Error('CFR decompiler tool not found, please ensure CFR jar is in classpath');
156
+ }
157
+ try {
158
+ const javaCmd = this.getJavaCommand();
159
+ // If Java path contains spaces, need to wrap with quotes
160
+ const quotedJavaCmd = javaCmd.includes(' ') ? `"${javaCmd}"` : javaCmd;
161
+ console.error(`Executing CFR decompilation: ${quotedJavaCmd} -jar "${this.cfrPath}" "${classFilePath}"`);
162
+ const { stdout, stderr } = await execAsync(`${quotedJavaCmd} -jar "${this.cfrPath}" "${classFilePath}" --silent true`, { timeout: 30000 });
163
+ if (stderr && stderr.trim()) {
164
+ console.warn('CFR warning:', stderr);
165
+ }
166
+ if (!stdout || stdout.trim() === '') {
167
+ throw new Error('CFR decompilation returned empty result, possibly due to corrupted class file or incompatible CFR version');
168
+ }
169
+ return stdout;
170
+ }
171
+ catch (error) {
172
+ console.error('CFR decompilation execution failed:', error);
173
+ if (error instanceof Error && error.message.includes('timeout')) {
174
+ throw new Error('CFR decompilation timeout, please check Java environment and CFR tool');
175
+ }
176
+ throw new Error(`CFR decompilation failed: ${error instanceof Error ? error.message : String(error)}`);
177
+ }
178
+ }
179
+ /**
180
+ * Find CFR jar package path
181
+ */
182
+ async findCfrJar() {
183
+ // Try to find CFR from multiple possible locations
184
+ const searchPaths = [
185
+ path.join(process.cwd(), 'lib'),
186
+ process.cwd(),
187
+ path.join(__dirname, '..', '..', 'lib'),
188
+ path.join(__dirname, '..', '..'),
189
+ ];
190
+ for (const searchPath of searchPaths) {
191
+ if (await fs.pathExists(searchPath)) {
192
+ const files = await readdir(searchPath);
193
+ const cfrJar = files.find(file => /^cfr-.*\.jar$/.test(file));
194
+ if (cfrJar) {
195
+ return path.join(searchPath, cfrJar);
196
+ }
197
+ }
198
+ }
199
+ // If not found, try to find from classpath
200
+ const classpath = process.env.CLASSPATH || '';
201
+ const classpathEntries = classpath.split(path.delimiter);
202
+ for (const entry of classpathEntries) {
203
+ if (entry.includes('cfr') && entry.endsWith('.jar')) {
204
+ return entry;
205
+ }
206
+ }
207
+ return '';
208
+ }
209
+ /**
210
+ * Batch decompile multiple classes
211
+ */
212
+ async decompileClasses(classNames, projectPath, useCache = true, cfrPath) {
213
+ const results = new Map();
214
+ for (const className of classNames) {
215
+ try {
216
+ const sourceCode = await this.decompileClass(className, projectPath, useCache, cfrPath);
217
+ results.set(className, sourceCode);
218
+ }
219
+ catch (error) {
220
+ console.warn(`Failed to decompile class ${className}: ${error}`);
221
+ results.set(className, `// Decompilation failed: ${error}`);
222
+ }
223
+ }
224
+ return results;
225
+ }
226
+ /**
227
+ * Get Java command path
228
+ */
229
+ getJavaCommand() {
230
+ const javaHome = process.env.JAVA_HOME;
231
+ if (javaHome) {
232
+ const javaCmd = process.platform === 'win32' ? 'java.exe' : 'java';
233
+ return path.join(javaHome, 'bin', javaCmd);
234
+ }
235
+ return 'java'; // Fallback to java in PATH
236
+ }
237
+ }
238
+ //# sourceMappingURL=DecompilerService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DecompilerService.js","sourceRoot":"","sources":["../../src/decompiler/DecompilerService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,KAAK,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAEpE,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AAE3C,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AAElC,MAAM,OAAO,iBAAiB;IAClB,OAAO,CAAoB;IAC3B,OAAO,CAAS;IAExB;QACI,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAiB,EAAE,CAAC;QACvC,IAAI,CAAC,OAAO,GAAG,EAAE,CAA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AAI,CAAC;gBACD,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;gBACxF,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;YACvC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,OAAO,CAAC,IAAI,CAAC,6BAA6B,SAAS,KAAK,KAAK,EAAE,CAAC,CAAC;gBACjE,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,4BAA4B,KAAK,EAAE,CAAC,CAAC;YAChE,CAAC;QACL,CAAC;QAED,OAAO,OAAO,CAAC;IACnB,CAAC;IAGD;;OAEG;IACK,cAAc;QAClB,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;QACvC,IAAI,QAAQ,EAAE,CAAC;YACX,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC;YACnE,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,MAAM,CAAC,CAAC,2BAA2B;IAC9C,CAAC;CACJ"}
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ export declare class JavaClassAnalyzerMCPServer {
3
+ private server;
4
+ private analyzer;
5
+ private scanner;
6
+ private decompiler;
7
+ constructor();
8
+ private setupHandlers;
9
+ private handleScanDependencies;
10
+ private handleDecompileClass;
11
+ private handleAnalyzeClass;
12
+ /**
13
+ * Ensure index file exists, create automatically if not
14
+ */
15
+ private ensureIndexExists;
16
+ run(): Promise<void>;
17
+ }
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAYA,qBAAa,0BAA0B;IACnC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAoB;IACpC,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,UAAU,CAAoB;;IAsBtC,OAAO,CAAC,aAAa;YAoGP,sBAAsB;YAmBtB,oBAAoB;YA2CpB,kBAAkB;IAyChC;;OAEG;YACW,iBAAiB;IAkBzB,GAAG;CAWZ"}
package/dist/index.js ADDED
@@ -0,0 +1,258 @@
1
+ #!/usr/bin/env node
2
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
5
+ import { JavaClassAnalyzer } from './analyzer/JavaClassAnalyzer.js';
6
+ import { DependencyScanner } from './scanner/DependencyScanner.js';
7
+ import { DecompilerService } from './decompiler/DecompilerService.js';
8
+ export class JavaClassAnalyzerMCPServer {
9
+ server;
10
+ analyzer;
11
+ scanner;
12
+ decompiler;
13
+ constructor() {
14
+ this.server = new Server({
15
+ name: 'java-class-analyzer',
16
+ version: '1.0.0',
17
+ }, {
18
+ capabilities: {
19
+ tools: {},
20
+ },
21
+ });
22
+ this.analyzer = new JavaClassAnalyzer();
23
+ this.scanner = new DependencyScanner();
24
+ this.decompiler = new DecompilerService();
25
+ this.setupHandlers();
26
+ }
27
+ setupHandlers() {
28
+ this.server.setRequestHandler(ListToolsRequestSchema, async () => {
29
+ return {
30
+ tools: [
31
+ {
32
+ name: 'scan_dependencies',
33
+ description: 'Scan all dependencies of a Maven project and build mapping index from class names to JAR packages',
34
+ inputSchema: {
35
+ type: 'object',
36
+ properties: {
37
+ projectPath: {
38
+ type: 'string',
39
+ description: 'Maven project root directory path',
40
+ },
41
+ forceRefresh: {
42
+ type: 'boolean',
43
+ description: 'Whether to force refresh index',
44
+ default: false,
45
+ },
46
+ },
47
+ required: ['projectPath'],
48
+ },
49
+ },
50
+ {
51
+ name: 'decompile_class',
52
+ description: 'Decompile specified Java class file and return Java source code',
53
+ inputSchema: {
54
+ type: 'object',
55
+ properties: {
56
+ className: {
57
+ type: 'string',
58
+ description: 'Fully qualified name of the Java class to decompile, e.g., com.example.QueryBizOrderDO',
59
+ },
60
+ projectPath: {
61
+ type: 'string',
62
+ description: 'Maven project root directory path',
63
+ },
64
+ useCache: {
65
+ type: 'boolean',
66
+ description: 'Whether to use cache, default true',
67
+ default: true,
68
+ },
69
+ cfrPath: {
70
+ type: 'string',
71
+ description: 'JAR package path of CFR decompilation tool, optional',
72
+ },
73
+ },
74
+ required: ['className', 'projectPath'],
75
+ },
76
+ },
77
+ {
78
+ name: 'analyze_class',
79
+ description: 'Analyze structure, methods, fields and other information of a Java class',
80
+ inputSchema: {
81
+ type: 'object',
82
+ properties: {
83
+ className: {
84
+ type: 'string',
85
+ description: 'Fully qualified name of the Java class to analyze',
86
+ },
87
+ projectPath: {
88
+ type: 'string',
89
+ description: 'Maven project root directory path',
90
+ },
91
+ },
92
+ required: ['className', 'projectPath'],
93
+ },
94
+ },
95
+ ],
96
+ };
97
+ });
98
+ this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
99
+ const { name, arguments: args } = request.params;
100
+ try {
101
+ switch (name) {
102
+ case 'scan_dependencies':
103
+ return await this.handleScanDependencies(args);
104
+ case 'decompile_class':
105
+ return await this.handleDecompileClass(args);
106
+ case 'analyze_class':
107
+ return await this.handleAnalyzeClass(args);
108
+ default:
109
+ throw new Error(`Unknown tool: ${name}`);
110
+ }
111
+ }
112
+ catch (error) {
113
+ console.error(`Tool call exception [${name}]:`, error);
114
+ return {
115
+ content: [
116
+ {
117
+ type: 'text',
118
+ text: `Tool call failed: ${error instanceof Error ? error.message : String(error)}\n\nSuggestions:\n1. Check if input parameters are correct\n2. Ensure necessary preparations have been completed\n3. Check server logs for detailed information`,
119
+ },
120
+ ],
121
+ };
122
+ }
123
+ });
124
+ }
125
+ async handleScanDependencies(args) {
126
+ const { projectPath, forceRefresh = false } = args;
127
+ const result = await this.scanner.scanProject(projectPath, forceRefresh);
128
+ return {
129
+ content: [
130
+ {
131
+ type: 'text',
132
+ text: `Dependency scanning complete!\n\n` +
133
+ `Scanned JAR count: ${result.jarCount}\n` +
134
+ `Indexed class count: ${result.classCount}\n` +
135
+ `Index file path: ${result.indexPath}\n\n` +
136
+ `Sample index entries:\n${result.sampleEntries.slice(0, 5).join('\n')}`,
137
+ },
138
+ ],
139
+ };
140
+ }
141
+ async handleDecompileClass(args) {
142
+ const { className, projectPath, useCache = true, cfrPath } = args;
143
+ try {
144
+ console.error(`Starting decompilation of class: ${className}, project path: ${projectPath}, use cache: ${useCache}, CFR path: ${cfrPath || 'auto-detect'}`);
145
+ // Check if index exists, create if not
146
+ await this.ensureIndexExists(projectPath);
147
+ const sourceCode = await this.decompiler.decompileClass(className, projectPath, useCache, cfrPath);
148
+ if (!sourceCode || sourceCode.trim() === '') {
149
+ return {
150
+ content: [
151
+ {
152
+ type: 'text',
153
+ text: `Warning: Decompilation result for class ${className} is empty, possibly due to CFR tool issues or corrupted class file`,
154
+ },
155
+ ],
156
+ };
157
+ }
158
+ return {
159
+ content: [
160
+ {
161
+ type: 'text',
162
+ text: `Decompiled source code for class ${className}:\n\n\`\`\`java\n${sourceCode}\n\`\`\``,
163
+ },
164
+ ],
165
+ };
166
+ }
167
+ catch (error) {
168
+ console.error(`Failed to decompile class ${className}:`, error);
169
+ return {
170
+ content: [
171
+ {
172
+ type: 'text',
173
+ text: `Decompilation failed: ${error instanceof Error ? error.message : String(error)}\n\nSuggestions:\n1. Ensure scan_dependencies has been run to build class index\n2. Check if CFR tool is properly installed\n3. Verify class name is correct`,
174
+ },
175
+ ],
176
+ };
177
+ }
178
+ }
179
+ async handleAnalyzeClass(args) {
180
+ const { className, projectPath } = args;
181
+ // Check if index exists, create if not
182
+ await this.ensureIndexExists(projectPath);
183
+ const analysis = await this.analyzer.analyzeClass(className, projectPath);
184
+ let result = `Analysis result for class ${className}:\n\n`;
185
+ result += `Package name: ${analysis.packageName}\n`;
186
+ result += `Class name: ${analysis.className}\n`;
187
+ result += `Modifiers: ${analysis.modifiers.join(' ')}\n`;
188
+ result += `Super class: ${analysis.superClass || 'None'}\n`;
189
+ result += `Implemented interfaces: ${analysis.interfaces.join(', ') || 'None'}\n\n`;
190
+ if (analysis.fields.length > 0) {
191
+ result += `Fields (${analysis.fields.length}):\n`;
192
+ analysis.fields.forEach(field => {
193
+ result += ` - ${field.modifiers.join(' ')} ${field.type} ${field.name}\n`;
194
+ });
195
+ result += '\n';
196
+ }
197
+ if (analysis.methods.length > 0) {
198
+ result += `Methods (${analysis.methods.length}):\n`;
199
+ analysis.methods.forEach(method => {
200
+ result += ` - ${method.modifiers.join(' ')} ${method.returnType} ${method.name}(${method.parameters.join(', ')})\n`;
201
+ });
202
+ result += '\n';
203
+ }
204
+ return {
205
+ content: [
206
+ {
207
+ type: 'text',
208
+ text: result,
209
+ },
210
+ ],
211
+ };
212
+ }
213
+ /**
214
+ * Ensure index file exists, create automatically if not
215
+ */
216
+ async ensureIndexExists(projectPath) {
217
+ const fs = await import('fs-extra');
218
+ const path = await import('path');
219
+ const indexPath = path.join(projectPath, '.mcp-class-index.json');
220
+ if (!(await fs.pathExists(indexPath))) {
221
+ console.error('Index file does not exist, creating automatically...');
222
+ try {
223
+ await this.scanner.scanProject(projectPath, false);
224
+ console.error('Index file creation complete');
225
+ }
226
+ catch (error) {
227
+ console.error('Failed to create index automatically:', error);
228
+ throw new Error(`Unable to create class index file: ${error instanceof Error ? error.message : String(error)}`);
229
+ }
230
+ }
231
+ }
232
+ async run() {
233
+ const transport = new StdioServerTransport();
234
+ await this.server.connect(transport);
235
+ const env = process.env.NODE_ENV || 'development';
236
+ if (env === 'development') {
237
+ console.error('Java Class Analyzer MCP Server running on stdio (DEBUG MODE)');
238
+ }
239
+ else {
240
+ console.error('Java Class Analyzer MCP Server running on stdio');
241
+ }
242
+ }
243
+ }
244
+ const mcpServer = new JavaClassAnalyzerMCPServer();
245
+ // Add global exception handling to prevent server crashes
246
+ process.on('uncaughtException', (error) => {
247
+ console.error('Uncaught exception:', error);
248
+ // Don't exit process, continue running
249
+ });
250
+ process.on('unhandledRejection', (reason, promise) => {
251
+ console.error('Unhandled Promise rejection:', reason);
252
+ // Don't exit process, continue running
253
+ });
254
+ mcpServer.run().catch((error) => {
255
+ console.error('Server startup failed:', error);
256
+ process.exit(1);
257
+ });
258
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACH,qBAAqB,EACrB,sBAAsB,GACzB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAEtE,MAAM,OAAO,0BAA0B;IAC3B,MAAM,CAAS;IACf,QAAQ,CAAoB;IAC5B,OAAO,CAAoB;IAC3B,UAAU,CAAoB;IAEtC;QACI,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CACpB;YACI,IAAI,EAAE,qBAAqB;YAC3B,OAAO,EAAE,OAAO;SACnB,EACD;YACI,YAAY,EAAE;gBACV,KAAK,EAAE,EAAE;aACZ;SACJ,CACJ,CAAC;QAEF,IAAI,CAAC,QAAQ,GAAG,IAAI,iBAAiB,EAAE,CAAC;QACxC,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAiB,EAAE,CAAC;QACvC,IAAI,CAAC,UAAU,GAAG,IAAI,iBAAiB,EAAE,CAAC;QAE1C,IAAI,CAAC,aAAa,EAAE,CAAC;IACzB,CAAC;IAEO,aAAa;QACjB,IAAI,C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AAS,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IAC5B,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;IAC/C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,52 @@
1
+ export interface ClassIndexEntry {
2
+ className: string;
3
+ jarPath: string;
4
+ packageName: string;
5
+ simpleName: string;
6
+ }
7
+ export interface ScanResult {
8
+ jarCount: number;
9
+ classCount: number;
10
+ indexPath: string;
11
+ sampleEntries: string[];
12
+ }
13
+ export declare class DependencyScanner {
14
+ private indexCache;
15
+ /**
16
+ * Scan all dependencies of a Maven project and build mapping index from class names to JAR packages
17
+ */
18
+ scanProject(projectPath: string, forceRefresh?: boolean): Promise<ScanResult>;
19
+ /**
20
+ * Get all JAR package paths from Maven dependency tree
21
+ */
22
+ private getMavenDependencies;
23
+ /**
24
+ * Scan JAR packages from local Maven repository
25
+ */
26
+ private scanLocalMavenRepo;
27
+ /**
28
+ * Resolve dependency coordinates to get JAR package path
29
+ */
30
+ private resolveJarPath;
31
+ /**
32
+ * Extract all class file information from JAR package
33
+ */
34
+ private extractClassesFromJar;
35
+ /**
36
+ * Find corresponding JAR package path by class name
37
+ */
38
+ findJarForClass(className: string, projectPath: string): Promise<string | null>;
39
+ /**
40
+ * Get all indexed class names
41
+ */
42
+ getAllClassNames(projectPath: string): Promise<string[]>;
43
+ /**
44
+ * Get Maven command path
45
+ */
46
+ private getMavenCommand;
47
+ /**
48
+ * Get Maven local repository path
49
+ */
50
+ private getMavenRepositoryPath;
51
+ }
52
+ //# sourceMappingURL=DependencyScanner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DependencyScanner.d.ts","sourceRoot":"","sources":["../../src/scanner/DependencyScanner.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,eAAe;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,UAAU;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,UAAU,CAA6C;IAE/D;;OAEG;IACG,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,GAAE,OAAe,GAAG,OAAO,CAAC,UAAU,CAAC;IAyE1F;;OAEG;YACW,oBAAoB;IAoClC;;OAEG;YACW,kBAAkB;IA2BhC;;OAEG;YACW,cAAc;IAqB5B;;OAEG;YACW,qBAAqB;IA4CnC;;OAEG;IACG,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAcrF;;OAEG;IACG,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAa9D;;OAEG;IACH,OAAO,CAAC,eAAe;IASvB;;OAEG;IACH,OAAO,CAAC,sBAAsB;CAWjC"}