You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(mcp): simplify pause_session — code in, result out
Drops the id-keyed message multiplexer and 7-action enum (run/snapshot/step/
resume/exit/status). The yield-mode subprocess now reads plain text lines
from stdin (same shape as the TTY readline REPL) and emits one JSON line
per input on stdout.
The MCP server pause_session tool exposes only "start" and "run". A run
takes a code string with the same conventions as the TTY pause REPL —
"" steps, "resume" continues, "exit" aborts, otherwise treat as I.<expr>
or =>raw_js. Each run returns the next protocol message.
Net: 237 lines removed, 159 added.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
description: 'Drive a paused test through pause(). Sub-actions: start (spawn test, wait for first paused event), run (execute CodeceptJS code in the paused session), snapshot (capture state without acting), step (let the test run one step then re-pause), resume (continue test to completion), exit (abort the paused test), status (return current state).',
430
+
description: 'Run code inside a paused test, mirroring the human pause() REPL. Two actions: "start" spawns a test and waits for it to hit pause(); "run" sends a code line (same syntax as the TTY pause REPL — empty string steps to the next test step, "resume" continues the test, "exit" aborts; any other input is treated as I.<expr> unless prefixed with "=>"). Each run returns the value plus an artifact bundle (URL, ARIA, HTML, screenshot, console, storage), like run_code.',
Copy file name to clipboardExpand all lines: docs/mcp.md
+18-23Lines changed: 18 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -237,43 +237,38 @@ Capture the current state of the browser without performing any action. Useful f
237
237
238
238
### pause_session
239
239
240
-
Drive a paused test through `pause()`over MCP. Replaces the human-only readline REPL with a JSON-line protocol the agent can speak. Useful when a test hits `pause()` or you want to pause-on-failure without a TTY.
240
+
Mirrors the human `pause()` REPL for an AI agent: send a code string, get a result with artifacts (same shape as `run_code`).
241
241
242
-
The subprocess is spawned with `CODECEPTJS_MCP=1` and `CODECEPTJS_MCP_PAUSE=1` so any `pause()` calls in the test land in yield mode (instead of the default skip-on-MCP behaviour).
242
+
Two actions:
243
243
244
-
**Sub-actions** (selected via `action`):
244
+
| Action | Params | Effect |
245
+
|---|---|---|
246
+
|`start`|`test`, `config?`, `timeout?`| Spawn the test subprocess in pause yield mode. Resolves when the test hits `pause()` and emits `{event:"paused"}`. |
247
+
|`run`|`code`, `timeout?`| Send one line of input — same syntax as the TTY REPL. Returns the next protocol message from the subprocess. |
245
248
246
-
| Action | Effect |
247
-
|---|---|
248
-
|`start`| Spawn the test subprocess in pause yield mode. Resolves when the first `paused` event arrives. |
249
-
|`run`| Execute a CodeceptJS expression in the paused session (`I.click('Save')` or `=> myVar`). Returns artifacts + return value. |
250
-
|`snapshot`| Capture browser state without acting. Returns the same artifact bundle as the `snapshot` tool. |
251
-
|`step`| Let the test run one step, then re-pause. Returns the `resumed` ack and the next `paused` event (or `exitInfo` if the test ended). |
252
-
|`resume`| Continue the test to completion. Returns when the subprocess exits. |
253
-
|`exit`| Abort the paused test and tear down the subprocess. |
254
-
|`status`| Inspect the current session — running flag, exit info, last stdout/stderr lines. |
249
+
`code` follows the TTY pause REPL conventions:
250
+
- An expression like `click('Save')` runs as `I.click('Save')` and returns `{event:"result", ok, value, artifacts, error}`.
251
+
- Prefix `=>` to evaluate raw JS: `=> myVar.id`.
252
+
-`""` (empty) → step to the next test step. The subprocess re-pauses; response is `{event:"step"}` followed by `{event:"paused"}` on the next `run` call.
253
+
-`"resume"` → continue the test to completion. Response is `{event:"resumed"}`; the subprocess will exit on its own.
254
+
-`"exit"` → abort the paused test. Same `{event:"resumed"}` response, then exit.
255
255
256
-
**Parameters:**
257
-
-`action` (required): one of the values above
258
-
-`test` (`start` only): test name or file path
259
-
-`code` (`run` only): expression to evaluate (defaults to `I.<expr>`; prefix with `=>` for raw JS)
260
-
-`config` (`start` only): path to codecept.conf.js
261
-
-`timeout` (optional): per-action timeout in ms
256
+
Each result includes the artifact bundle (URL, ARIA, HTML, screenshot, console, storage), like `run_code`. If the subprocess exits during a `run`, the response is `{event:"exited", exitInfo:{code, signal}}`.
A single `pause_session` instance owns one subprocess. Concurrent `start` calls are rejected — `exit` (or `resume`) the running session first.
267
+
A single `pause_session` instance owns one subprocess. Concurrent `start` calls are rejected — send `code: "exit"` (or `"resume"`) first.
274
268
275
269
**Notes:**
276
-
-`pause()` calls in tests run through MCP without yield mode (env `CODECEPTJS_MCP=1` only) print a notice and return immediately so leftover `pause()` calls don't deadlock CI runs.
270
+
- The subprocess is spawned with `CODECEPTJS_MCP=1` and `CODECEPTJS_MCP_PAUSE=1` so `pause()` calls in the test land in yield mode.
271
+
-`pause()` calls running under `CODECEPTJS_MCP=1`*without*`CODECEPTJS_MCP_PAUSE=1` print a notice and return immediately so leftover `pause()` calls don't deadlock CI runs invoked through MCP.
277
272
- TTY behaviour (`npx codeceptjs run --debug` at a terminal) is unchanged — the readline REPL is used whenever `process.stdin.isTTY` is true.
0 commit comments