|
| 1 | +use clap::Parser; |
| 2 | +use docker_git_android_connection::mcp::{run_stdio, McpState}; |
| 3 | +use docker_git_android_connection::{ |
| 4 | + android_spec, DEFAULT_ADB_ENDPOINT, DEFAULT_ANDROID_IMAGE, DEFAULT_PROJECT_ID, |
| 5 | +}; |
| 6 | +use std::io::{self, BufReader}; |
| 7 | +use std::path::PathBuf; |
| 8 | +use std::process::ExitCode; |
| 9 | + |
| 10 | +#[derive(Parser, Debug)] |
| 11 | +#[command(version, about = "Android MCP stdio server for docker-git")] |
| 12 | +struct Cli { |
| 13 | + #[arg(long, default_value = DEFAULT_PROJECT_ID)] |
| 14 | + project: String, |
| 15 | + #[arg(long, default_value = "docker-git-shared")] |
| 16 | + network: String, |
| 17 | + #[arg(long, default_value = DEFAULT_ADB_ENDPOINT)] |
| 18 | + endpoint: String, |
| 19 | + #[arg(long, default_value = DEFAULT_ANDROID_IMAGE)] |
| 20 | + image: String, |
| 21 | + #[arg(long, default_value = ".")] |
| 22 | + workspace: PathBuf, |
| 23 | + #[arg(long)] |
| 24 | + allow_install: bool, |
| 25 | + #[arg(long)] |
| 26 | + no_adb_probe: bool, |
| 27 | +} |
| 28 | + |
| 29 | +fn main() -> ExitCode { |
| 30 | + match run() { |
| 31 | + Ok(()) => ExitCode::SUCCESS, |
| 32 | + Err(error) => { |
| 33 | + eprintln!("{error}"); |
| 34 | + ExitCode::from(1) |
| 35 | + } |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +fn run() -> Result<(), Box<dyn std::error::Error>> { |
| 40 | + let cli = Cli::parse(); |
| 41 | + let spec = android_spec(&cli.project, &cli.network, &cli.endpoint, &cli.image)?; |
| 42 | + let state = McpState { |
| 43 | + spec, |
| 44 | + workspace: cli.workspace, |
| 45 | + adb_probe: !cli.no_adb_probe, |
| 46 | + allow_install: cli.allow_install, |
| 47 | + }; |
| 48 | + let stdin = io::stdin(); |
| 49 | + let stdout = io::stdout(); |
| 50 | + let mut reader = BufReader::new(stdin.lock()); |
| 51 | + let mut writer = stdout.lock(); |
| 52 | + run_stdio(&mut reader, &mut writer, state)?; |
| 53 | + Ok(()) |
| 54 | +} |
0 commit comments