Skip to Content
HeyBug docs
MCP

Generate and run tests from an agent

## What it is for

What it is for

A coding agent can have HeyBug write a test plan, run the tests and read the results, without you opening the dashboard. The agent needs three things: a way to start a run, a way to poll it until it finishes, and a way to cancel it if it is no longer needed.

Every MCP call on the remote server (/api/mcp) stops waiting after 50 seconds. The run keeps going on the server, so a slow call still gives the agent a run id to poll. For the general pattern, see long-running calls.

The 45 second rule

  • Ask for at most 45 seconds per poll. heybug_get_run accepts wait from 0 to 45. One poll that waits 45 seconds finishes before the 50 second limit.
  • Poll in a loop. Call again while the status is queued or running. Stop at passed, failed, error or canceled.
  • Silence is not failure. "Stopped waiting" and "Still running" mean the work continues. Keep the id and poll.

The steps

  1. Plan (optional). Call heybug_plan with projectId and type (frontend or backend). It explores the app and proposes cases. The reply gives the pending card id.

  2. Start. Pick one:

    • heybug_generate_and_run with projectId applies the pending plan and runs it. Pass testIds to run only some cases.
    • heybug_run with url starts a quick run of a page. Send "wait": false to get the run id at once.
    • heybug_run_tests with projectId and caseKeys runs only the named tests.
  3. Get the run id. The reply has the id. If the call stopped at 50 seconds, call heybug_list_runs with projectId. The newest run is listed first, with its id=.

  4. Poll. Call heybug_get_run with runId and wait: 45. Repeat until the status is final.

  5. Cancel. The MCP tools in this build have no cancel call. Use the CLI (below) or the Cancel run button on the run page, /p/{project}/runs/{run}. Both call POST /api/runs/{runId}/cancel.

    heybug runs cancel run_123

Example

Start a run of the pending plan:

curl -s https://opentest.nagara.cloud/api/mcp \
  -H "Authorization: Bearer $HEYBUG_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"heybug_generate_and_run","arguments":{"projectId":"p_1"}}}'

If the run is not finished at 50 seconds, the reply reads:

Stopped waiting after 50s; the work continues on the server. Call heybug_get_run with the run id to get the result.

Find the id, then list the newest runs of the project:

3 runs, newest first:
- #12 running (0 passed, 0 failed, 0 errored of 8) id=run_123

Poll with the id and wait 45 seconds:

curl -s https://opentest.nagara.cloud/api/mcp \
  -H "Authorization: Bearer $HEYBUG_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"heybug_get_run","arguments":{"runId":"run_123","wait":45}}}'

While the run is going, the reply ends with:

Run #12 is running (0 passed, 0 failed, 0 errored of 8). https://opentest.nagara.cloud/p/p_1/runs/run_123
Still running; call heybug_get_run again with wait.

When it finishes, the reply names the verdict and counts, then lists each failed case with its failing step, Expected, Actual and a link to the case. The numbers and ids above are examples.

From a terminal, the same run can be started and followed with the CLI. This prints a JSON receipt with the run ids:

heybug runs start --project p_1 --no-wait --output json
heybug runs wait run_123 --timeout 20m --output json
heybug runs cancel run_123

When it fails

  • "Stopped waiting" or "Still running". Not a failure. Poll with the run id.
  • "Lost contact while waiting for the run". The connection dropped. The run continues, so poll again with the same id.
  • "No runs yet. Use heybug_generate_and_run to start one." The start call did not create a run. Call heybug_plan first if there is no pending plan, then start again.
  • "runId is required" or "projectId is required". Pass the id from the reply or from the dashboard URL (/p/<projectId>).
  • The id starts with exp_. That id belongs to an exploration, not a run. Open the link in the reply instead.
  • Status error. An infrastructure problem, not a test verdict. Start a new run.
  • Status canceled. The run was stopped. Its results are incomplete. Start a new run if you still need them.
  • heybug runs cancel exits 4. The run was not found. Check the id with heybug runs list --project <projectId>. See CLI exit codes.
  • 401 or 403. The key or the Origin header is wrong. See MCP troubleshooting.
  • A tool is missing. Restart the client and compare with GET /api/mcp/tools.

On this page