Skip to main content
Glama

Add Test Script

add_test_script

Add pre-request, post-response, or test scripts to a Bruno request, appending by default or replacing existing scripts when needed.

Instructions

Add pre-request, post-response, or tests scripts to a Bruno request. Canonical scriptType values are pre-request/post-response/tests; the aliases before-request (→ pre-request) and after-response (→ post-response) are also accepted. Appends to any existing script of that type by default — pass scriptMode:"replace" to overwrite it, or use remove_script to clear it. Assertions must be wrapped in test("name", function() { ... }) to be reported. Scripts run as async functions: top-level await works, and bru.sleep(ms), setTimeout and setInterval spend the script timeout (settings.timeout, default 5000ms), which write_request's settings argument raises.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "bruFilePath": "<bruFilePath>",
      "scriptType": "<scriptType>",
      "script": "<script>"
    },
    "name": "add_test_script"
  }
}

Input Schema

NameRequiredDescriptionDefault
scriptYesScript body. For post-response/tests, wrap every assertion in a test() block — test("status is 200", function() { expect(res.getStatus()).to.equal(200); }); — because only test() blocks are recorded in run_collection results; a bare passing top-level expect() records nothing and the run reports "tests": []. res.getBody() returns the response already parsed for application/json and +json content-types, so read fields directly (res.getBody().field) and do NOT JSON.parse() it.
scriptModeNoHow to write the script. "append" (default) concatenates onto any existing script of this type; "replace" overwrites it. Each script type has its own slot in both .bru and .yml, so replacing one leaves the others untouched.append
scriptTypeYesScript type. Canonical: pre-request, post-response, tests. Aliases: before-request (→ pre-request), after-response (→ post-response).
bruFilePathYesAbsolute path to the .yml or .bru request file. Get from list_requests or get_collection_stats.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changedv2.6.0
    • changedInput schema / properties / script / description
      Previous value: -"Script body. For post-response/tests, wrap every assertion in a test() block — test(\"status is 200\", function() { expect(res.getStatus()).to.equal(200); }); — because only test() blocks are recorded in run_collection results. A bare passing expect() at the top level records nothing and the run reports \"tests\": []. res.getBody() returns the response already parsed into a JS object/array for application/json and +json content-types, so read fields directly (res.getBody().field) and do NOT JSON.parse() it."New value: +"Script body. For post-response/tests, wrap every assertion in a test() block — test(\"status is 200\", function() { expect(res.getStatus()).to.equal(200); }); — because only test() blocks are recorded in run_collection results; a bare passing top-level expect() records nothing and the run reports \"tests\": []. res.getBody() returns the response already parsed for application/json and +json content-types, so read fields directly (res.getBody().field) and do NOT JSON.parse() it."
    • changedInput schema / properties / scriptMode / description
      Previous value: -"How to write the script. \"append\" (default) concatenates onto any existing script of this type; \"replace\" overwrites it. Each of the three script types has its own slot in both .bru and .yml, so replacing one leaves the other two untouched."New value: +"How to write the script. \"append\" (default) concatenates onto any existing script of this type; \"replace\" overwrites it. Each script type has its own slot in both .bru and .yml, so replacing one leaves the others untouched."
  2. First observedv2.2.1

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full behavioral burden and does so well: append-vs-replace semantics, the fact that each script type occupies its own slot in .bru and .yml, the test() wrapping requirement for assertions to be reported, and async execution details including that bru.sleep/setTimeout/setInterval consume settings.timeout (default 5000ms). It even points to write_request's settings argument as the way to raise that timeout, which is context an agent could not infer elsewhere.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with purpose and canonical values, then defaults, then runtime gotchas; nearly every sentence carries actionable information. The final sentence is long and packs several runtime facts (async, await, timers, timeout default, cross-tool override), which slightly hurts scannability but not accuracy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a four-parameter mutation tool with no annotations and no output schema, the description covers the pitfalls an agent would otherwise hit: silent non-recording of bare expect(), double-parsing of JSON bodies, script timeouts, and append defaults. Nothing essential to invoking it correctly appears to be missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3; the description nonetheless adds cross-tool meaning by tying the script timeout to write_request's settings argument and restating the alias mapping (before-request/after-response) in behavioral terms. The bruFilePath sourcing hint (from list_requests or get_collection_stats) is duplicated in the schema, so added value is incremental rather than extensive.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ('Add pre-request, post-response, or tests scripts to a Bruno request') and immediately enumerates the three canonical script types, so the scope is unambiguous. It also names remove_script, letting an agent distinguish this write path from the deletion path.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explains the default append behavior and explicitly says to pass scriptMode:"replace" to overwrite or use remove_script to clear it, which gives clear when-to-use routing among overlapping operations. It lacks any statement about when this tool is inappropriate (e.g., wrong file type or read-only collections), so it stops short of full exclusion guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.