Skip to main content
Glama
handsomestWei

Java Class Analyzer MCP Server

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[];
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states what the tool does (analyzes class structure) but doesn't describe behavioral traits such as whether it's read-only, what permissions are needed, how it handles errors, or what the output format looks like. For a tool with no annotations, this leaves significant gaps in understanding its operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence in Chinese: '分析Java类的结构、方法、字段等信息'. It's front-loaded with the core purpose and wastes no words, making it highly concise and well-structured for quick understanding.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of analyzing Java classes, the lack of annotations, and no output schema, the description is incomplete. It doesn't cover what information is returned, how the analysis is performed, or any behavioral context. For a tool with two required parameters and no structured output, more detail is needed to guide effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with clear parameter descriptions in Chinese. The tool description doesn't add any meaning beyond what the schema provides—it doesn't explain parameter interactions, constraints, or usage examples. With high schema coverage, the baseline score is 3, as the description doesn't compensate but also doesn't detract.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '分析Java类的结构、方法、字段等信息' (analyze Java class structure, methods, fields, etc.). It specifies the verb 'analyze' and the resource 'Java class', making the purpose unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'decompile_class' or 'scan_dependencies', which prevents a score of 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools or any context for choosing this analysis tool over decompilation or dependency scanning. There's no information about prerequisites or exclusions, leaving usage entirely implied from the purpose statement.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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