RecafMCP 标志

RecafMCP

社区
sniperrich

Use MCP to control Recaf4.0 to achieve methods like decompile/rename

发布者sniperrich
代码仓库RecafMCP
语言Java
复刻数
8
星标数
40
可用工具
0
传输类型stdio
链接
  • 将工具接入 AI 工作流

    RecafMCP 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 0 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 40 个星标和 8 个复刻。

Recaf MCP Plugin

Version License: MIT JDK 22+ MCP Protocol Tools

Enable AI assistants to control Recaf 4.x through the Model Context Protocol (MCP) — decompile, search, analyze, edit bytecode, compile Java, assemble/disassemble JASM, diff classes, patch workspaces, deobfuscate, and export Java bytecode directly from your AI workflow.

中文文档

How It Works

The plugin uses a dual-process architecture to bridge AI assistants with Recaf's powerful bytecode analysis engine:

┌─────────────────┐     STDIO / JSON-RPC     ┌─────────────────┐    HTTP :9847     ┌─────────────────┐
│  AI Assistant    │ ◄──────────────────────► │   MCP Server    │ ◄────────────────► │  Recaf Plugin   │
│ (Claude Code,   │                          │ (Standalone JAR) │                    │ (Bridge Server) │
│  Cursor, etc.)  │                          └─────────────────┘                    └────────┬────────┘
└─────────────────┘                                                                          │
                                                                                    ┌────────┴────────┐
                                                                                    │   Recaf 4.x     │
                                                                                    │ (Analysis Engine)│
                                                                                    └─────────────────┘
  • Recaf Plugin (Bridge Server) — Runs inside Recaf's process. Injects Recaf services via CDI (Jakarta) and exposes them as HTTP endpoints on localhost:9847.
  • MCP Server — A standalone fat JAR launched by the AI client. Communicates with the AI via STDIO JSON-RPC and forwards tool calls to the Bridge Server over HTTP.

This separation is necessary because Recaf runs as a JavaFX desktop application with its own module system, while MCP requires a STDIO-based process that the AI client can spawn and manage.

Available MCP Tools (28)

Workspace Management

ToolDescriptionKey Parameters
open_jarOpen a JAR, APK, or class file for analysispath — absolute file path. Returns workspaceId.
close_workspaceClose the current or a specific workspaceworkspaceId (optional) — close by ID
switch_workspaceSwitch to a previously opened workspaceworkspaceId — ID returned by open_jar
list_workspacesList all registered workspaces—
list_classesList classes with offset/limit paginationfilter, offset, limit
get_class_infoGet class details: fields, methods, interfacesclassName
class_outlineLightweight class structure (no code, fast)className
read_fileRead a non-class file (e.g. MANIFEST.MF, configs)path, maxChars
class_deleteDelete a class from the workspaceclassName

Analysis

ToolDescriptionKey Parameters
decompile_classDecompile a class to Java source codeclassName
search_codeSearch strings, references, or declarationsquery, type, maxResults
get_call_graphGet method call graph (callers and callees)className, methodName, depth
get_inheritanceGet inheritance hierarchy (parents/children)className, direction
diff_classesCompare two classes or class vs. source codeclassName1, className2 or source
method_bytecodeView method bytecode instructions (opcodes, operands, try-catch, locals)className, methodName, methodDesc

Compilation & Assembly

ToolDescriptionKey Parameters
compile_javaCompile Java source and apply to workspaceclassName, source, targetVersion, debug
disassemble_classDisassemble a class into JASM textclassName, maxChars
assemble_classAssemble JASM source and apply to workspaceclassName, source
method_disassembleDisassemble a single method into JASM textclassName, methodName, methodDesc, maxChars

Modification

ToolDescriptionKey Parameters
rename_symbolRename class/field/method (updates all refs)type, oldName, newName, className
batch_renameBatch rename classes/fields/methods in one atomic operationmappings — array of {type, oldName, newName, className?, descriptor?}
edit_bytecodeAdd/remove/modify methods and fieldsclassName, operation, + operation-specific params
patchCreate or apply workspace change patchesaction (create/apply), patchJson

Export

ToolDescriptionKey Parameters
export_mappingsExport rename mappings to a fileformat, outputPath
export_jarExport workspace as a JAR fileoutputPath
export_sourceExport decompiled source to a directoryoutputDir, className (optional)

