Architecture Decision Records (ADRs)
Architecture Decision Records document the key technical choices, trade-offs, and invariants governing the Shukoi framework.
ADR-001: Adaptive TypeBox JIT Validation Probe
- Status: Accepted
- Context: Node.js and Bun support JIT code compilation via
new Function(), enabling TypeBox's ultra-fastTypeCompiler. However, Cloudflare Workers V8 isolates strictly forbid dynamic code generation at runtime (eval/Function), causing crashes if JIT compilers are initialized. - Decision: Probe environment capabilities at startup (
try { new Function(''); return true; } catch { return false; }). Cache result inSUPPORTS_JIT. Whentrue, compile schemas withTypeCompiler.Compile(). Whenfalse, safely fall back to AST interpretation (Value.Check()).
ADR-002: Per-Request Scoped MCP Server Factory
- Status: Accepted
- Context: The official
@modelcontextprotocol/sdkmaintains a mutablethis._transportreference on itsServersingleton instance. Under concurrent HTTP requests, parallel requests overwrite each other's transport state, resulting in dropped frames and race conditions. - Decision: Do not use a singleton server for HTTP. Compile and freeze the MCP catalog once at application boot (
compileMcpCatalog), and instantiate a lightweight, isolatedcreateScopedMcpServerper incoming HTTP connection, closing it deterministically in afinallyblock.
ADR-003: Single-Flight Mutex for JWKS Key Discovery
- Status: Accepted
- Context: When cold starts or traffic spikes hit an edge cluster, hundreds of concurrent requests requiring JWT verification simultaneously query the authorization server's
.well-known/jwks.jsonendpoint (cache stampede). - Decision: Implement a Single-Flight Mutex (
inFlightPromise). If a JWKS fetch is already in flight, all concurrent verifications latch onto the existing promise instead of firing redundant HTTP requests.
ADR-004: Stream-Bounded Body Parsing (OOM Defense)
- Status: Accepted
- Context: Attackers can bypass naive
Content-Lengthheader checks by sending chunked transfer encoding (Transfer-Encoding: chunked), slowly streaming gigabytes of data and crashing the Node/Bun process with an Out-of-Memory (OOM) fatal error. - Decision: Never rely on
Content-Length. Read incoming request bodies chunk-by-chunk using aReadableStreamDefaultReaderwith an accumulating byte counter (readBoundedJsonStream). Abort the stream with HTTP 413 the instant accumulated bytes exceedconfig.limits.maxBodyBytes.
ADR-005: Sterile STDOUT & Anti-Zombie Process Watchdog
- Status: Accepted
- Context: In STDIO MCP mode, desktop IDEs communicate with the server over File Descriptor 1 (
process.stdout). Any unhandledconsole.log()pollutes the JSON-RPC stream and breaks the client. Furthermore, if the parent IDE crashes, headless child processes remain as zombies. - Decision: Hijack
console.log/info/warn/debugto redirect output exclusively toprocess.stderr. Listen forstdinclosure,stdoutEPIPE, and POSIX signals to terminate the child process with exit code 0 within 200 ms.