KeiSeiKit-1.0/_ts_packages/packages/mcp-server/BUILD.md
Parfii-bot e67ade47c8 feat(v0.18): kei-mcp-server single-binary compile — 5-platform via bun
Phase 1 of exobrain architecture. Ships TS MCP server as a static
binary so users on machines without Node can run KeiSeiKit (USB /
flashdrive / air-gapped scenarios).

.github/workflows/release.yml (+62 LOC) — new build-mcp-binary job:
  - 5-target matrix: darwin arm64/x64, linux arm64/x64, windows x64
  - bun build --compile, linux arm64 continue-on-error (ARM runners
    less reliable)
  - Artifact kei-mcp-server-<os>-<arch>[.exe] + sha256
  - release job now needs [build-release, build-mcp-binary]

install/lib-rust.sh (+50 LOC) — have_prebuilt_mcp_server() +
  report_mcp_server_binary_status(); KEI_SKIP_MCP_BUILD=1 env
  flag skips bun/npm install when a prebuilt binary is present.
  File 165 LOC (<200 limit).

_ts_packages/packages/mcp-server/package.json — scripts.build:native
  + 5 per-target aliases (macos-arm, macos-x64, linux-x64,
  linux-arm, win-x64) for local dev.

_ts_packages/packages/mcp-server/BUILD.md (NEW, 52 LOC) — local
  compile guide per platform + Gatekeeper/code-sign notes +
  cites bun docs [VERIFIED: https://bun.sh/docs/bundler/executables].

README.md pre-built-binaries section gains 'MCP server binary'
subsection (download, chmod +x, xattr -d com.apple.quarantine for
macOS, UAC note for Windows).

CHANGELOG.md [Unreleased] bullet added.

Output size: ~90 MB per binary (bundled bun runtime). Acceptable
trade for zero-dep USB distribution.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 15:52:36 +08:00

2.3 KiB
Raw Blame History

Building a single-binary kei-mcp-server

KeiSeiKit v0.18 Phase 1 (exobrain) — ship the MCP server as a portable static binary so any machine without Node can run it off a USB drive.

Tooling

Compile via bun (bun build --compile). Bundles the Bun runtime + JS into one static executable — no Node, no node_modules/ at runtime. Requires bun >= 1.0. Docs (target list + flags): [VERIFIED: https://bun.sh/docs/bundler/executables]

Supported targets

Platform Arch --target= Output name
Linux x64 bun-linux-x64 kei-mcp-server-linux-x64
Linux arm64 bun-linux-arm64 kei-mcp-server-linux-arm64
macOS x64 bun-darwin-x64 kei-mcp-server-darwin-x64
macOS arm64 bun-darwin-arm64 kei-mcp-server-darwin-arm64
Windows x64 bun-windows-x64 kei-mcp-server-windows-x64.exe

Local build

cd _ts_packages/packages/mcp-server
bun install
bun run build:native                       # host-native
bun run build:native:darwin-arm64          # explicit cross-target

Output lands in dist/. Size ~8595 MB per binary (bundled runtime).

Release build (CI)

.github/workflows/release.yml → job build-mcp-binary runs the 5-target matrix on tag push (v*) and attaches binaries + .sha256 sums to the GitHub release. Runtime requirement: none (static).

Troubleshooting

  • macOS Gatekeeper (“cannot be opened because Apple cannot check it for malicious software”) — remove the quarantine attribute: xattr -d com.apple.quarantine ./kei-mcp-server-darwin-arm64
  • Windows SmartScreen / AV flags — not signed; right-click → Properties → Unblock, or add an AV exclusion for the binary path.
  • Missing symbol at startup — usually a native-only dep that resolved at runtime on Node but cannot be bundled. Re-run bun install, then bun build --compile ... --smol to surface the resolution error.
  • .js ESM imports fail — the mcp-server source imports via .js suffix (ESM canonical). Bun resolves these from the sibling .ts file automatically; no tsc pre-step needed.