Deobfuscation

ToolDescriptionKey Parameters
eval_methodExecute a static method in a sandboxed ClassLoader (e.g. string decryption)className, methodName, methodDesc, arguments (optional), timeout (optional)
simplify_methodMulti-pass bytecode simplification: constant folding, dead branch elimination, goto chain combining, NOP cleanup, unreachable code removalclassName, methodName, methodDesc, passes (optional)

MCP Resources

URIDescription
recaf://workspaceCurrent workspace information (JSON)
recaf://classesFull class list of the current workspace (JSON)

Prerequisites

  • JDK 22+ — Required by Recaf 4.x. Make sure java on your PATH points to JDK 22 or higher.
  • Recaf 4.x — This plugin is built against snapshot d07958a5c7. The build system will download it automatically.

Build

bash
git clone https://github.com/your-repo/recaf-mcp-plugin.git
cd recaf-mcp-plugin
./gradlew build

This produces two JARs:

FilePurpose
build/libs/recaf-mcp-plugin-1.3.0.jarRecaf plugin (loads inside Recaf, runs the Bridge Server)
build/mcp/recaf-mcp-server-1.3.0.jarMCP Server (standalone fat JAR, launched by AI client)

Setup & Usage

Step 1: Start Recaf with the Plugin

Option A: Run directly from the project (recommended for development)

bash
./gradlew runRecaf

This builds the plugin and launches Recaf with it auto-loaded.

Option B: Manual installation

Copy build/libs/recaf-mcp-plugin-1.3.0.jar to Recaf's plugin directory:

OSPlugin Directory
macOS / Linux~/Recaf/plugins/
Windows%APPDATA%/Recaf/plugins/

Then start Recaf normally.

Verify: Look for this in Recaf's Logging panel:

========================================
  Recaf MCP Plugin enabled
  Bridge Server running on port 9847
========================================

Step 2: Configure Your AI Client

Claude Code

Add to ~/.claude.json:

json
{
  "mcpServers": {
    "recaf": {
      "command": "java",
      "args": ["-jar", "/absolute/path/to/build/mcp/recaf-mcp-server-1.3.0.jar"]
    }
  }
}

Then restart Claude Code. The recaf tools will appear in your tool list.

Cursor

Add to your MCP configuration (Settings → MCP):

json
{
  "mcpServers": {
    "recaf": {
      "command": "java",
      "args": ["-jar", "/absolute/path/to/build/mcp/recaf-mcp-server-1.3.0.jar"]
    }
  }
}

Other MCP-Compatible Clients

Any client that supports the MCP protocol can use this plugin. Configure it to spawn the MCP Server JAR via java -jar over STDIO.

Step 3: Start Using

Once both Recaf and your AI client are running, you can interact naturally:

Open /path/to/target.jar and list all classes
Decompile the com/example/Main class
Search for all strings containing "password"
Show me the call graph for com/example/Main
Rename com/example/a to com/example/LoginManager
Compare com/example/A with com/example/B
Remove the method "unused" from com/example/Foo
Show me the bytecode instructions for com/example/Main.main
Disassemble com/example/Crypto into JASM
Compile this modified Java source back into the workspace
Read the META-INF/MANIFEST.MF file
Create a patch of all my changes
Export the modified JAR to /tmp/output.jar

Example Workflows

Reverse Engineering an Obfuscated JAR

1. "Open /path/to/obfuscated.jar"
2. "List all classes" — get an overview of the package structure
3. "Decompile com/a/b/c" — read the decompiled source
4. "Search for strings containing 'http'" — find network endpoints
5. "Get the call graph for com/a/b/c method d" — understand control flow
6. "Rename com/a/b/c to com/app/NetworkManager" — give it a meaningful name
7. "Export mappings as TinyV1 to ./mappings.tiny" — save your work
8. "Export the modified JAR to ./cleaned.jar" — save the result

Multi-JAR Comparison

1. "Open /path/to/v1.jar" — opens first JAR, returns workspaceId
2. "Open /path/to/v2.jar" — opens second JAR, returns workspaceId
3. "List workspaces" — see both workspaces
4. "Switch to workspace v1-1" — switch to first JAR
5. "Decompile com/example/Main" — get v1 source
6. "Switch to workspace v2-2" — switch to second JAR
7. "Diff com/example/Main against the v1 source" — compare versions

