use crate::cli::McpArgs;
use crate::error::CliResult;
use crate::mcp::{McpContext, serve_stdio};
use tokio::io::BufReader;
pub async fn run(args: McpArgs) -> CliResult<()> {
let cwd = std::env::current_dir()?;
let env_path =
crate::env_loader::resolve_env_file(args.env_file.as_deref(), args.no_env_file, &cwd)?;
crate::env_loader::load_env_file_if_present(env_path.as_deref())?;
let auth = crate::auth_catalog::build_auth_catalog(None)?;
#[cfg_attr(not(feature = "templates"), allow(unused_mut))]
let mut ctx = McpContext::new(auth, args.allow_mutations);
#[cfg(feature = "templates")]
if let Some(url) = args.template_store.as_deref() {
ctx = ctx.with_templates(crate::templates::resolve_store_url(url).await?);
tracing::info!(store = %url, "pipeline-template registry attached");
}
tracing::info!(
allow_mutations = args.allow_mutations,
"faucet mcp stdio server started"
);
let mut stdout = tokio::io::stdout();
serve_stdio(&ctx, BufReader::new(tokio::io::stdin()), &mut stdout).await?;
tracing::info!("faucet mcp stdio server stopped (stdin closed)");
Ok(())
}