(server: String, action: McpCommands)
| 3691 | } |
| 3692 | |
| 3693 | async fn handle_mcp_command(server: String, action: McpCommands) -> anyhow::Result<()> { |
| 3694 | let client = reqwest::Client::new(); |
| 3695 | |
| 3696 | match action { |
| 3697 | McpCommands::List => { |
| 3698 | let endpoint = server_url(&server, "/mcp"); |
| 3699 | let status_map: HashMap<String, McpStatusEntry> = |
| 3700 | parse_http_json(client.get(endpoint).send().await?).await?; |
| 3701 | |
| 3702 | if status_map.is_empty() { |
| 3703 | println!("No MCP servers reported."); |
| 3704 | return Ok(()); |
| 3705 | } |
| 3706 | |
| 3707 | println!("\nMCP servers:\n"); |
| 3708 | let mut items: Vec<_> = status_map.into_values().collect(); |
| 3709 | items.sort_by(|a, b| a.name.cmp(&b.name)); |
| 3710 | |
| 3711 | for server_info in items { |
| 3712 | println!( |
| 3713 | " {:<20} {:<12} tools={} resources={}", |
| 3714 | server_info.name, server_info.status, server_info.tools, server_info.resources |
| 3715 | ); |
| 3716 | if let Some(error) = server_info.error { |
| 3717 | println!(" error: {}", error); |
| 3718 | } |
| 3719 | } |
| 3720 | println!(); |
| 3721 | } |
| 3722 | McpCommands::Add { |
| 3723 | name, |
| 3724 | url, |
| 3725 | command, |
| 3726 | args, |
| 3727 | enabled, |
| 3728 | timeout, |
| 3729 | } => { |
| 3730 | let config = if let Some(url) = url { |
| 3731 | serde_json::json!({ |
| 3732 | "type": "remote", |
| 3733 | "url": url, |
| 3734 | "enabled": enabled, |
| 3735 | "timeout": timeout |
| 3736 | }) |
| 3737 | } else if let Some(command) = command { |
| 3738 | serde_json::json!({ |
| 3739 | "command": command, |
| 3740 | "args": args, |
| 3741 | "enabled": enabled, |
| 3742 | "timeout": timeout |
| 3743 | }) |
| 3744 | } else { |
| 3745 | anyhow::bail!("`mcp add` requires either --url (remote) or --command (local)"); |
| 3746 | }; |
| 3747 | |
| 3748 | let endpoint = server_url(&server, "/mcp"); |
| 3749 | let _: HashMap<String, McpStatusEntry> = parse_http_json( |
| 3750 | client |
no test coverage detected