Skip to main content
Glama
java-class-analyzer-mcp

java-class-analyzer-mcp

by Aorls

Java Class Analyzer MCP

通用Java类分析MCP工具,让AI自动分析Maven项目依赖中的类。

核心特性

✅ 完整JavaDoc支持 - 自动从sources.jar读取原始源码
✅ 智能降级 - sources.jar → CFR → javap 四级降级
✅ 通用可配置 - 支持任何Maven项目和groupId
✅ 灵活配置 - 通过mcp.json或config.json配置
✅ 自动化 - CFR反编译器可选自动下载

Related MCP server: Maven Package README MCP Server

快速开始

1. 安装

cd .cursor/java-class-analyzer
npm install

2. 配置(可选)

有三种配置方式,按优先级:

方式一:通过 .cursor/mcp.json(推荐)

{
  "mcpServers": {
    "java-class-analyzer": {
      "command": "node",
      "args": [".cursor/java-class-analyzer/index.js"],
      "env": {
        "MAVEN_REPO": "${HOME}/.m2/repository",
        "GROUP_ID_MAPPINGS": "[{\"groupId\":\"com/mycompany\",\"prefix\":\"com.mycompany.\"}]"
      }
    }
  }
}

方式二:本地config.json

复制 config.example.json 为 config.json 并修改:

cp config.example.json config.json

方式三:使用默认配置

默认支持常见的groupId:

  • com.ql.*

  • com.qinglusaas.*

  • io.quarkus.*

  • io.quarkiverse.*

  • org.apache.commons.*

  • org.springframework.*

3. 使用

  1. 重启Cursor

  2. 在对话中: "请初始化Java类索引"

  3. 开始使用: "请分析 [类名]"

配置选项

Maven仓库路径

环境变量: MAVEN_REPO
默认值: ${HOME}/.m2/repository

{
  "env": {
    "MAVEN_REPO": "/custom/path/to/.m2/repository"
  }
}

GroupId映射

环境变量: GROUP_ID_MAPPINGS (JSON数组)
说明: 用于识别JAR文件名中的groupId前缀

{
  "env": {
    "GROUP_ID_MAPPINGS": "[{\"groupId\":\"com/mycompany\",\"prefix\":\"com.mycompany.\"}]"
  }
}

或在config.json中:

{
  "groupIdMappings": [
    { "groupId": "com/mycompany", "prefix": "com.mycompany." },
    { "groupId": "org/example", "prefix": "org.example." }
  ]
}

CFR路径

环境变量: CFR_JAR_PATH
默认值: cfr.jar(当前目录)

{
  "env": {
    "CFR_JAR_PATH": "/path/to/cfr.jar"
  }
}

反编译策略

在config.json中配置:

{
  "decompile": {
    "enableSourcesJar": true,
    "enableCFR": true,
    "enableJavap": true
  }
}

反编译优先级

工具会按以下优先级获取源码:

优先级

方式

JavaDoc

质量

说明

1

sources.jar

✅

最高

Maven源码包

2

CFR

❌

高

反编译器

3

javap

❌

中

JDK工具

4

基本信息

❌

低

兜底

MCP工具

  • java_class_indexer - 构建类索引

  • java_class_analyzer - 分析反编译类

  • java_class_search - 搜索类

适用项目

  • ✅ 所有Maven项目

  • ✅ 任何groupId

  • ✅ 公司内部二方包

  • ✅ 开源第三方库

Available Tools

3 tools
java_class_analyzerA

分析和反编译指定的Java类。根据类的全限定名查找对应的JAR包并进行反编译,返回源代码。

Inputs: className (required).

java_class_indexerA

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

Inputs: no named parameters.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.2/5.0

    Scored across 3 tools

    Disambiguation5/5

    Each tool has a clearly distinct role: one builds the index, one searches it, and one decompiles a specific class. There is no functional overlap or ambiguity between them.

    Naming Consistency5/5

    All tools share the java_class_ prefix and follow the same noun-style naming pattern: indexer, analyzer, search. This creates a predictable and recognizable set.

    Tool Count5/5

    Three tools is well-scoped for a Java class analysis server: index, search, and analyze. Each tool is necessary and the count feels complete without being bloated.

    Completeness5/5

    The tool surface covers the full workflow: building an index from Maven dependencies, searching indexed classes by keyword, and analyzing/decompiling a selected class. There are no obvious dead ends or missing operations for the stated purpose.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      C
      maintenance
      Enables AI tools to analyze Java dependencies by scanning Maven projects, decompiling JAR files, and extracting detailed class information including methods, fields, and inheritance relationships. Solves the problem of AI hallucinations when generating code that calls external dependencies by providing accurate class structures through decompilation.
      3
      13 npm
      41
      Apache 2.0
    • A
      license
      Not graded
      quality
      A
      maintenance
      Indexes local Maven and Gradle caches to enable AI agents to search for Java classes, method signatures, and source code, including from internal or obscure libraries.
      64 npm
      23
      ISC