use futures::stream::StreamExt;
use iflow_cli_sdk_rust::{EnvVariable, IFlowClient, IFlowOptions, McpServer};
use iflow_cli_sdk_rust::error::IFlowError;
use std::io::Write;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.init();
let local = tokio::task::LocalSet::new();
local.run_until(async {
use std::path::PathBuf;
let mcp_servers = vec![
McpServer::Stdio {
name: "sequential-thinking".to_string(),
command: PathBuf::from("npx"),
args: vec!["-y".to_string(), "@iflow-mcp/server-sequential-thinking@0.6.2".to_string()],
env: vec![
EnvVariable {
name: "DEBUG".to_string(),
value: "1".to_string(),
meta: None,
}
],
}
];
let options = IFlowOptions::new()
.with_mcp_servers(mcp_servers)
.with_process_config(
iflow_cli_sdk_rust::types::ProcessConfig::new()
.enable_auto_start()
.start_port(8090)
)
.with_logging_config(iflow_cli_sdk_rust::types::LoggingConfig {
enabled: true,
level: "INFO".to_string(),
logger_config: iflow_cli_sdk_rust::logger::LoggerConfig {
enabled: true,
log_file: "logs/iflow_client_mcp.log".into(),
max_file_size: 10 * 1024 * 1024, max_files: 5,
},
});
let mut client = IFlowClient::new(Some(options));
client.connect().await?;
let prompt = "use sequential-thinking mcp server List files in the current directory, calc total font nums";
println!("📤 Sending: {}", prompt);
match client.send_message(prompt, None).await {
Ok(()) => {
println!("✅ Message sent successfully");
}
Err(IFlowError::Timeout(msg)) => {
eprintln!("⏰ Timeout error occurred: {}", msg);
eprintln!("This may be due to MCP server startup time or processing delays.");
eprintln!("Consider increasing the timeout or checking MCP server configuration.");
}
Err(e) => {
eprintln!("❌ Error sending message: {}", e);
return Err(e.into());
}
}
let mut message_stream = client.messages();
while let Some(message) = message_stream.next().await {
match message {
iflow_cli_sdk_rust::Message::Assistant { content } => {
print!("{}", content);
std::io::stdout().flush()?;
}
iflow_cli_sdk_rust::Message::TaskFinish { .. } => {
break;
}
_ => {
println!("Received other message type");
}
}
}
client.disconnect().await?;
Ok(())
}).await
}