Script hooks
There are three hooks, each corresponding to a stage in the execution pipeline:| Hook | Default export | Purpose |
|---|---|---|
| Handler | export default (...) | Replaces DB execution entirely |
| Input transform | export default (...) | Pre-process arguments before execution |
| Output transform | export default (...) | Post-process results before returning |
Selecting exported functions
For all script references, you can target a non-default export with#:
#exportName, Hyperterse calls the script’s export default function.The function name itself is optional and ignored by the runtime.
Handler
A handler replaces adapter-based execution. Whenhandler is configured, no use or statement is needed. The return value becomes the tool’s result payload.
Input transform
An input transform pre-processes arguments before they reach the executor or handler. Use it for validation, normalization, or rejection. The returned object replaces the original inputs for all subsequent pipeline stages. Throwing an error aborts execution.Output transform
An output transform post-processes results before they are returned. Use it for field mapping, formatting, or redaction.Runtime APIs
Scripts execute in a sandboxed runtime with two injected globals:fetch(url, options?)— HTTP client for outbound requests. Returns{ status, ok, text(), json() }.console—log,error,warn,info,debug— all wired to the framework’s structured logger with the tool name as context.
setTimeout and setInterval are not available — use async/await instead.
Convention discovery
When script paths are omitted in tool config, Hyperterse auto-discovers script files from the tool directory. Convention names include:handler.tsinput.ts(or*input*validator*.ts)output.ts(or*data*mapper*.ts)
npm packages
If your scripts import external packages, add apackage.json at the project root. The build process packages dependencies with your scripts, so deployment does not require node_modules/.
Error handling
Errors thrown from scripts propagate as MCP error responses. The error message is included in the response; stack traces are logged at debug level but not exposed to callers.Further reading
See Execution pipeline for how scripts fit into the request lifecycle, and Tool configuration reference forhandler and mappers configuration.