# @zyf8827/tern-mcp [Health: Active]

**Category:** 💻 Developer Tools  
**Repository:** https://github.com/zyf8827/tern  
**GitHub Stars:** 0  
**npm Downloads (last month):** 178  
**Views:** 0  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/zyf8827-tern-mcp

## Description
Model Context Protocol (MCP) server for Tern E2E testing platform

## Tools
Capabilities this server exposes over MCP:

- **tern_list_projects** — 列出平台上的所有测试项目（用例 git/local 仓库）及用例数量、最近同步状态、git 认证摘要（secret 不回显）
- **tern_add_project** — 添加一个 git 用例仓库作为测试项目（自动 clone + 首次同步）。默认 HTTP 协议，可用账号密码；SSH 必须提供私钥 PEM（运行在容器内，不会使用宿主机密钥）。仓库根目录需要 tern.yaml
- **tern_sync_project** — 强制更新一个项目：git 仓库会 fetch + reset --hard + clean -fdx（丢弃一切本地修改）后重新扫描用例。写完用例 push 之后调用它让平台生效
- **tern_list_cases** — 查询测试用例列表（默认一页 20 条）。可用 project / version / module / tags（tagMode any=任一命中, all=全部命中）/ excludeTags / 关键字多维度过滤
- **tern_get_case** — 获取单个用例的元数据、完整源码与最近执行记录
- **tern_run_cases** — 创建并执行一次测试运行。必须指定 project（或只用 caseIds/suites，且须同属一个项目）。可覆盖该项目的多个 version / module / tag。suites 引用平台测试集（可多个：各自用各自绑定的环境，按「用例×环境」去重执行）。env 引用平台环境（显式指定时会覆盖拉平所有测试集的环境绑定）。workerId 缺省则所有空闲 worker 并行。wait=true（默认）阻塞到结束
- **tern_list_runs** — 分页列出测试运行（默认一页 20 条），可按 status / project / env / createdBy / workerId / 关键字 / 创建时间筛选
- **tern_get_run** — 查询一次测试运行的状态与逐用例结果。runId 不传时返回最近一次运行
- **tern_wait_run** — 阻塞等待测试运行结束并返回最终统计
- **tern_retry_failed** — 基于某次测试运行中失败的用例创建新运行并执行（修复后验证的标准动作）
- **tern_rerun** — 重跑某次测试运行的全部用例（沿用源运行的环境/参数/worker/trace 选项）；只复跑失败用例用 tern_retry_failed
- **tern_cancel_run** — 结束一次测试运行。默认强制结束：运行立即收敛为 cancelled（不等 worker 回执），中断 worker 上该用例的全部阶段（含尚未开始执行/登录中的条目），worker 不在线时重连后补发中断；force=false 为软取消：仅通知已进入执行阶段的用例。
- **tern_get_execution** — 查询单条用例某次执行的详情：错误、日志尾部、产物清单（截图/trace URL）
- **tern_get_screenshot** — 获取某次用例执行的失败截图，以图片返回（多模态模型可直接查看失败现场）
- **tern_list_workers** — 列出所有执行 Worker 及其状态
- **tern_resync_cases** — 全量更新并重新扫描所有项目用例（git 拉取 + 重扫 + lint/打包校验）
- **tern_list_environments** — 列出项目环境与变量清单（清单来自用例仓库 tern.yaml 的 env.variables；环境值在平台配置，secret 不回显）。发起运行前可用它确认环境是否配齐
- **tern_delete_run** — 删除一次测试运行：级联删除执行记录/事件，并清理截图、trace、日志等产物文件（不可恢复）。进行中的运行需 force=true
- **tern_get_failure_summary** — 获取一次运行的失败摘要：按错误签名聚类分组（同签名 = 同类失败），每组含代表性用例、截图 URL、日志尾部与跨 run 历史（首见/出现次数）。诊断批量失败的首选工具
- **tern_list_schedules** — 列出定时任务（cron、环境、下次触发时间、最近一次运行）
- **tern_list_suites** — 列出项目测试集：可命名复用的用例选择 + 环境/账号绑定。返回命中数与健康度（悬空引用/空集/环境缺值）——发起运行前选集的主入口
- **tern_get_suite** — 获取单个测试集详情：选择器、环境/账号绑定、健康度与命中数
- **tern_create_suite** — 创建测试集（项目内可命名复用的用例选择 + 执行前提绑定）。选择器 = 筛选条件 + 显式包含/排除（排除优先）；空选择器 = 项目全量。env/account 是运行该集时的缺省环境与账号（AUTH_ACCOUNT，只覆盖未声明 auth 的用例），run 显式指定可覆盖
- **tern_update_suite** — 更新测试集（只改提供的字段；改名会联动引用它的定时任务）
- **tern_delete_suite** — 删除测试集（历史 run 靠 scope 快照不受影响；引用它的定时任务触发时会明确报错）
- **tern_preview_run** — run 创建 dry-run 预览（不执行不落库）：与 tern_run_cases 同参，返回去重后的条目总数、按环境分组的命中构成（每组的来源测试集与条数）、各测试集命中数与去重明细——发起前自查选择是否写对
- **tern_set_case_quarantine** — 手动隔离/解除隔离一条用例（flaky 治理）。隔离的用例默认不参与新建运行，但仍可显式 caseIds 点名执行；手动设置优先于自动规则