Bytecode Editing

1. "Open /path/to/target.jar"
2. "Remove the method 'checkLicense' from com/app/Main"
3. "Add a public field 'debug' of type boolean to com/app/Config"
4. "Export the modified JAR to /tmp/patched.jar"

Compile & Assemble Round-Trip

1. "Open /path/to/target.jar"
2. "Decompile com/app/Main" — get the Java source
3. (modify the source) → "Compile this Java source for com.app.Main" — compile & apply
4. "Decompile com/app/Main" — verify the changes took effect
5. "Disassemble com/app/Crypto" — get JASM assembly text
6. "Show me the bytecode for com/app/Crypto.encrypt" — inspect method instructions
7. "Create a patch" — save all modifications as JSON
8. "Export the modified JAR to /tmp/patched.jar"

Deobfuscation Workflow

1. "Open /path/to/obfuscated.jar"
2. "Decompile com/a/b/c" — find encrypted strings and decryption method signatures
3. "eval_method com/a/b/Decryptor decrypt (Ljava/lang/String;)Ljava/lang/String; with args [{type:'string', value:'encrypted_data'}]"
   — call the decryption function directly, get plaintext result
4. "simplify_method com/a/b/c main (Ljava/lang/String;)V" — remove opaque predicates and dead branches
5. "Decompile com/a/b/c" — verify the simplified code is cleaner
6. "Batch rename the deobfuscated symbols"
7. "Export the cleaned JAR to /tmp/deobfuscated.jar"

Project Structure

src/main/java/dev/recaf/mcp/
├── RecafMcpPlugin.java                  # Plugin entry point — CDI injection of 14 Recaf services
├── bridge/
│   ├── BridgeServer.java                # HTTP server on :9847 — routes requests to handlers
│   ├── WorkspaceRegistry.java           # Multi-workspace registry — ID → Workspace mapping
│   └── handlers/
│       ├── WorkspaceHandler.java        # /workspace/* — open, close, switch, list, classes, info, outline, read-file, delete-class
│       ├── DecompileHandler.java        # /decompile — decompile class to Java source
│       ├── SearchHandler.java           # /search — string, class, method, field, declaration search
│       ├── AnalysisHandler.java         # /analysis/* — call graph & inheritance hierarchy
│       ├── MappingHandler.java          # /mapping/* — rename symbols & export mappings
│       ├── BytecodeHandler.java         # /bytecode/* — edit/add/remove methods & fields, method bytecode instructions
│       ├── DiffHandler.java             # /diff — compare two classes (unified diff)
│       ├── ExportHandler.java           # /export/* — export JAR & decompiled source
│       ├── CompileHandler.java          # /compile — compile Java source & apply to workspace
│       ├── AssemblerHandler.java        # /disassemble, /assemble — JASM disassembly & assembly
│       └── PatchHandler.java            # /patch — create & apply workspace patches
│       └── DeobfuscationHandler.java    # /deobf/* — eval method (string decryption) & bytecode simplification
├── server/
│   ├── RecafMcpServer.java              # MCP Server — STDIO JSON-RPC, 28 tools dispatch
│   └── BridgeClient.java               # HTTP client — forwards MCP tool calls to Bridge Server
└── util/
    ├── JsonUtil.java                    # JSON response helpers
    ├── ErrorMapper.java                 # Structured error codes, messages & suggestions
    └── DiffUtil.java                    # LCS-based unified diff algorithm

Bridge HTTP API Reference

All endpoints accept POST with JSON body and return JSON responses.

