use std::collections::HashMap;
use anyhow::Result;
use crate::client::protocol::detect_mcp_protocol_with_headers;
use crate::client::support::{CheckArgs, DetectArgs, merge_headers};
pub async fn run_check_command(args: CheckArgs, _verbose: bool, quiet: bool) -> Result<()> {
if !quiet {
eprintln!("Checking service health: {}", &args.url);
}
let headers = merge_headers(HashMap::new(), &args.header, args.auth.as_ref());
match detect_mcp_protocol_with_headers(&args.url, Some(&headers)).await {
Ok(protocol) => {
if !quiet {
eprintln!("Service is healthy (protocol: {protocol})");
}
Ok(())
}
Err(e) => {
if !quiet {
eprintln!("Service check failed: {e}");
}
Err(e)
}
}
}
pub async fn run_detect_command(args: DetectArgs, _verbose: bool, quiet: bool) -> Result<()> {
let headers = merge_headers(HashMap::new(), &args.header, args.auth.as_ref());
let protocol = detect_mcp_protocol_with_headers(&args.url, Some(&headers)).await?;
if quiet {
println!("{}", protocol);
} else {
eprintln!("Detected protocol: {}", protocol);
println!("{}", protocol);
}
Ok(())
}