///|
/// mcpbox — carry MCP tools into scripts, CLIs and agents.
///
/// The package is a small MCP client runtime plus the `mcpbox` command line.
/// `main_cli` is the executable entry point; the types, config loader and
/// `Session` API below it are usable as a library.

///|
/// Entry point for the `mcpbox` executable. A failure is reported once, on
/// stderr, and turns into a non-zero exit status.
pub async fn main_cli() -> Unit {
  let args = @env.args()
  let code = try {
    run(args)
    0
  } catch {
    error => {
      // A stopped script is not a failed script: report the interruption the
      // way a shell reports Ctrl-C, with 128 + SIGINT.
      let interrupted = mcpbox_js_interrupted() != 0
      let message = if interrupted { "interrupted" } else { error_text(error) }
      @stdio.stderr.write("mcpbox: \{message}\n") catch {
        _ => ()
      }
      if interrupted {
        130
      } else {
        1
      }
    }
  }
  mcpbox_exit(code)
}