English | 中文
Garlic — the world's fastest APK/Java decompiler — also speaks the Model Context Protocol (MCP).
By running garlic -m, it starts an MCP server over stdio that exposes decompilation, class inspection, call graph analysis, and DuckDB-powered SQL querying to any MCP-compatible AI client (Claude Desktop, Cline, Continue, etc.).
- Garlic v1.6 or later (built with MCP support)
- DuckDB CLI — required. The MCP server uses DuckDB for all analysis features:
https://duckdb.org/install/?platform=macos&environment=cli
Without DuckDB,
analyze,cg_importandcg_querytools will fail.
Download the latest binary for your platform from the GitHub Releases page. Choose the archive matching your OS and architecture (macOS, Linux, Windows; x86_64 or aarch64).
Extract and place the garlic binary somewhere in your PATH, for example:
# macOS / Linux
tar xzf garlic-*.tar.gz
sudo mv garlic /usr/local/bin/git clone https://github.com/neocanable/garlic.git
cd garlic
# Build with CMake
cmake -B build
cmake --build build
# Or with Zig (cross-platform)
zig build --release=fastVerify it works:
./build/garlic -m
# (no output means it started successfully — it's waiting for JSON-RPC messages on stdin)Add to your claude_desktop_config.json (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"garlic": {
"command": "garlic",
"args": ["-m"]
}
}
}If Garlic is not in your system PATH, use the full path:
{
"mcpServers": {
"garlic": {
"command": "/usr/local/bin/garlic",
"args": ["-m"]
}
}
}Add in MCP server settings:
{
"mcpServers": {
"garlic": {
"command": "garlic",
"args": ["-m"]
}
}
}Add to config.json:
{
"experimental": {
"mcpServers": {
"garlic": {
"command": "garlic",
"args": ["-m"]
}
}
}
}You can interact with the MCP server directly:
# List available tools (shows all tool names, descriptions, and JSON schemas)
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | garlic -m
# Try a decompilation
echo '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"dump_info","arguments":{"path":"/path/to/Hello.class"}}}' | garlic -mGarlic MCP provides 7 tools. The tools are listed below in typical workflow order — start with analyze for most reverse-engineering tasks, then drill down with the other tools as needed.
RECOMMENDED ENTRY POINT. One-shot comprehensive analysis: decompile + generate call graph + import into DuckDB, all in one step.
- Input:
path(string) — path to.dexor.apkfile;output_dir(string) — working directory for all outputs. - Output: Creates three items inside
output_dir:decompiled/— Java source files (package-directory hierarchy preserved)cg/— call graph CSV files (call_graph_node.csv,call_graph_edge.csv)analysis.duckdb— DuckDB database with indexedjava_cg_nodes/java_cg_edgestables
- Returns: A summary with Java file count, CG node count, and CG edge count, plus a ready-to-use
cg_query(...)example. - Dependencies: Requires
duckdbCLI installed on PATH. - Use cases: Run this first for most reverse-engineering tasks. After it completes, use:
android_manifestto read app permissions / entry pointscg_queryto explore the call graph via SQL
- Example:
analyze(path="/path/to/app.apk", output_dir="./app_analysis")
Recover readable Java source code from compiled Java/Android binaries.
- Input:
path(string) — path to.class,.jar,.dex, or.apkfile.- Optional
output_dir(string) — when omitted, sources are returned inline and temp files cleaned.
- Optional
- Output: Java source files preserving package directory structure. For APK inputs,
AndroidManifest.xmlis also extracted alongside the sources. - Dependencies: None (standalone — does not require DuckDB).
- Use cases: Use when you only need Java source recovery without call graph or SQL analysis. For full analysis, prefer
analyzeinstead. - Example:
decompile(path="/path/to/app.apk", output_dir="./sources")
Quick-inspect internal class/DEX file structure — methods, fields, constants, annotations, and signatures — without performing full decompilation. Similar to javap or dexdump.
- Input:
path(string) — path to.classor.dexfile. - Output: Structured text showing class/bytecode structure.
- Dependencies: None.
- Use cases: Fast validation of file type, API-surface inspection, checking for obfuscation patterns.
- Example:
dump_info(path="/path/to/classes.dex")
Generate a full call graph for a .dex or .apk file.
- Input:
path(string) — path to.dexor.apkfile.- Optional
output_dir(string) — when omitted, uses a temp directory.
- Optional
- Output: Two (or four) CSV files:
call_graph_node.csv— each row is one method, with columns fornode_id,method_raw,node_type, andapi_typecall_graph_edge.csv— each row is one caller→callee edge (src_id,dst_id)string_node.csv/string_edge.csv— present when string-reference analysis data is available
- Dependencies: None (standalone — does not require DuckDB).
- Use cases: Understanding method dependencies, finding entry points, tracing data flow, detecting unused code. The CSV output is designed for import into DuckDB via
cg_import. - Example:
call_graph(path="/path/to/app.apk", output_dir="./cg_output")
Import call graph CSV files into a DuckDB database with indexed tables for fast SQL analysis.
- Input:
cg_dir(string) — directory produced bycall_graph, containingcall_graph_node.csvandcall_graph_edge.csvdb_path(string) — output path for the.duckdbdatabase file
- Output: A DuckDB database at
db_pathcontaining:java_cg_nodes(node_id, method_raw, node_type, api_type)— method metadata, indexedjava_cg_edges(src_id, dst_id)— call relationships, indexed on both endsstring_nodes/string_edges— created only when the corresponding CSV files exist
- Dependencies: Requires
duckdbCLI installed on PATH. - Use cases: Intermediate step between
call_graphandcg_query. Run this aftercall_graph, then usecg_queryto analyse the database. - Example:
cg_import(cg_dir="./cg_output", db_path="./analysis.duckdb")
Run a SQL query against a call graph DuckDB database (created by cg_import).
- Input:
db_path(string) — path to.duckdbdatabase file (fromcg_import)sql(string) — SQL query to execute
- Output: Query results in CSV format.
- Dependencies: Requires
duckdbCLI installed on PATH. - Database schema:
java_cg_nodes—node_id BIGINT, method_raw VARCHAR, node_type BIGINT, api_type BIGINTjava_cg_edges—src_id BIGINT, dst_id BIGINTstring_nodes— string constants metadata (if imported)string_edges— string-to-method references (if imported)
- Use cases:
- Find all methods called by a given method:
SELECT * FROM java_cg_edges WHERE src_id = ? - Find all callers of a method:
SELECT * FROM java_cg_edges WHERE dst_id = ? - Discover app entry points:
SELECT * FROM java_cg_nodes WHERE api_type > 0 - Find unused (zero-callee) methods:
SELECT n.* FROM java_cg_nodes n LEFT JOIN java_cg_edges e ON n.node_id = e.dst_id WHERE e.dst_id IS NULL - Count API calls by type:
SELECT node_type, COUNT(*) FROM java_cg_nodes GROUP BY node_type
- Find all methods called by a given method:
- Important: Queries run in read-only mode — the database is never modified.
- Example:
cg_query(db_path="./analysis.duckdb", sql="SELECT method_raw, node_type FROM java_cg_nodes LIMIT 20")
Read AndroidManifest.xml from a previous decompile or analyze output directory.
- Input:
output_dir(string) — the directory used withdecompileoranalyze. - Output: Full XML content of AndroidManifest.xml, including:
- App permissions (
<uses-permission>) - Activity, service, broadcast receiver, and content provider declarations
- Intent filters and exported-component flags
- App permissions (
- Dependencies: None.
- Use cases: After decompiling an APK, use this to understand the app's attack surface, entry points, declared permissions, and inter-component communication (ICC) surface.
- Example:
android_manifest(output_dir="./app_analysis")
analyze(path, output_dir) ← Start here for most tasks
├─ decompile(path, output_dir?) ← Or use individually
├─ dump_info(path) ← Quick peek at structure
└─ call_graph(path, output_dir?) ← Generate call graph CSVs
└─ cg_import(cg_dir, db_path) ← Import into DuckDB
└─ cg_query(db_path, sql) ← Analyse with SQL
android_manifest(output_dir) ← Read app permissions (after decompile/analyze)
garlic -mexits immediately — no input on stdin when used interactively. Configure it in your MCP client instead.- Tool returns empty results — file not found or wrong path. Verify the path exists and garlic can read it.
cg_import/cg_queryfail — DuckDB not installed. Install withbrew install duckdb.duckdb: command not found— DuckDB not in PATH. Install DuckDB or provide full path.decompilereturns error — unsupported or malformed file. Check the file type (class/jar/dex/apk).- Slow response on large APK — large file processing. Decompilation is fast (200MB APK in ~12s), but very large files may take longer.
If garlic was built in debug mode (without NDEBUG), MCP log messages go to stderr:
garlic -m 2>/dev/null # suppress
garlic -m # show in terminal- Server name:
garlic-mcp - Version:
1.0.0 - MCP Protocol:
2024-11-05 - Transport: stdio (JSON-RPC 2.0)
- Max message size: 1 MB
Apache 2.0 — see LICENSE.