## Claude Desktop Quick Installation
Install path detected from listing signals. Uses `npx` (confidence: high):

```json
"mcpServers": {
  "tern-mcp": {
    "command": "npx",
    "args": ["-y","@zyf8827/tern-mcp"],
    "env": {
      "TERN_URL": ""
    }
  }
}
```

**Requires environment variables:** `TERN_URL` — the values above are empty placeholders; fill in real credentials before running (see the repository for what each one is for).

## Documentation

## What @zyf8827/tern-mcp does

@zyf8827/tern-mcp exposes Tern's E2E testing platform to coding agents through the Model Context Protocol. Tern stores Playwright test cases in separate Git repositories, indexes those cases, schedules their execution, and collects results from worker nodes. The MCP layer gives an agent an interface for interacting with those workflows instead of requiring manual use of the web console.

The package is intended for teams using Tern to develop and maintain browser tests alongside an agent. It fits workflows where an agent needs to create or update test cases, synchronize repository content, launch test activity, inspect individual outcomes, and investigate failures using captured artifacts.

## How it works

Tern's test cases use standard Playwright Test APIs and live under `cases/**/*.spec.ts`. Metadata such as titles, tags, modules, versions, authentication settings, timeouts, devices, and dependencies is supplied through `@tern` comment blocks. The MCP server communicates with the Tern server over its configured URL; Tern then coordinates execution through workers that connect outward to the server over persistent WebSockets.

A run can cover test suites and multiple environments. Tern removes duplicate `(case, environment)` combinations before dispatching work, while worker slot limits control concurrency. When a test fails, the platform records console output, request information, a first failure screenshot, and a Playwright Trace. MCP tools can return the screenshot to the agent's context, allowing the agent to use the failure evidence during diagnosis and reruns.

## Setup and configuration

The npm package can be launched with `npx`:

```json
{
  "mcpServers": {
    "tern": {
      "command": "npx",
      "args": ["-y", "@zyf8827/tern-mcp"],
      "env": {
        "TERN_URL": "http://127.0.0.1:7430"
      }
    }
  }
}
```

Set `TERN_URL` to the address of the Tern server. Tern itself can run locally with Node.js 20 or newer and pnpm 10, or through Docker Compose. A typical local setup builds the repository, installs Chromium for Playwright, and starts the server with a worker. The web console is available at port 7430 in the documented local configuration.

An alternative deployment is the standalone `tern-mcp.mjs` artifact, which can be started with Node.js. The MCP package is published on npm under `@zyf8827/tern-mcp` and is also listed in the official MCP Registry as `io.github.zyf8827/tern`.

## Tools and capabilities

The package provides 27 MCP tools covering the Tern agent workflow, including capabilities to:

- Work with Playwright E2E cases stored in Git repositories.
- Synchronize and inspect indexed test projects and cases.
- Trigger test execution across configured suites or environments.
- Check run progress, summaries, and individual case results.
- Retrieve failure screenshots and other diagnostic information.
- Support failure investigation and test reruns from the agent context.

Tern also supports declarative authentication recipes, device emulation, test dependencies, scheduled runs, webhook or DingTalk notifications, and an embedded Trace Viewer. These are platform capabilities that the MCP tools can expose as part of the surrounding test workflow.

## Limitations and notes

The MCP package depends on a reachable Tern server; it is not a standalone Playwright execution service. A worker and the Tern server must be available for tests to run. Test assets follow Tern's repository conventions and use native Playwright rather than a private test DSL. Authentication recipes can reference environment variables for sensitive values, while Tern stores credentials encrypted and does not return them through its API.

_Full upstream README: https://allmcps.com/mcp/zyf8827-tern-mcp/readme_

