use anyhow::Result;
use mcp_tester::tester::ServerTester;
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::fmt::init();
let url = std::env::args()
.nth(1)
.unwrap_or_else(|| "http://localhost:3004".to_string());
println!("đ Connecting to MCP server at: {}", url);
println!();
let mut tester = ServerTester::new(
&url,
Duration::from_secs(30),
false,
None,
Some("http"),
None,
)?;
println!("đĄ Initializing connection...");
let init_result = tester.test_initialize().await;
if init_result.status != mcp_tester::report::TestStatus::Passed {
eprintln!("â Failed to initialize: {}", init_result.name);
return Ok(());
}
println!("â
Connected successfully");
println!();
println!("đ§ Discovering tools...");
let tools_result = tester.test_tools_list().await;
if tools_result.status != mcp_tester::report::TestStatus::Passed {
eprintln!("â Failed to list tools: {}", tools_result.name);
return Ok(());
}
println!("â
Found tools");
println!();
println!("đ¨ Discovering tools with UIs...");
tester.load_all_tool_uis().await?;
let tool_uis = tester.get_tool_uis();
if tool_uis.is_empty() {
println!("âšī¸ No tools with UI metadata found");
println!();
println!("đĄ Make sure the server implements UI resources with:");
println!(" - UIResourceBuilder for creating UIs");
println!(" - TypedTool.with_ui() to associate tools with UIs");
println!();
return Ok(());
}
println!("â
Found {} tool(s) with UIs:", tool_uis.len());
for (tool_name, ui_info) in tool_uis {
println!(" - {} â {}", tool_name, ui_info.ui_resource_uri);
}
println!();
println!("đ Rendering UIs to HTML files...");
for (tool_name, _ui_info) in tool_uis {
let filename = format!("{}_ui.html", tool_name.replace("_", "-"));
let output_path = std::env::current_dir()?.join(&filename);
tester.render_tool_ui(tool_name, output_path.to_str().unwrap())?;
}
println!();
println!("â
Done! UI files generated.");
println!();
println!("đ To view the UIs:");
println!(" 1. Open the HTML file(s) in your browser");
println!(" 2. Click 'đ Toggle Debug' to show/hide the debug panel");
println!(" 3. Tool calls will be logged in the debug panel");
println!();
println!("âšī¸ Note: This is a static viewer. Tool calls are logged but not executed.");
println!(" For interactive testing, use the HTTP server mode (coming soon).");
Ok(())
}