EndpointDescription
GET /healthHealth check — returns {"status":"ok"}
POST /workspace/openOpen a file: {"path": "/path/to/file.jar"} → returns workspaceId
POST /workspace/closeClose workspace: {"workspaceId": "optional"}
GET /workspace/infoGet workspace info
POST /workspace/classesList classes: {"filter": "opt", "offset": 0, "limit": 500}
POST /workspace/class-infoClass details: {"className": "com/example/Main"}
POST /workspace/switchSwitch workspace: {"workspaceId": "xxx"}
GET /workspace/list-workspacesList all registered workspaces
POST /decompileDecompile: {"className": "com/example/Main"}
POST /searchSearch: {"query": "text", "type": "string", "maxResults": 100}
POST /analysis/call-graphCall graph: {"className": "...", "methodName": "...", "depth": 3}
POST /analysis/inheritanceInheritance: {"className": "...", "direction": "both"}
POST /mapping/renameRename: {"type": "class", "oldName": "...", "newName": "..."}
POST /mapping/batch-renameBatch rename: {"mappings": [{"type": "class", "oldName": "...", "newName": "..."}, ...]}
POST /mapping/exportExport mappings: {"format": "TinyV1", "outputPath": "/path"}
POST /bytecode/edit-methodEdit method: {"className": "...", "methodName": "...", "methodDesc": "...", "accessFlags": 1}
POST /bytecode/edit-fieldEdit field: {"className": "...", "fieldName": "...", "accessFlags": 2}
POST /bytecode/remove-memberRemove member: {"className": "...", "memberName": "...", "memberType": "method"}
POST /bytecode/add-fieldAdd field: {"className": "...", "fieldName": "...", "descriptor": "I"}
POST /bytecode/add-methodAdd method: {"className": "...", "methodName": "...", "methodDesc": "()V"}
POST /diffDiff classes: {"className1": "A", "className2": "B"} or {"className1": "A", "source": "..."}
POST /export/jarExport JAR: {"outputPath": "/path/to/output.jar"}
POST /export/sourceExport source: {"outputDir": "/path/to/src", "className": "optional"}
POST /workspace/outlineClass outline: {"className": "com/example/Main"} — lightweight structure, no code
POST /workspace/read-fileRead file: {"path": "META-INF/MANIFEST.MF", "maxChars": 60000}
POST /workspace/delete-classDelete class: {"className": "com/example/Main"}
POST /bytecode/instructionsMethod bytecode: {"className": "...", "methodName": "...", "methodDesc": "..."}
POST /compileCompile Java: {"className": "com.example.Main", "source": "...", "targetVersion": 17, "debug": true}
POST /disassembleDisassemble class: {"className": "com/example/Main", "maxChars": 120000}
POST /disassemble/methodDisassemble method: {"className": "...", "methodName": "...", "methodDesc": "...", "maxChars": 120000}
POST /assembleAssemble JASM: {"className": "com/example/Main", "source": "..."}
POST /patchPatch: {"action": "create"} or {"action": "apply", "patchJson": "..."}
POST /deobf/eval-methodEval method: {"className": "...", "methodName": "...", "methodDesc": "...", "arguments": [...], "timeout": 5000}
POST /deobf/simplify-methodSimplify method: {"className": "...", "methodName": "...", "methodDesc": "...", "passes": 3}

Technical Details

ItemValue
MCP Protocol Version2024-11-05
Bridge Port9847 (hardcoded)
MCP Server DependenciesGson only (no MCP SDK — lightweight custom JSON-RPC implementation)
Decompile Timeout30 seconds
Default Max Search Results100
Default Class List Limit500 (with offset pagination)
Java ToolchainJDK 22+
Build SystemGradle with Shadow plugin for fat JAR
Total MCP Tools28

Troubleshooting

"Connection refused" errors from MCP Server

  • Make sure Recaf is running and the Bridge Server is active on port 9847.
  • Check Recaf's Logging panel for the startup banner.

MCP tools not appearing in AI client

  • Verify the path to recaf-mcp-server-1.3.0.jar is correct and absolute.
  • Make sure java points to JDK 22+: run java -version to check.
  • Restart your AI client after updating the MCP configuration.

Decompilation returns empty or errors

  • Ensure a workspace is open (use open_jar first).
  • Check the class name format: use / separators (e.g. com/example/Main), not . separators.

Structured error responses

  • All errors now include code, message, and suggestion fields.
  • Common codes: NO_WORKSPACE, CLASS_NOT_FOUND, MEMBER_NOT_FOUND, INVALID_PARAMS, DECOMPILE_TIMEOUT, COMPILE_FAILED, ASSEMBLER_FAILED, PATCH_FAILED, EVAL_FAILED, EVAL_TIMEOUT, SIMPLIFY_FAILED.

