Skip to main content

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.json 或 claude_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.json 的 env 中设置:

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

方式二:放到项目目录

将 cfr-*.jar 文件放到项目根目录,会自动识别。

方式三:自动下载

调用 download_cfr_tool 工具,会自动从镜像下载到项目目录。

手动运行测试

# 激活虚拟环境
source .venv/bin/activate

# 运行 MCP 服务器
uv run main.py

许可证

MIT License

Metadata

Release files for iflow-mcp_ruoji6-java-decompile-mcp 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iflow-mcp_ruoji6-java-decompile-mcp 0.3.1
File Size Uploaded
iflow_mcp_ruoji6_java_decompile_mcp-0.3.1.tar.gz 9.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for iflow-mcp_ruoji6-java-decompile-mcp 0.3.1
File Interpreter ABI Platform
iflow_mcp_ruoji6_java_decompile_mcp-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 19.6 kB

Release files / iflow_mcp_ruoji6_java_decompile_mcp-0.3.1.tar.gz

Download URL iflow_mcp_ruoji6_java_decompile_mcp-0.3.1.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
991f1f126bed8458212c173ad0e435a626057a5e8b1fcd9fd560f24be1e09c51
BLAKE2b-256 checksum
How to use checksums
3c20e889998450bb533bcc6045af372c1e375eb7734f865c1cbe80dd81b2c9c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / iflow_mcp_ruoji6_java_decompile_mcp-0.3.1-py3-none-any.whl

Download URL iflow_mcp_ruoji6_java_decompile_mcp-0.3.1-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f108a0841f150644e5f1afa1f832a80ade008abc7edfbbc0c641486957143a84
BLAKE2b-256 checksum
How to use checksums
3ac7b2f50b1b319575866dd9a19bb9b254cde941340370285f65d28e4935cff3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page