use std::io::Write as _;
use std::path::Path;
use anyhow::Result;
use openmoat_hosts::Host;
use crate::home::Home;
use crate::render::Deferred;
pub(super) struct Proxy {
pub sandbox: Option<bool>,
}
pub(super) fn servers(
home: &Home,
binary: &Path,
proxy: Option<Proxy>,
hosts: &[Host],
hold: bool,
out: &mut Deferred,
) -> Result<()> {
let cwd = std::env::current_dir().ok();
let pinned = crate::mcp::pin_current(home, binary, cwd.as_deref(), hold)?;
writeln!(
out,
"✔ mcp servers {} definitions pinned; a changed or new one waits for `openmoat mcp accept`",
pinned.count
)?;
if !pinned.held.is_empty() {
writeln!(
out,
"! mcp servers {} not pinned: no person at a terminal to accept them; their tool \
calls are denied until you run `openmoat mcp accept` in a terminal",
pinned.held.len()
)?;
for change in &pinned.held {
writeln!(out, " {}", change.describe().replace('\n', "\n "))?;
}
}
if let Some(proxy) = proxy {
super::super::mcp::wrap_servers(home, binary, hosts, &[], proxy.sandbox, false, out)?;
}
Ok(())
}