fix(android): let the bridge advertise its own tool schemas

Listing the bridge tools closed the connection. The bridge copied each
property from the pinned engine's schema, and that schema has no
`overload_index` for `get_xrefs_to_method`, so the advertised map carried
a null that kotlinx serialization cannot write. Only `tools/list` was
affected: REA calls tools by name, which is why the real lanes never saw
it, and the same defect reproduces against the 0.7.1 engine.

The bridge now declares the properties and required fields it accepts, so
an engine bump can neither advertise a null nor drop the overload
selector REA relies on. The real Android lane lists the live catalog to
keep the shape under test. One tool list serves both the consumed set and
the reimplementation loop, unknown names fail fast instead of inheriting
a method-shaped schema, and the identity moves to 12 because main's JNI
split-qualification change already owns 11.

Validation: build:cached, check:fast, docs:check, test:focused over the
Android boundary files, and verify:android against the real 0.8.0 JAR and
ApiDemos 6.0.18. The new catalog step passes; the lane still stops at the
pre-existing `missing java` recovery expectation, which this change does
not touch.
This commit is contained in:
Xiangfang Chen authored and Ysopwnable committed 2026-11-22 16:01:00 +08:00
1 parent 3ca89d8272
commit 2b6ede2d0c
3 files changed
+157 -27

No files matched your search

