use protocol_droid::application::client::Client;
use protocol_droid::domain::TransportSpec;
use protocol_droid::domain::ir::JsonObject;
use serde_json::json;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()?;
runtime.block_on(run())
}
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let peer = std::env::var("MCP_PEER").unwrap_or_else(|_| "http://127.0.0.1:3000/mcp".to_owned());
eprintln!("http_client: connecting to {peer}");
let spec: TransportSpec = peer.parse()?;
let client = Client::connect_to(&spec).await?;
let tools = client.list_tools().await?;
eprintln!("server advertises: {tools}", tools = tools.as_str());
let args = JsonObject::from_value(json!({ "text": "hello" }))?;
let reply = client.call_tool("shout", &args).await?;
let reply_value: serde_json::Value = serde_json::from_str(reply.as_str())?;
println!("shout(hello) -> {reply_value}");
Ok(())
}