<!-- https://testapilocally.com/docs/core-features/mcp-and-cli/ -->
# MCP & CLI

Headless entry points for the same execution engine behind Runner: **`npm run runner`** (`run` + `load`), **`npm run mock`**, and the **MCP server** for AI coding agents. No cloud relay — everything is local stdio/process.

Working directory examples assume the `qasignoff-backend` package.

---

### Collection runner (`npm run runner -- run`)

* **Platform Availability:** Full Parity (CLI)
* **Overview:** Execute a Signoff `*.signoff.json` or Postman v2.1 collection with environments, dotenv, data files, iterations, workers, retries, and reporters (`json`, `html`, `pdf`, `junit`, `csv`).
* **How It Works (Windows App):** Export or save collection/env files from the workspace, then run from PowerShell/terminal. UI Runner remains available for interactive plans.
* **How It Works (VS Code Extension):** Same CLI from the integrated terminal; optional UI Runner while developing.

![Windows runner main](/docs/assets/screenshots/windows/windows-runner-main.png)

![VS Code runner main](/docs/assets/screenshots/vscode/vscode-runner-main.png)

* **Code / Configuration Examples:**

| Flag | Description | Default |
|------|-------------|---------|
| `-c, --collection <path>` | Collection file (Signoff or Postman v2.1) | **required** |
| `-e, --environment <path>` | Environment JSON (Signoff or Postman) | — |
| `--env-file <path>` | Dotenv file merged after environment JSON | — |
| `-d, --data <path>` | Data file (CSV/JSON) | — |
| `-o, --output <dir>` | Report output directory | `cwd` |
| `--reporters <formats>` | `json,html,pdf,junit,csv` (comma-separated) | `json` |
| `-i, --iteration <n>` | Iteration count | `1` |
| `--delay <ms>` | Delay between requests | `0` |
| `--retry <n>` | Retry count | `0` |
| `-w, --workers <n>` | Parallel workers (`1` = sequential) | `1` |
| `--timeout <ms>` | Per-request timeout | `30000` |
| `--bail` | Stop on first failure | `false` |
| `-v, --verbose` | Verbose logging | `false` |
| `--var <pair...>` | `key=value` overrides (highest precedence) | — |
| `--folder <nameOrId>` | Run a single folder | — |
| `--request <nameOrId...>` | Run one or more requests | — |

```bash
npm run runner -- run \
  -c ./signoff-studio-starter.signoff.json \
  -e ./signoff-studio-starter.httpbingo.signoff.env.json \
  --reporters json,html,junit \
  -o ./reports \
  --bail -v
```

Exit codes: **0** ok · **1** failures (including assertions) · **2** usage/load/validation.

* **Edge Cases, Troubleshooting & Pro-Tips:**
  - PDF needs Chrome or Edge (if one writes no PDF, the next installed browser is tried) or `SIGNOFF_CHROME_PATH` (otherwise prefer `html`).
  - `--var` wins over env JSON and dotenv — use for CI secrets injection.
  - Scope with `--folder` / `--request` for fast PR checks.

---

### Load testing (`npm run runner -- load`)

* **Platform Availability:** Full Parity (CLI)
* **Overview:** Process-local VU sessions with ramp, think time, and optional p95 / error-rate gates. See [Load testing](/docs/core-features/load-testing/) for UI parity.
* **How It Works (Windows App):** Use Load panel or CLI; CLI preferred for automation.
* **How It Works (VS Code Extension):** Same.

![Windows load panel](/docs/assets/screenshots/windows/windows-load-panel.png)

![VS Code load panel](/docs/assets/screenshots/vscode/vscode-load-panel.png)

* **Code / Configuration Examples:**

| Flag | Description | Default |
|------|-------------|---------|
| `-c, --collection <path>` | Collection file | **required** |
| `-e, --environment <path>` | Environment JSON | — |
| `--env-file <path>` | Dotenv merged after env JSON | — |
| `-o, --output <dir>` | Load JSON report directory | `cwd` |
| `--vus <n>` | Virtual users | `10` |
| `--users <n>` | Alias for `--vus` | — |
| `--duration <ms>` | Steady-state duration | `30000` |
| `--duration-ms <ms>` | Alias for `--duration` | — |
| `--ramp-up <ms>` | Ramp 0→N | `0` |
| `--ramp-down <ms>` | Drain after duration | `0` |
| `--think-time <ms>` | Pause between iterations per VU | `0` |
| `--p95 <ms>` | Fail if p95 exceeds | — |
| `--error-rate <rate>` | Fail if error rate exceeds (0–1) | — |
| `--max-vus <n>` | Soft VU cap (hard 200) | `50` |
| `-v, --verbose` | Verbose progress | `false` |
| `--var <pair...>` | `key=value` overrides | — |
| `--folder <nameOrId>` | Load one folder | — |
| `--request <nameOrId...>` | Load specific requests | — |

