Skip to content

Commit f325bb7

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
feat: binder-mcp remote mode — MCP server proxying to device via gadb
Add --mode remote that runs the MCP server on the host and proxies binder transactions to an Android device through adb port-forwarding. The remote mode creates a gadb proxy Session (cross-compiles and pushes the daemon, starts it, sets up port forwarding), probes the device's version table by trying listServices with each candidate revision's transaction code, then serves the same 6 MCP tools as device mode. Key design: ToolSet.sm is now a ServiceLookup interface satisfied by both the real servicemanager.ServiceManager (device mode) and the new remoteServiceManager (remote mode). The remoteServiceManager sends binder transactions through RemoteTransport using AIDL descriptors, with lazy descriptor discovery via a well-known service name map and INTERFACE_TRANSACTION probing.
1 parent 9a14db1 commit f325bb7

4 files changed

Lines changed: 714 additions & 11 deletions

File tree

cmd/binder-mcp/device.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ func runDevice(cmd *cobra.Command, _ []string) error {
6060
sm := servicemanager.New(transport)
6161

6262
tools := &ToolSet{
63-
sm: sm,
64-
transport: transport,
63+
sm: sm,
6564
}
6665

6766
mcpServer := server.NewMCPServer(

cmd/binder-mcp/main.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//go:build linux
22

33
// binder-mcp is an MCP server that exposes Android binder services as
4-
// tools for AI agents. It runs on-device and communicates via stdio,
5-
// so an agent can connect through `adb shell /data/local/tmp/binder-mcp`.
4+
// tools for AI agents. In device mode it runs on-device (agents connect
5+
// via adb shell); in remote mode it runs on the host and proxies binder
6+
// transactions to a device through adb port-forwarding.
67
package main
78

89
import (
@@ -22,7 +23,8 @@ const (
2223
// ModeDevice runs the MCP server on-device, opening /dev/binder directly.
2324
ModeDevice Mode = "device"
2425

25-
// ModeRemote is a placeholder for future adb-bridge mode.
26+
// ModeRemote runs the MCP server on the host and proxies binder
27+
// transactions to an Android device via gadb.
2628
ModeRemote Mode = "remote"
2729
)
2830

@@ -33,8 +35,11 @@ func newRootCmd() *cobra.Command {
3335
cmd := &cobra.Command{
3436
Use: "binder-mcp",
3537
Short: "MCP server exposing Android binder services as AI-agent tools",
36-
Long: `binder-mcp opens /dev/binder and serves Model Context Protocol (MCP)
37-
tools over stdio. AI agents connect via adb shell /data/local/tmp/binder-mcp.`,
38+
Long: `binder-mcp serves Model Context Protocol (MCP) tools over stdio.
39+
40+
In device mode it opens /dev/binder directly (agents connect via
41+
adb shell /data/local/tmp/binder-mcp). In remote mode it proxies
42+
binder transactions to a device through adb port-forwarding.`,
3843
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
3944
l := logrus.Default().WithLevel(logLevel)
4045
ctx := belt.CtxWithBelt(cmd.Context(), belt.New())
@@ -47,7 +52,7 @@ tools over stdio. AI agents connect via adb shell /data/local/tmp/binder-mcp.`,
4752
case ModeDevice:
4853
return runDevice(cmd, args)
4954
case ModeRemote:
50-
return fmt.Errorf("remote mode is not yet implemented")
55+
return runRemoteMode(cmd, args)
5156
default:
5257
return fmt.Errorf("unknown mode %q; supported: device, remote", mode)
5358
}
@@ -63,7 +68,12 @@ tools over stdio. AI agents connect via adb shell /data/local/tmp/binder-mcp.`,
6368
(*string)(&mode),
6469
"mode",
6570
string(ModeDevice),
66-
"operating mode: device (on-device binder) or remote (adb bridge, not yet implemented)",
71+
"operating mode: device (on-device binder) or remote (adb bridge via gadb)",
72+
)
73+
cmd.Flags().String(
74+
"serial",
75+
"",
76+
"device serial for remote mode (empty = auto-discover first device)",
6777
)
6878
cmd.Flags().String(
6979
"binder-device",

0 commit comments

Comments
 (0)