---
name: unmbt-ciallo-js
description: Use when deploying an unmbt/ciallo App (including MCP Streamable HTTP servers) to Cloudflare Workers, Vercel Edge, Deno, Bun, or Node.js via the MoonBit js target.
---

# unmbt/ciallo-js

Pure `js` (`-all+js`) adapter with `FixedArray`/`Bytes` FFI (zero `[0020]` warnings), multi-value `Set-Cookie` append, `ReadableStream` backpressure streaming, `ctx.waitUntil` passthrough, and built-in Node.js / Bun HTTP + SSE server (`serve`).

## Node.js 18+ & Bun 1.x Entrypoint Pattern (Zero Glue JS)
In your executable package `moon.pkg`:
```moonbit nocheck
supported_targets = "-all+js"
pkgtype(kind: "executable")
options(link: { "js": { "format": "esm" } })
```
In `main.mbt`:
```moonbit nocheck
async fn main {
  let app = build_app() // e.g. mcp.mount_http(@core.App::App())
  let server = @ciallo_js.serve(app, host="127.0.0.1", port=3000, on_listen=p => {
    println("Listening on http://127.0.0.1:\{p}")
  })
  // `serve` auto-uses `Bun.serve` on Bun and dynamic `import("node:http")` on Node.js
  // Call `server.close()` to stop and run `app.stop_lifecycles()`
  ignore(server)
}
```
Run directly with `node _build/js/release/build/.../app.js` or `bun _build/js/release/build/.../app.js`.

## Cloudflare Workers Entrypoint Pattern
In your Worker package `moon.pkg`:
```moonbit nocheck
supported_targets = "-all+js"
pkgtype(kind: "foreign_library")
options(link: { "js": { "format": "esm" } })
```
In `worker.mbt`:
```moonbit nocheck
let handler = @ciallo_js.to_fetch_handler(try! build_app())
#export_name("fetch")
pub fn worker_fetch(req : @ciallo_js.JsRequest, env : @ciallo_js.JsEnv, ctx : @ciallo_js.JsExecutionContext) -> @js_async.Promise[@ciallo_js.JsResponse] {
  handler(req, env, ctx)
}
```
> `serve()` uses dynamic `await import("node:http")` only when called on Node.js, so Cloudflare Workers bundles using `to_fetch_handler` remain 100% free of static `node:*` imports.