```bash
npm run runner -- load -c ./Pets.signoff.json --vus 20 --duration 60000 --p95 500 --error-rate 0.01 -v
```

Exit codes: **0** thresholds pass · **1** fail · **2** usage.

* **Edge Cases, Troubleshooting & Pro-Tips:**
  - Not distributed — one process, one machine.
  - Soft-capped by `--max-vus` (default 50).

---

### Mock server (`npm run mock`)

* **Platform Availability:** Full Parity (CLI)
* **Overview:** Serve a local mock from workspace collection, collection file, or OpenAPI/Swagger. Details in [Mocks & OpenAPI](/docs/core-features/mocks-openapi/).
* **How It Works (Windows App):** CLI or UI mock actions.
* **How It Works (VS Code Extension):** CLI from terminal; UI mock from tree.

![Windows import modal](/docs/assets/screenshots/windows/windows-import-modal.png)

![VS Code import modal](/docs/assets/screenshots/vscode/vscode-import-modal.png)

* **Code / Configuration Examples:**

| Flag | Description | Default |
|------|-------------|---------|
| `-w, --workspace <path>` | Absolute Signoff workspace folder | — |
| `-c, --collection <id\|name\|file>` | Collection id/name or file | — |
| `--folder <id\|name>` | Folder when using a workspace | — |
| `-o, --openapi <path>` | OpenAPI/Swagger JSON or YAML | — |
| `-p, --port <n>` | Port (`0` = ephemeral) | `0` |
| `--quiet` | Less request logging | `false` |

```bash
npm run mock -- --openapi ./petstore.yaml --port 0
npm run mock -- -w C:/abs/workspace -c Pets --folder smoke
```

* **Edge Cases, Troubleshooting & Pro-Tips:**
  - Require workspace+collection, collection file, or `--openapi`.
  - Absolute workspace paths only; `..` rejected.

---

### MCP server for AI coding agents

* **Platform Availability:** Full Parity. The Windows app, the VS Code extension and the npm package all ship the same local stdio server.
* **Overview:** Lets Claude Code, Cursor, VS Code Copilot agent mode and Gemini CLI call your APIs with checks (`http_request`), query databases read-only (`db_query`, `db_assert`), verify an API call and its database effect in one step (`verify_api_effect`), and save those checks into the workspace (`save_request`, `save_db_check`). 19 tools, secrets redacted by value, read-only SQL enforced by the driver.
* **How It Works (Windows App):** **Help → Connect AI agents…** registers the server with each agent, or adds it to a project folder (previewed, merge-only). The app runs the server itself (`QaSignOff.exe --mcp-stdio`), so no Node is needed.
* **How It Works (VS Code Extension):** The extension registers the server with Copilot agent mode automatically (VS Code 1.101+). **SignOff Studio: Connect AI Agents** sets up the other agents.

```bash
npx -y @signoff-studio/mcp init
```

**Full guide** (per-agent setup, every tool, safety and privacy): [testapilocally.com/mcp](https://testapilocally.com/mcp/).

* **Edge Cases, Troubleshooting & Pro-Tips:**
  - The server finds the workspace from the agent's open folder; `--workspace <dir>` overrides it.
  - Database passwords kept only in the vault are provided by the running app while the vault is unlocked; otherwise set the connection's password env key in the workspace `.env`.
  - Point requests at `npm run mock` for fully local agent loops.

---

### Workspace normalize (related CLI)

* **Platform Availability:** Full Parity (CLI utility in backend package)
* **Overview:** `workspace:normalize` (package script) repairs/normalizes on-disk workspace layout for Git-friendly collections. Use when migrating legacy state or after manual file edits.

```bash
npm run workspace:normalize -- --workspace C:/absolute/path/to/workspace
```

* **Edge Cases, Troubleshooting & Pro-Tips:** Commit after normalize so teammates share the same layout.

---

## Related

- [Runner](/docs/runner/)
- [Load testing](/docs/core-features/load-testing/)
- [Mocks & OpenAPI](/docs/core-features/mocks-openapi/)
- [AI assist](/docs/core-features/ai-assist/)
