Java Decompiler MCP Server
An MCP server that uses the CFR decompiler to convert Java .class and .jar files back into readable source code. It supports single-file, batch, and recursive directory decompilation with automated CFR tool management.
README
Java Decompiler MCP Server
一个基于 MCP (Model Context Protocol) 的 Java 反编译工具,使用 CFR 反编译器对 .class 和 .jar 文件进行反编译。
功能特性
- ✅ 单个文件反编译(.class / .jar)
- ✅ 多个文件批量反编译
- ✅ 目录递归扫描反编译
- ✅ 自定义输出目录
- ✅ 自动下载 CFR 反编译器
- ✅ 直接保存到文件系统(避免 token 限制)
- ✅ 实时进度显示
- ✅ 详细统计信息
- ✅ 多线程并发处理(大幅提升速度)
改进亮点
🚀 解决大文件/大量文件反编译问题
问题: 当反编译大量文件时,如果将所有结果作为字符串返回,可能超过 MCP 的 token 限制(例如 413,072 字符)。
解决方案:
-
直接保存到文件系统(推荐)
- 新增
save_to_file参数(默认true) - 反编译结果直接写入指定目录
- 仅返回摘要信息(成功数、失败数、输出路径等)
- 避免通过 MCP 传输大量内容
- 新增
-
实时进度显示
- 新增
show_progress参数(默认true) - 显示当前处理进度:
[1/46] 处理中: Controller.class - 实时反馈处理状态
- 新增
-
详细统计报告
- 成功/失败/跳过文件数
- 生成的 .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(可选): 是否直接保存到文件系统,默认trueshow_progress(可选): 是否显示详细进度,默认truemax_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(可选): 是否递归子目录,默认truesave_to_file(可选): 是否直接保存到文件系统,默认trueshow_progress(可选): 是否显示详细进度,默认truemax_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 反编译器查找顺序:
- 环境变量
CFR_PATH - 项目目录下的
cfr-*.jar - 自动下载(首次调用反编译工具时)
方式一: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
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.