1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(
name = "adbridge",
about = "Android Bridge for AI-Assisted Development",
version
)]
pub struct Cli {
/// Target device serial number (uses first connected device if omitted)
#[arg(long, global = true)]
pub device: Option<String>,
#[command(subcommand)]
pub command: Command,
}
#[derive(Subcommand)]
pub enum Command {
/// Capture screenshot with optional OCR and view hierarchy
Screen(ScreenArgs),
/// Stream or query logcat with filtering
Log(LogArgs),
/// Send input to device (keyboard, tap, swipe, clipboard)
Input(InputArgs),
/// Query current device/app state
State(StateArgs),
/// Get crash context (stacktrace + screenshot + recent actions)
Crash(CrashArgs),
/// List connected Android devices
Devices(DevicesArgs),
/// Start MCP server (stdio transport)
Serve,
}
#[derive(clap::Args)]
pub struct DevicesArgs {
/// Output as JSON
#[arg(long, default_value_t = false)]
pub json: bool,
}
#[derive(clap::Args)]
pub struct ScreenArgs {
/// Run OCR on the screenshot
#[arg(long, default_value_t = false)]
pub ocr: bool,
/// Include view hierarchy from uiautomator
#[arg(long, default_value_t = false)]
pub hierarchy: bool,
/// List interactive UI elements with tap coordinates
#[arg(long, default_value_t = false)]
pub elements: bool,
/// Save screenshot to file instead of stdout
#[arg(short, long)]
pub output: Option<String>,
/// Output as JSON (for piping)
#[arg(long, default_value_t = false)]
pub json: bool,
}
#[derive(clap::Args)]
pub struct LogArgs {
/// Filter by application package name
#[arg(long)]
pub app: Option<String>,
/// Filter by log tag
#[arg(long)]
pub tag: Option<String>,
/// Minimum log level (verbose, debug, info, warn, error, fatal)
#[arg(long, default_value = "verbose")]
pub level: String,
/// Number of recent lines to show (0 = stream live)
#[arg(short, long, default_value_t = 50)]
pub lines: u32,
/// Output as JSON
#[arg(long, default_value_t = false)]
pub json: bool,
}
#[derive(clap::Args)]
pub struct InputArgs {
#[command(subcommand)]
pub action: InputAction,
}
#[derive(Subcommand)]
pub enum InputAction {
/// Type text on the device
Text {
/// The text to type
value: String,
},
/// Tap at screen coordinates
Tap {
/// X coordinate
x: u32,
/// Y coordinate
y: u32,
},
/// Swipe between coordinates
Swipe {
x1: u32,
y1: u32,
x2: u32,
y2: u32,
/// Duration in milliseconds
#[arg(short, long, default_value_t = 300)]
duration: u32,
},
/// Send a key event (home, back, enter, etc.)
Key {
/// Key name (home, back, enter, menu, power, volup, voldown)
name: String,
},
/// Push text to device clipboard
Clip {
/// Text to set on clipboard
text: String,
},
}
#[derive(clap::Args)]
pub struct StateArgs {
/// Output as JSON
#[arg(long, default_value_t = false)]
pub json: bool,
/// Include memory statistics
#[arg(long, default_value_t = false)]
pub memory: bool,
}
#[derive(clap::Args)]
pub struct CrashArgs {
/// Output as JSON
#[arg(long, default_value_t = false)]
pub json: bool,
}