Build fails

  • Ensure JDK 22+ is installed. Run ./gradlew -q javaToolchains to see detected JDKs.
  • If using a non-default JDK, configure a Gradle toolchain.

Changelog

v1.3.0

  • String decryption — eval_method executes static methods in a sandboxed ClassLoader, enabling direct invocation of obfuscator string decryption functions to recover plaintext
  • Bytecode simplification — simplify_method performs multi-pass bytecode transforms: constant folding, dead branch elimination, goto chain combining, NOP cleanup, and unreachable code removal
  • New error codes — EVAL_FAILED, EVAL_TIMEOUT, SIMPLIFY_FAILED
  • Deobfuscation handler — new DeobfuscationHandler with sandboxed WorkspaceClassLoader (parent = PlatformClassLoader for isolation)
  • COMPUTE_FRAMES fallback — simplify_method falls back to COMPUTE_MAXS if COMPUTE_FRAMES fails on malformed bytecode
  • Tool count: 26 → 28

v1.2.0

  • Batch rename — batch_rename applies multiple class/field/method renames in a single atomic operation, ideal for deobfuscation workflows
  • Java compilation — compile_java compiles Java source code via Recaf's JavacCompiler and applies the result to the workspace
  • JASM assembly/disassembly — disassemble_class and assemble_class for full class JASM round-trip; method_disassemble for single method disassembly
  • Method bytecode viewer — method_bytecode shows detailed bytecode instructions (opcodes, operands, try-catch blocks, local variables) via ASM tree API
  • Class outline — class_outline provides lightweight class structure (fields, methods, access flags) without decompiling code
  • File reader — read_file reads non-class files from the workspace (e.g. MANIFEST.MF, config files, resources)
  • Class deletion — class_delete removes a class from the workspace
  • Patch system — patch tool creates and applies workspace change patches (serializable JSON format)
  • New error codes — COMPILE_FAILED, COMPILER_UNAVAILABLE, PATCH_FAILED
  • 4 new Recaf service injections — AssemblerPipelineManager, JavacCompiler, PatchProvider, PatchApplier
  • Tool count: 16 → 26

v1.1.0

  • Multi-workspace support — open multiple JARs simultaneously, switch between them with switch_workspace and list_workspaces
  • Bytecode editing — edit_bytecode tool with 5 operations: edit_method, edit_field, remove_member, add_field, add_method (ASM-based)
  • Class diff — diff_classes tool produces unified diff between two decompiled classes or class vs. provided source
  • Export — export_jar exports the workspace (with modifications) as a JAR; export_source exports decompiled source to a directory
  • Pagination — list_classes now supports offset/limit with totalMatched/hasMore metadata
  • Structured errors — all errors return code, message, and suggestion fields (e.g. NO_WORKSPACE, CLASS_NOT_FOUND)
  • Error detection — MCP Server now sets isError: true on error responses for better AI client handling
  • Tool count: 10 → 16

v1.0.0

  • Initial release with 10 MCP tools: open_jar, close_workspace, list_classes, get_class_info, decompile_class, search_code, get_call_graph, get_inheritance, rename_symbol, export_mappings

License

MIT

将 RecafMCP MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 RecafMCP 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请勿关闭终端窗口或停止其中的连接器进程。
3

将 RecafMCP 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 RecafMCP MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "recafmcp": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 RecafMCP MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 RecafMCP MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 RecafMCP 帮我完成这项任务吗?
RecafMCP
当然,我看过了。
以下是我使用 RecafMCP 得到的结果。

常见问题

RecafMCP MCP 服务器有什么用途?

RecafMCP 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 RecafMCP MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您无需为每个模型单独配置 MCP 服务器,就能在 Claude、ChatGPT、Gemini 或您在 TypingMind 中配置的其他 AI 模型中使用 RecafMCP。

为什么在 TypingMind 中使用 RecafMCP MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是最出色的大语言模型聊天前端之一。连接 RecafMCP 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 RecafMCP MCP 连接到 TypingMind?

RecafMCP 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

RecafMCP MCP 在 TypingMind 中提供哪些工具?

RecafMCP 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 RecafMCP MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行选择模型提供商,并自行管理 API 密钥、提示词和 MCP 配置。如果 RecafMCP 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