Skip to main content
Glama
handsomestWei

Java Class Analyzer MCP Server

scan_dependencies

Scans Maven project dependencies to create a class-to-JAR mapping index for accurate Java code analysis and dependency resolution.

Instructions

扫描Maven项目的所有依赖,建立类名到JAR包的映射索引

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectPathYesMaven项目根目录路径
forceRefreshNo是否强制刷新索引

Implementation Reference

  • Core logic implementing the dependency scanning: gets Maven deps, extracts classes from each JAR, builds index, caches to .mcp-class-index.json.
    async scanProject(projectPath: string, forceRefresh: boolean = false): Promise<ScanResult> {
        const indexPath = path.join(projectPath, '.mcp-class-index.json');
        const isDebug = process.env.NODE_ENV === 'development';
    
        // 如果强制刷新,先删除旧的索引文件
        if (forceRefresh && await fs.pathExists(indexPath)) {
            if (isDebug) {
                console.error('强制刷新:删除旧的索引文件');
            }
            await fs.remove(indexPath);
        }
    
        // 检查缓存
        if (!forceRefresh && await fs.pathExists(indexPath)) {
            if (isDebug) {
                console.error('使用缓存的类索引');
            }
            const cachedIndex = await fs.readJson(indexPath);
            return {
                jarCount: cachedIndex.jarCount,
                classCount: cachedIndex.classCount,
                indexPath,
                sampleEntries: cachedIndex.sampleEntries
            };
        }
    
        if (isDebug) {
            console.error('开始扫描Maven依赖...');
        }
    
        // 1. 获取Maven依赖树
        const dependencies = await this.getMavenDependencies(projectPath);
        console.error(`找到 ${dependencies.length} 个依赖JAR包`);
    
        // 2. 解析每个JAR包,建立类索引
        const classIndex: ClassIndexEntry[] = [];
        let processedJars = 0;
    
        for (const jarPath of dependencies) {
            try {
                const classes = await this.extractClassesFromJar(jarPath);
                classIndex.push(...classes);
                processedJars++;
    
                if (processedJars % 10 === 0) {
                    console.error(`已处理 ${processedJars}/${dependencies.length} 个JAR包`);
                }
            } catch (error) {
                console.warn(`处理JAR包失败: ${jarPath}, 错误: ${error}`);
            }
        }
    
        // 3. 保存索引到文件
        const result: ScanResult = {
            jarCount: processedJars,
            classCount: classIndex.length,
            indexPath,
            sampleEntries: classIndex.slice(0, 10).map(entry =>
                `${entry.className} -> ${path.basename(entry.jarPath)}`
            )
        };
    
        await fs.outputJson(indexPath, {
            ...result,
            classIndex,
            lastUpdated: new Date().toISOString()
        }, { spaces: 2 });
    
        console.error(`扫描完成!处理了 ${processedJars} 个JAR包,索引了 ${classIndex.length} 个类`);
    
        return result;
    }
  • MCP server handler for scan_dependencies tool call: extracts args, calls DependencyScanner, returns MCP-formatted response.
    private async handleScanDependencies(args: any) {
        const { projectPath, forceRefresh = false } = args;
    
        const result = await this.scanner.scanProject(projectPath, forceRefresh);
    
        return {
            content: [
                {
                    type: 'text',
                    text: `依赖扫描完成!\n\n` +
                        `扫描的JAR包数量: ${result.jarCount}\n` +
                        `索引的类数量: ${result.classCount}\n` +
                        `索引文件路径: ${result.indexPath}\n\n` +
                        `示例索引条目:\n${result.sampleEntries.slice(0, 5).join('\n')}`,
                },
            ],
        };
    }
  • Input JSON Schema for scan_dependencies tool.
    inputSchema: {
        type: 'object',
        properties: {
            projectPath: {
                type: 'string',
                description: 'Maven项目根目录路径',
            },
            forceRefresh: {
                type: 'boolean',
                description: '是否强制刷新索引',
                default: false,
            },
        },
        required: ['projectPath'],
    },
  • src/index.ts:123-125 (registration)
    Registration of tool handlers in CallToolRequestSchema switch statement.
    switch (name) {
        case 'scan_dependencies':
            return await this.handleScanDependencies(args);
  • src/index.ts:51-69 (registration)
    Tool metadata registration (name, desc, schema) in ListToolsRequestSchema handler.
    {
        name: 'scan_dependencies',
        description: '扫描Maven项目的所有依赖,建立类名到JAR包的映射索引',
        inputSchema: {
            type: 'object',
            properties: {
                projectPath: {
                    type: 'string',
                    description: 'Maven项目根目录路径',
                },
                forceRefresh: {
                    type: 'boolean',
                    description: '是否强制刷新索引',
                    default: false,
                },
            },
            required: ['projectPath'],
        },
    },
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 describes what the tool does (scanning and indexing) but lacks critical behavioral details: it doesn't specify whether this is a read-only operation, what permissions are required, whether it modifies any files, how long it might take, or what the output format is. For a tool with no annotation coverage, this leaves significant gaps in understanding its behavior.

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 that directly states the tool's purpose without any fluff. It's appropriately sized and front-loaded, with every word contributing to understanding the core functionality. There's no wasted verbiage or redundancy.

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 scanning and indexing dependencies, the lack of annotations, and no output schema, the description is incomplete. It doesn't explain what the output looks like (e.g., a mapping structure, file location, or error handling), nor does it cover behavioral aspects like performance or side effects. For a tool that likely involves file system operations and data processing, more context is needed.

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 schema description coverage is 100%, meaning the input schema already fully documents both parameters ('projectPath' and 'forceRefresh'). The description adds no additional parameter semantics beyond what's in the schema. According to the rules, when schema coverage is high (>80%), the baseline score is 3 even with no param info in the description.

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: '扫描Maven项目的所有依赖,建立类名到JAR包的映射索引' (Scan all dependencies of a Maven project, build a class name to JAR package mapping index). It uses specific verbs ('扫描' - scan, '建立' - build) and identifies the resource (Maven project dependencies). However, it doesn't explicitly differentiate from sibling tools like 'analyze_class' or 'decompile_class', which appear to be related but distinct operations.

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 when this tool is appropriate, what prerequisites might be needed, or how it relates to the sibling tools ('analyze_class' and 'decompile_class'). The agent must infer usage from the purpose alone.

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