+55 -26
View File
@@ -49,7 +49,7 @@ class ReaJadxBridge {
// REA reads this identity from this source (JadxRelease.ts), so it is typed
// once. Change BRIDGE_VERSION with any protocol change REA must not mix.
static final String BRIDGE_NAME = "rea-jadx-bridge";
static final String BRIDGE_VERSION = "11";
static final String BRIDGE_VERSION = "12";
private static final Gson JSON = new Gson();
private final SessionHolder holder;
private JadxSession indexedSession;
@@ -1079,6 +1079,20 @@ class ReaJadxBridge {
return json(result);
}
/** Shared input guidance for the bridge's exact-selection tools. */
private static final kotlinx.serialization.json.JsonObject CLASS_NAME_PROPERTY =
property("string", "Exact class name.");
private static final kotlinx.serialization.json.JsonObject METHOD_NAME_PROPERTY =
property("string", "Method name inside the selected class.");
private static final kotlinx.serialization.json.JsonObject OVERLOAD_INDEX_PROPERTY =
property("integer", "0-based index when the name is overloaded; omit for the single overload.");
private static kotlinx.serialization.json.JsonObject property(String type, String description) {
return new kotlinx.serialization.json.JsonObject(Map.of(
"type", kotlinx.serialization.json.JsonElementKt.JsonPrimitive(type),
"description", kotlinx.serialization.json.JsonElementKt.JsonPrimitive(description)));
}
private static void registerBridgeTool(Server server, ReaJadxBridge bridge, String name,
ToolSchema schema, String description) {
Tool tool = new Tool(name, schema, description, null, null, null, null, null, null);
@@ -1112,9 +1126,11 @@ class ReaJadxBridge {
server.removeTool("load_apk");
server.addTool(loadTool, (connection, request, continuation) ->
bridge.load(request.getArguments(), defaults, continuation));
Set<String> consumed = Set.of("load_apk",
List<String> reimplementedTools = List.of(
"list_classes", "get_class_summary", "get_method_body",
"get_xrefs_to_class", "get_xrefs_to_method");
Set<String> consumed = new HashSet<>(reimplementedTools);
consumed.add("load_apk");
for (String name : new ArrayList<>(server.getTools().keySet()))
if (!consumed.contains(name)) server.removeTool(name);
Tool diagnostics = new Tool("rea_jvm_status",
@@ -1133,39 +1149,52 @@ class ReaJadxBridge {
registerBridgeTool(server, bridge, name,
new ToolSchema(null, new kotlinx.serialization.json.JsonObject(Map.of()), List.of(), null), description);
}
for (String name : List.of("list_classes", "get_class_summary",
"get_method_body", "get_xrefs_to_class", "get_xrefs_to_method")) {
Tool tool = server.getTools().get(name).getTool();
// REA owns these input schemas: it pages inventories and selects overloads
// itself, so the pinned engine's shape cannot describe what it accepts.
for (String name : reimplementedTools) {
server.removeTool(name);
List<String> fields = switch (name) {
case "list_classes" -> List.of("offset", "limit");
case "get_method_body" -> List.of("class_name", "method_name", "overload_index");
case "get_xrefs_to_method" -> List.of("class_name", "method_name", "overload_index");
default -> List.of("class_name");
};
Map<String, kotlinx.serialization.json.JsonElement> properties = new LinkedHashMap<>();
for (String field : fields) properties.put(field, tool.getInputSchema().getProperties().get(field));
if (name.equals("list_classes")) properties.put("query",
new kotlinx.serialization.json.JsonObject(Map.of(
"type", kotlinx.serialization.json.JsonElementKt.JsonPrimitive("string"))));
if (name.equals("get_class_summary")) properties.put("dex_static_values",
new kotlinx.serialization.json.JsonObject(Map.of(
"type", kotlinx.serialization.json.JsonElementKt.JsonPrimitive("boolean"))));
if (name.equals("get_class_summary") || name.equals("get_xrefs_to_method"))
properties.put("reference_target", new kotlinx.serialization.json.JsonObject(Map.of(
"type", kotlinx.serialization.json.JsonElementKt.JsonPrimitive("boolean"))));
if (name.equals("get_class_summary")) properties.put("method_name",
new kotlinx.serialization.json.JsonObject(Map.of(
"type", kotlinx.serialization.json.JsonElementKt.JsonPrimitive("string"))));
List<String> required;
switch (name) {
case "list_classes" -> {
properties.put("offset", property("integer", "Inventory position to start listing from."));
properties.put("limit", property("integer", "Maximum matching class names to return."));
properties.put("query", property("string", "Case-sensitive substring matched against top-level class names; omit or leave empty to inventory every name."));
required = List.of();
}
case "get_class_summary" -> {
properties.put("class_name", CLASS_NAME_PROPERTY);
properties.put("dex_static_values", property("boolean", "Include encoded static final field values."));
required = List.of("class_name");
}
case "get_method_body" -> {
properties.put("class_name", CLASS_NAME_PROPERTY);
properties.put("method_name", METHOD_NAME_PROPERTY);
properties.put("overload_index", OVERLOAD_INDEX_PROPERTY);
required = List.of("class_name", "method_name");
}
case "get_xrefs_to_class" -> {
properties.put("class_name", CLASS_NAME_PROPERTY);
required = List.of("class_name");
}
case "get_xrefs_to_method" -> {
properties.put("class_name", CLASS_NAME_PROPERTY);
properties.put("method_name", METHOD_NAME_PROPERTY);
properties.put("overload_index", OVERLOAD_INDEX_PROPERTY);
required = List.of("class_name", "method_name");
}
default -> throw new IllegalStateException("Unhandled reimplemented tool: " + name);
}
String description = switch (name) {
case "list_classes" -> "Pages of case-sensitive matching top-level class names; offset and next_offset are inventory positions, limit bounds matching rows. Omitted or empty query inventories all names.";
case "get_class_summary" -> "Parsed member metadata for one exact class name; no source generation. Set dex_static_values to include encoded static final field values.";
case "get_method_body" -> "Source for an exact class and stable same-name overload index; static initializers use smali to preserve folded field initialization.";
default -> "Complete static using-node inventory for an exact class or selected method overload; one node may contain multiple invoke instructions, and source lines are unresolved.";
case "get_xrefs_to_class", "get_xrefs_to_method" -> "Complete static using-node inventory for an exact class or selected method overload; one node may contain multiple invoke instructions, and source lines are unresolved.";
default -> throw new IllegalStateException("Unhandled reimplemented tool: " + name);
};
registerBridgeTool(server, bridge, name,
new ToolSchema(null, new kotlinx.serialization.json.JsonObject(properties),
tool.getInputSchema().getRequired(), null), description);
required, null), description);
}
CountDownLatch done = new CountDownLatch(1);
server.onClose(() -> { done.countDown(); return Unit.INSTANCE; });
+13 -1
View File
@@ -15,6 +15,7 @@ import { verifyAndroidCliCancellation } from "./cli-cancellation.mjs";
import { verifyAndroidMetadata } from "./metadata.mjs";
import { verifyAndroidClassSearch } from "./class-search.mjs";
import { verifyAndroidFailureRecovery } from "./failure-recovery.mjs";
import { verifyAndroidBridgeCatalog } from "./bridge-catalog.mjs";
import { resolveJadxConfigurationInputs } from "../../../dist/android/JadxConfiguration.js";
import { HOST_PLATFORM } from "../../../dist/platform/HostPlatform.js";
import { validateVerifierJadxConfiguration } from "../../lib/jadx-configuration-inspection.mjs";
@@ -56,6 +57,10 @@ const entrypoint =
process.env.REA_ANDROID_ENTRYPOINT ?? resolve(repository, "scripts/rea.mjs");
const environment = { ...process.env, REA_JADX_MCP_JAR: resolve(jar) };
const path = resolve(apk);
const bridge = resolve(
dirname(entrypoint),
"../bridge/android/ReaJadxBridge.java",
);
await verifyAndroidMetadata({
java,
jar: resolve(jar),
@@ -65,7 +70,14 @@ await verifyAndroidMetadata({
jvmArguments,
entrypoint,
environment,
bridge: resolve(dirname(entrypoint), "../bridge/android/ReaJadxBridge.java"),
bridge,
});
await verifyAndroidBridgeCatalog({
java,
jar: resolve(jar),
bridge,
repository,
jvmArguments,
});
const tasks = [
{
+89
View File
@@ -0,0 +1,89 @@
import assert from "node:assert/strict";
import { Client } from "@modelcontextprotocol/client";
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
import { jadxBridgeIdentity } from "../../../dist/android/JadxRelease.js";
/**
* Input schemas the bridge advertises for the tools it reimplements. REA owns
* these, so a caller can page, select over one overload and read manifest facts
* without depending on whichever schema the pinned engine happens to publish.
*/
const expectedInputs = {
list_classes: { properties: ["offset", "limit", "query"], required: [] },
get_class_summary: {
properties: ["class_name", "dex_static_values"],
required: ["class_name"],
},
get_method_body: {
properties: ["class_name", "method_name", "overload_index"],
required: ["class_name", "method_name"],
},
get_xrefs_to_class: { properties: ["class_name"], required: ["class_name"] },
get_xrefs_to_method: {
properties: ["class_name", "method_name", "overload_index"],
required: ["class_name", "method_name"],
},
rea_jvm_status: { properties: [], required: [] },
rea_native_declarations: { properties: ["path"], required: ["path"] },
get_app_info: { properties: [], required: [] },
get_android_manifest: { properties: [], required: [] },
};
/** Prove the real bridge advertises a serializable, REA-owned tool catalog. */
export const verifyAndroidBridgeCatalog = async ({
java,
jar,
bridge,
repository,
jvmArguments = [],
}) => {
const bridgeIdentity = jadxBridgeIdentity();
if (!bridgeIdentity.ok) throw new Error(bridgeIdentity.error);
const transport = new StdioClientTransport({
command: java,
args: [...jvmArguments, "-classpath", jar, bridge],
cwd: repository,
stderr: "pipe",
});
const client = new Client({ name: "rea-bridge-catalog", version: "1" });
try {
await client.connect(transport);
assert.deepEqual(
client.getServerVersion(),
{
name: bridgeIdentity.value.name,
version: bridgeIdentity.value.version,
},
"The bridge must report the identity REA expects",
);
const tools = new Map(
(await client.listTools()).tools.map((tool) => [tool.name, tool]),
);
assert.deepEqual(
[...tools.keys()].sort(),
[...Object.keys(expectedInputs), "load_apk"].sort(),
"The bridge must advertise only the tools REA consumes",
);
assert.ok(
tools.get("load_apk").inputSchema.properties?.path,
"load_apk must keep advertising the caller's target path",
);
for (const [name, expected] of Object.entries(expectedInputs)) {
const { inputSchema } = tools.get(name);
assert.deepEqual(
Object.keys(inputSchema.properties ?? {}).sort(),
[...expected.properties].sort(),
`${name} input properties`,
);
assert.deepEqual(
[...(inputSchema.required ?? [])].sort(),
[...expected.required].sort(),
`${name} required fields`,
);
}
console.log("PASS real bridge tool catalog and input schemas");
} finally {
await client.close();
await transport.close();
}
};