Built-in Tools

Code Execute

A Code Execute tool runs your JavaScript inside a QuickJS sandbox whenever an AI client invokes it. You declare typed parameters; the platform validates them, casts them, and injects them as JS variables before your code runs. Good for formatters, calculators, validators, and other deterministic logic — no HTTP service required.

What the AI client sees

The AI client sees a single named MCP tool with a JSON Schema derived from the parameters you defined. When the model invokes the tool, Vectoralix validates the parameters against the schema, casts each one to its declared JS type, boots the QuickJS sandbox with those variables already in scope, runs your code body, and returns the result back to the model.

AI client → invoke tool with named params
          → Vectoralix casts params to typed JS values
          → QuickJS sandbox boots with timeout + memory cap
          → your code runs with params in scope
          → result returns to the model

Fields on the configure page

The configure page (/configure-code) has two parts: the page-level form for the code body and execution limits, and a parameters relation manager below it for declaring named inputs.

  • Code body — JavaScript source. The QuickJS runtime is ES2023 (language only — not Node).
  • Timeout — wall-clock cap in milliseconds. Default 5000 ms.
  • Memory limit — hard cap in megabytes. Default 128 MB.

Parameters

Each parameter row defines one input field the AI client must (or may) supply:

  • param_name — the JS variable name and the schema field name.
  • description — short hint shown to the model.
  • type — string, integer, decimal, date, boolean, array, or object.
  • required — when true, missing values raise a validation error before any JS runs.
  • default_value — used when the AI client omits the field on a non-required parameter.

Parameters are injected as top-level JavaScript variables before your code body runs. There is no params object — the variable name you declare is the variable name in scope.

A worked example

A format_currency tool that takes a number and a 3-letter currency code and returns a formatted string. Two parameters:

param_name type required
amount decimal yes
currency_code string yes

Code body:

const formatter = new Intl.NumberFormat('en-US', {
    style: 'currency',
    currency: currency_code,
});
formatter.format(amount);

Persistence semantics

  • Parameter rows save immediately when you click Save inside the relation manager modal — there is no batched save.
  • The code body, timeout, and memory limit save together when you click the page-level Save button.
  • On first visit, an empty code_tools row is created automatically (code_body='', timeout_ms=5000, memory_limit_mb=128) so the parameters table has somewhere to attach to.

What the sandbox can and cannot do

  • No filesystem access, no network access, no require, no host process access. The sandbox is the language only.
  • A hard wall-clock timeout terminates execution if the code runs too long. Default 5 seconds, configurable up to a platform-wide cap.
  • A hard memory cap terminates execution if the code allocates too much. Default 128 MB.
  • Output is the result of the last expression, or whatever you explicitly return / assign to the output. The dashboard caps displayed output at 128 KB; the live MCP call does not apply this cap.
  • A tool with no saved code_body is silently skipped at MCP registration time rather than registered as a broken tool.

Registration rules

Disabled tools (is_enabled = false) are filtered out before MCP registration. A Code Execute tool that has not been configured (no code_tools row, or code_body is empty) is also skipped silently. Once enabled with a non-empty code_body, the tool registers on every server it is attached to via the pivot.

Verify before exposing: The Configure page ships a Test Code modal that runs the same Action the live MCP endpoint would. Use mod+enter to re-run after editing inputs without reopening the dialog. Then exercise the tool end-to-end via the Playground.