Skip to main content
Glama

analyze_class

Analyze Java class structures, methods, and fields by scanning Maven projects and decompiling JAR files to provide accurate class information for code generation.

Instructions

分析Java类的结构、方法、字段等信息

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
classNameYes要分析的Java类全名
projectPathYesMaven项目根目录路径

Implementation Reference

  • MCP tool handler for 'analyze_class': parses input arguments, ensures dependency index exists, delegates analysis to JavaClassAnalyzer, formats and returns the structured class information as text.
    private async handleAnalyzeClass(args: any) { const { className, projectPath } = args; // 检查索引是否存在,如果不存在则先创建 await this.ensureIndexExists(projectPath); const analysis = await this.analyzer.analyzeClass(className, projectPath); let result = `类 ${className} 的分析结果:\n\n`; result += `包名: ${analysis.packageName}\n`; result += `类名: ${analysis.className}\n`; result += `修饰符: ${analysis.modifiers.join(' ')}\n`; result += `父类: ${analysis.superClass || '无'}\n`; result += `实现的接口: ${analysis.interfaces.join(', ') || '无'}\n\n`; if (analysis.fields.length > 0) { result += `字段 (${analysis.fields.length}个):\n`; analysis.fields.forEach(field => { result += ` - ${field.modifiers.join(' ')} ${field.type} ${field.name}\n`; }); result += '\n'; } if (analysis.methods.length > 0) { result += `方法 (${analysis.methods.length}个):\n`; analysis.methods.forEach(method => { result += ` - ${method.modifiers.join(' ')} ${method.returnType} ${method.name}(${method.parameters.join(', ')})\n`; }); result += '\n'; } return { content: [ { type: 'text', text: result, }, ], }; }
  • Input schema definition for the 'analyze_class' tool, specifying required parameters className and projectPath.
    { name: 'analyze_class', description: '分析Java类的结构、方法、字段等信息', inputSchema: { type: 'object', properties: { className: { type: 'string', description: '要分析的Java类全名', }, projectPath: { type: 'string', description: 'Maven项目根目录路径', }, }, required: ['className', 'projectPath'], }, },
  • src/index.ts:128-129 (registration)
    Tool dispatch registration in the CallToolRequestSchema handler switch statement.
    case 'analyze_class': return await this.handleAnalyzeClass(args);
  • Core analysis logic: finds JAR for class using scanner, invokes javap via analyzeClassWithJavap, returns ClassAnalysis.
    async analyzeClass(className: string, projectPath: string): Promise<ClassAnalysis> { try { // 1. 获取类文件路径 const jarPath = await this.scanner.findJarForClass(className, projectPath); if (!jarPath) { throw new Error(`未找到类 ${className} 对应的JAR包`); } // 2. 直接使用 javap 分析JAR包中的类 const analysis = await this.analyzeClassWithJavap(jarPath, className); return analysis; } catch (error) { console.error(`分析类 ${className} 失败:`, error); throw error; } }
  • Type definition for the output structure of class analysis (used internally by handler).
    className: string; packageName: string; modifiers: string[]; superClass?: string; interfaces: string[]; fields: ClassField[]; methods: ClassMethod[]; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/handsomestWei/java-class-analyzer-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server