//! apoc executable entry point.
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let argv = std::env::args().skip(1).collect::<Vec<_>>();
if let Some(message) = apoc::cli::exact_argv_cli_error(&argv) {
println!(
"code: VALIDATION_ERROR\nmessage: {}",
serde_json::to_string(message)?
);
std::process::exit(2);
}
// `--mcp` is dispatched by incurs into its default tool-router surface. apoc
// serves Code Mode instead, and an MCP stdio session owns stdout for its
// whole life, so it cannot run inside the command graph's output envelope.
//
// Only a flag before the first `--` selects the surface. Matching anywhere in
// argv hijacked `apoc execution command ... -- --mcp`, where `--mcp` is an
// argument being forwarded to a child and means nothing to apoc.
if argv
.iter()
.take_while(|arg| *arg != "--")
.any(|arg| arg == "--mcp")
{
return apoc::mcp_surface::serve_stdio().await;
}
apoc::build_cli().serve_with(argv).await
}