Java Decompiler MCP Server

$uvx java-decompile-mcp
README.md

Convert .class and .jar files into readable Java source code using CFR.

Java Decompiler MCP Server

一个基于 MCP (Model Context Protocol) 的 Java 反编译工具,使用 CFR 反编译器对 .class.jar 文件进行反编译。

功能特性

  • ✅ 单个文件反编译(.class / .jar)
  • ✅ 多个文件批量反编译
  • ✅ 目录递归扫描反编译
  • ✅ 自定义输出目录
  • ✅ 自动下载 CFR 反编译器
  • ✅ 直接保存到文件系统(避免 token 限制)
  • ✅ 实时进度显示
  • ✅ 详细统计信息
  • 多线程并发处理(大幅提升速度)

改进亮点

🚀 解决大文件/大量文件反编译问题

问题: 当反编译大量文件时,如果将所有结果作为字符串返回,可能超过 MCP 的 token 限制(例如 413,072 字符)。

解决方案:

  1. 直接保存到文件系统(推荐)

    • 新增 save_to_file 参数(默认 true
    • 反编译结果直接写入指定目录
    • 仅返回摘要信息(成功数、失败数、输出路径等)
    • 避免通过 MCP 传输大量内容
  2. 实时进度显示

    • 新增 show_progress 参数(默认 true
    • 显示当前处理进度:[1/46] 处理中: Controller.class
    • 实时反馈处理状态
  3. 详细统计报告

    • 成功/失败/跳过文件数
    • 生成的 .java 文件总数
    • 输出目录路径
    • 清晰的格式化输出

使用示例

场景 1:反编译大量文件(推荐方式)

# 使用 8 个线程并发处理,大幅提升速度
decompile_directory(
    directory_path="/path/to/classes",
    output_dir="/path/to/output",
    save_to_file=True,      # 默认值
    show_progress=True,     # 显示进度
    max_workers=8           # 8 线程并发
)

场景 2:反编译少量文件并查看内容

# 返回反编译内容(仅适用于小文件)
decompile_file(
    file_path="/path/to/MyClass.class",
    save_to_file=False      # 返回内容而不是保存
)

场景 3:静默批量处理

# 不显示详细进度,仅返回统计,单线程处理
decompile_files(
    file_paths=[...],
    show_progress=False,    # 仅显示统计信息
    max_workers=1           # 单线程
)

环境要求

  • Python >= 3.10
  • Java Runtime Environment (JRE)
  • uv (Python 包管理器)

安装

方式一:通过 uvx 直接使用(推荐)

无需安装,直接在 MCP 配置中使用(可让ai自动下载cfr-0.152.jar然后你手动配置路径):

{
  "mcpServers": {
    "java-decompiler": {
      "type": "stdio",
      "command": "uvx",
      "args": ["java-decompile-mcp"],
      "env": {
        "CFR_PATH": "/你的路径/cfr-0.152.jar"
      },
      "disabled": false
    }
  }
}

方式二:本地开发

# 克隆项目
git clone <repository-url>
cd java-decompile-mcp

# 创建虚拟环境并安装依赖
uv venv
source .venv/bin/activate  # macOS/Linux
# 或 .venv\Scripts\activate  # Windows

uv pip install "mcp>=1.0.0"

MCP 配置

方式一:使用 uvx(推荐,已发布到 PyPI)

.kiro/settings/mcp.jsonclaude_desktop_config.json 中添加:

{
  "mcpServers": {
    "java-decompiler": {
      "command": "uvx",
      "args": ["java-decompile-mcp"],
      "disabled": false
    }
  }
}

方式二:本地开发模式

.kiro/settings/mcp.json 中添加:

{
  "mcpServers": {
    "java-decompiler": {
      "command": "uv",
      "args": [
        "--directory",
        "/项目路径",
        "run",
        "main.py"
      ],
      "disabled": false,
      "autoApprove": []
    }
  }
}

⚠️ 本地开发模式需要将路径替换为实际的项目路径

项目地址

GitHub: https://github.com/RuoJi6/java-decompile-mcp

可用工具

1. decompile_file

反编译单个文件

参数:

  • file_path (必需): 要反编译的文件路径
  • output_dir (可选): 输出目录,默认为文件所在目录下的 decompiled 文件夹
  • save_to_file (可选): 是否直接保存到文件系统,默认 true(推荐)

示例:

反编译 /path/to/MyClass.class 到 /output/dir

返回结果:

✅ 反编译成功
源文件: /path/to/MyClass.class
输出目录: /output/dir
生成文件数: 1
提示: 反编译结果已保存到文件系统

2. decompile_files

批量反编译多个文件(支持多线程)

参数:

  • file_paths (必需): 文件路径列表
  • output_dir (可选): 输出目录
  • save_to_file (可选): 是否直接保存到文件系统,默认 true
  • show_progress (可选): 是否显示详细进度,默认 true
  • max_workers (可选): 最大并发线程数,默认 4(设为 1 则单线程)

示例:

反编译以下文件:
- /path/to/Class1.class
- /path/to/Class2.class
- /path/to/app.jar
使用 8 个线程并发处理

返回结果:

✅ [1/3] 成功: Class1.class
✅ [2/3] 成功: Class2.class
✅ [3/3] 成功: app.jar

============================================================
📊 反编译完成统计
============================================================
✅ 成功: 3
❌ 失败: 0
⏭️  跳过: 0
📁 总计: 3 个文件
📄 生成: 46 个 .java 文件
📂 输出目录: /output/dir
🔧 并发线程: 4
============================================================
💾 反编译结果已保存到文件系统

3. decompile_directory

反编译目录下所有 .class 和 .jar 文件(支持多线程)

参数:

  • directory_path (必需): 目录路径
  • output_dir (可选): 输出目录
  • recursive (可选): 是否递归子目录,默认 true
  • save_to_file (可选): 是否直接保存到文件系统,默认 true
  • show_progress (可选): 是否显示详细进度,默认 true
  • max_workers (可选): 最大并发线程数,默认 4

示例:

反编译 /path/to/classes 目录下的所有 class 文件,使用 8 个线程

返回结果:

📂 扫描目录: /path/to/classes
🔍 找到 46 个文件待反编译
📤 输出目录: /path/to/classes/decompiled
🔧 并发线程: 4

✅ [1/46] 成功: Controller1.class
✅ [2/46] 成功: Controller2.class
...
✅ [46/46] 成功: Utils.class

============================================================
📊 反编译完成统计
============================================================
✅ 成功: 46
❌ 失败: 0
⏭️  跳过: 0
📁 总计: 46 个文件
📄 生成: 46 个 .java 文件
📂 输出目录: /path/to/classes/decompiled
🔧 并发线程: 4
============================================================
💾 反编译结果已保存到文件系统

4. download_cfr_tool

下载 CFR 反编译器

参数:

  • target_dir (可选): 下载目标目录,默认当前工作目录

5. check_cfr_status

检查 CFR 反编译器状态

6. get_java_version

获取 Java 版本信息

CFR 配置

CFR 反编译器查找顺序:

  1. 环境变量 CFR_PATH
  2. 项目目录下的 cfr-*.jar
  3. 自动下载(首次调用反编译工具时)

方式一:MCP 配置中指定(推荐)

mcp.jsonenv 中设置:

{
  "mcpServers": {
    "java-decompiler": {
      "command": "uv",
      "args": ["--directory", "/项目路径", "run", "main.py"],
      "env": {
        "CFR_PATH"

Tools (6)

decompile_fileDecompile a single .class or .jar file into Java source code.
decompile_filesBatch decompile multiple files with multi-threading support.
decompile_directoryRecursively scan and decompile all .class and .jar files in a directory.
download_cfr_toolDownload the CFR decompiler executable.
check_cfr_statusCheck the current status and availability of the CFR decompiler.
get_java_versionRetrieve the installed Java version information.

Environment Variables

CFR_PATHPath to the CFR decompiler jar file

Configuration

claude_desktop_config.json
{"mcpServers":{"java-decompiler":{"command":"uvx","args":["java-decompile-mcp"],"env":{"CFR_PATH":"/path/to/cfr-0.152.jar"},"disabled":false}}}

Try it

Decompile the file /path/to/MyClass.class and save the result to /output/dir.
Batch decompile all .class files in /path/to/classes using 8 threads for speed.
Recursively decompile the entire /path/to/project directory and save the source code to a new folder.
Check if the CFR decompiler is installed and what version of Java I am running.
Download the CFR tool to my current working directory.

Frequently Asked Questions

What are the key features of Java Decompiler MCP Server?

Multi-threaded concurrent processing for high-speed batch decompilation.. Direct file system output to bypass MCP token limits for large files.. Recursive directory scanning for .class and .jar files.. Automatic CFR decompiler downloading and environment status checking.. Real-time progress tracking and detailed statistical reporting..

What can I use Java Decompiler MCP Server for?

Analyzing legacy Java libraries where source code is unavailable.. Performing security audits on compiled .jar dependencies.. Recovering lost source code from compiled production artifacts.. Large-scale codebase analysis by converting binary files to readable text.. Debugging third-party Java components by inspecting their internal logic..

How do I install Java Decompiler MCP Server?

Install Java Decompiler MCP Server by running: uvx java-decompile-mcp

What MCP clients work with Java Decompiler MCP Server?

Java Decompiler MCP Server works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Use Java Decompiler MCP Server with Conare

Manage MCP servers visually, upload persistent context, and never start from zero with Claude Code & Codex.

Try Free