Test responses with handler scripts
A response handler is a short JavaScript program after a request. It runs once the response has arrived, can test it, log values and store globals for the next requests. A handler runs only after you approve its exact text for the project, in a separate process with no network, no files and fixed limits. Response handler scripts: Experimental.
Write a handler
Section titled “Write a handler”### Log inPOST {{host}}/loginContent-Type: application/json
{ "user": "demo", "password": "{{password}}" }
> {% client.test("logged in", () => { client.assert(response.status === 200, "expected 200, got " + response.status); }); client.global.set("auth", response.body.token);%}
### Use the tokenGET {{host}}/ordersAuthorization: Bearer {{auth}}> {% … %}holds the script, on one line or several.> handlers/login.js(or.mjs) reads it from a file under the rules of body files, at most 64 KiB.- With several handlers on one request, the last one is used and the others are named in the notes. Handler text is never sent.
- Run All resolves each request just before it is sent, so
{{auth}}set by the first handler reaches the second request.
There are no pre-request scripts (< {% … %} before a request).
What a script can use
Section titled “What a script can use”| Name | What it does |
|---|---|
client.test(name, fn) |
a test: passes if fn returns, fails with the message it throws |
client.assert(condition, message) |
throws when the condition is false (“Assertion failed” by default) |
client.log(...values) |
one line in Output; objects as JSON |
client.global.set(name, value), .get(name), .isEmpty(), .clear(name), .clearAll() |
text values for {{name}} in later requests; get of an unknown name is null |
response.status |
the status code |
response.headers.valueOf(name), .valuesOf(name) |
the first or all values of a header, any case |
response.body |
the decoded body; parsed when the type is JSON (or +json) and the text is valid; null with no text or above 2 MiB |
response.contentType.mimeType, .charset |
the parsed Content-Type |
Not available: request and request.variables, client.exit, cookies, crypto helpers, and
anything outside the language itself: no require, import(), fetch, XMLHttpRequest, timers,
files or processes. Globals set by a script cannot override a variable of the file or the
environment.
Approve and run it
Section titled “Approve and run it”- The response arrivesThe request is sent as usual, whether or not its handler is approved.
- Is this exact script approved for this project?Approvals are kept per project folder and the script’s SHA-256.If not: Output says the handler waits for approval; a banner over the response shows the whole script and Approve and Run.
- A sandboxed process runs itAn empty environment, no network, read access only to system folders, fixed limits.
- Results in OutputTests, log lines, the globals set and any error.
- Send the request. Output says the handler waits for approval.
- Read the script in the banner above the response.
- Click Approve and Run. The script runs on the response you have, and from then on after every send of that request.
Output then shows “Response handler script: 2 tests, 0 failed · 14 ms”, one line per test (✓ or
✗ with the message, failures in red), the log lines, the globals set and any error.
Approvals are stored in http-script-approvals.json in your settings folder (mode 600), at most
10,000; the oldest go first. Approving is something only a person at the window can do: no MCP tool
and no UI automation presses the button.
Limits
Section titled “Limits”Every limit is fixed. If one cannot be applied on your system, the script does not run at all.
| Limit | Value |
|---|---|
| Wall time | 5 s |
| CPU time | 10 s |
| Memory | 512 MiB (checked every 5 ms); on Linux also a data limit of 768 MiB |
| Loop iterations | 10,000,000 in all |
| Nested calls | 256 |
| Script size | 64 KiB |
| Body given to the script | 2 MiB |
| Tests, log lines, globals | 1,000 each |
| Length of a log line | 4 KiB |
| Size of a global value | 64 KiB |
When a limit is hit, the script is stopped with a message such as “The script was stopped after 5 s, its time limit.” or “…used more than 512 MiB of memory, its limit.”. What it logged, tested and set before an error of its own is kept; if the process is stopped from outside, the globals stay as they were.
The sandbox. Scripts run in the Boa JavaScript engine inside a separate ferris-idea http-script process with an empty environment. On macOS the process runs under a Seatbelt profile
without network access that may read only system folders and the program’s own folder; on Linux it
uses Landlock and a network namespace where the kernel offers them. The script’s result names the
isolation it got (seatbelt, landlock or process). No core file is written.
Globals live in memory for the session and are gone when the window or the MCP server ends. In the agent log they are masked like private environment values.
When it does not work
Section titled “When it does not work”- “waits for approval” after every edit: approval is per exact text; approve the new version.
- “The script did not run: the limits for scripts cannot be applied”: the system refused one of the limits, so the script was not started. This is deliberate.
response.bodyisnull: the body is empty, not text, or larger than 2 MiB.- A global does not change: its name is empty or has braces, or the value is over 64 KiB; a note says so.
For agents
Section titled “For agents”An agent’s send_http_request runs a handler only if you approved it in the window; otherwise the
answer reports needs approval. clear_http_cookies with globals: true clears the globals of the
agent’s session. The window and the MCP server keep separate cookies and globals.
clear_http_cookiesForget the cookies this MCP server keeps betweensend_http_requestcalls; withglobals: truealso the globals response handler scripts set.http_cookiesCookies this MCP server keeps betweensend_http_requestcalls (in memory only, per origin by RFC 6265, never in a file, gone when the server stops): name, domain, path, secure, http_only, expiry — never the value.send_http_requestSend one request of a.httpfile.
No tool matches. Try fewer words, or .