Skip to main content
Glama

Add Test Script

add_test_script

Add pre-request, post-response, or test scripts to a Bruno request with append or replace modes for automated API validation.

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 are available. Time spent waiting counts against the script timeout (settings.timeout, default 5000ms); raise it with modify_request's settings argument.

Input Schema

TableJSON 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 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.
scriptModeNoHow 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.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.
Behavior5/5

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

With no annotations, the description carries full burden and delivers richly: discloses appending behavior, alias mapping, async execution, top-level await support, timeout counting, and the critical requirement that assertions must be wrapped in test() to be recorded. This goes far beyond generic 'adds a script'.

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

Conciseness5/5

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

The description is concise yet information-dense, with the primary purpose front-loaded. Every sentence adds value—aliases, modes, async details, timeout. No fluff or redundancy.

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?

Despite no output schema, the description covers behavior, modes, aliases, runtime environment, timeout, and alternatives. It fully equips an agent to select and invoke the tool correctly for typical use cases.

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

Parameters5/5

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

Schema coverage is 100%, but the description adds significant meaning beyond schema descriptions: explains script body expectations (test() wrappers, res.getBody() behavior), append/replace semantics, and scriptType aliases. It compensates and enhances parameter understanding.

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?

The description opens with a specific verb+resource: 'Add pre-request, post-response, or tests scripts to a Bruno request.' It clearly names the tool's action and object, and the mention of scriptType values distinguishes it from sibling tools like remove_script or modify_request.

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

Usage Guidelines5/5

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

Explicitly covers when to use append vs. replace, and points to remove_script as the alternative for clearing scripts. It also directs users to modify_request's settings argument for timeout adjustments, showing awareness of alternatives.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Ostico/bruno-mcp-studio'

If you have feedback or need assistance with the MCP directory API, please join our Discord server