Gaffer

sh.gaffer由 gaffer.sh 发布v0.9.0更新于 Oct 24, 2026

Test analytics for AI agents: test history, flaky tests, failure clusters, coverage.

已验证STDIO仅桌面开发者工具数据与分析

概览

AI 生成的概览

Gaffer 的本地 MCP 服务器让 AI 编程助手读取 Gaffer 中的测试历史、不稳定测试、失败聚类和覆盖率,并提供一个上传工具

可以做什么
查看项目测试健康状况、通过率、趋势和最近的测试运行,可按提交、分支或状态筛选,并查看单次运行的详细结果,以及按根因聚类的失败或按错误文本和测试名搜索的失败。查询某个测试的通过/失败历史、不稳定测试、按 P95 耗时排序的最慢测试,以及两次提交或运行之间的前后对比。分析覆盖率:总体摘要与趋势、指定文件或路径的覆盖率、低于阈值的未测试文件,以及覆盖率低且存在失败的高风险区域。获取报告文件链接和 30 分钟有效的签名浏览器查看链接,并检查 CI 结果是否已上传和处理。以唯一写入工具上传结构化测试结果。
适用场景
当项目的测试结果已存入 Gaffer,且希望助手诊断 CI 失败、判断测试是否不稳定或失败是否为新出现、验证修复对耗时的影响,或依据覆盖率缺口决定在哪里补充测试时使用。
运行要求
通过 stdio 在本地运行,通常用 npx 启动 npm 包。需要已上传测试结果的 Gaffer 账户,并在 GAFFER_API_KEY 中提供 API 密钥(gaf_ 用户密钥,或仅限单个项目的 gfr_ 项目令牌)。GAFFER_API_URL 可覆盖 API 基础地址。需要访问 Gaffer API 的网络连接。
安装前请注意
API 密钥通过 GAFFER_API_KEY 传入;gaf_ 用户密钥可读取你各组织下的所有项目,应谨慎授权。upload_test_results 会写入数据,受速率限制、记录审计日志且不幂等,重试可能产生重复运行。报告链接为 30 分钟有效的签名 URL。测试数据和查询会发送到 Gaffer 服务。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Gaffer,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

@gaffer-sh/mcp

MCP (Model Context Protocol) server for Gaffer - give your AI assistant memory of your tests.

What is this?

This MCP server connects AI coding assistants like Claude Code and Cursor to your Gaffer test history and coverage data. It runs in code mode: three MCP tools over a namespace of 17 functions — 16 read-only analytics functions plus upload_test_results. It allows AI to:

  • Check your project's test health (pass rate, flaky tests, trends)
  • Look up the history of specific tests to understand stability
  • Get context about test failures when debugging
  • Analyze code coverage and identify untested areas
  • Browse all your projects (with user API Keys)
  • Access test report files (HTML reports, coverage, etc.)

Prerequisites

  1. A Gaffer account with test results uploaded
  2. An API Key from Account Settings > API Keys

Setup

Claude Code (CLI)

The easiest way to add the Gaffer MCP server is via the Claude Code CLI:

bash
claude mcp add gaffer -e GAFFER_API_KEY=gaf_your_api_key_here -- npx -y @gaffer-sh/mcp

Claude Code (Manual)

Alternatively, add to your Claude Code settings (~/.claude.json or project .claude/settings.json):

json
{  "mcpServers": {    "gaffer": {      "command": "npx",      "args": ["-y", "@gaffer-sh/mcp"],      "env": {        "GAFFER_API_KEY": "gaf_your_api_key_here"      }    }  }}

Cursor

Add to .cursor/mcp.json in your project:

json
{  "mcpServers": {    "gaffer": {      "command": "npx",      "args": ["-y", "@gaffer-sh/mcp"],      "env": {        "GAFFER_API_KEY": "gaf_your_api_key_here"      }    }  }}

How this server works

This server uses code mode. Instead of exposing one MCP tool per API call, it exposes three tools plus a codemode namespace you call from JavaScript. Fewer tool definitions occupy the context window, and a single execution can chain several calls.

MCP toolWhat it does
execute_codeRun JavaScript against codemode.<function>(). Max 20 API calls, 30s timeout.
search_toolsFind available functions by keyword. An empty query lists all of them.
list_projectsList projects. Registered only when the token is a user API Key (gaf_).
javascript
const health = await codemode.get_project_health({ projectId: "proj_abc" });if (health.flakyTestCount > 0) {  const flaky = await codemode.get_flaky_tests({ projectId: "proj_abc" });  return { health, flaky };}return { health };

Functions available via execute_code

FunctionCategoryDescription
get_project_healthhealthHealth score, pass rate, flaky count, trend
get_test_historytestingPass/fail history for a specific test
get_flaky_teststestingTests with high flip rates (pass↔fail)
list_test_runstestingRecent test runs, filterable by commit/branch/status
get_test_run_detailstestingParsed individual results for one run
get_failure_clusterstestingFailed tests grouped by root cause
get_slowest_teststestingSlowest tests by P95 duration
compare_test_metricstestingCompare test performance between commits or runs
search_failurestestingSearch failures by error or test-name pattern, or list all recent failures
get_coverage_summarycoverageOverall coverage metrics and trend
get_coverage_for_filecoverageCoverage for specific files or paths
get_untested_filescoverageFiles below a coverage threshold
find_uncovered_failure_areascoverageFiles with low coverage AND test failures
get_reportreportsReport file URLs for a test run
get_report_browser_urlreportsSigned browser-navigable report URL (30 min)
get_upload_statusuploadsWhether CI results are uploaded and processed
upload_test_resultsuploadsUpload test results (write) — rate-limited and audit-logged

Every function except upload_test_results is read-only.

Function Reference

list_projects

List all projects you have access to.

  • Input: organizationId (optional), limit (optional, default: 50)
  • Returns: List of projects with IDs, names, and organization info
  • Example: "What projects do I have in Gaffer?"

get_project_health

Get the health metrics for a project.

  • Input: projectId (required), days (optional, default: 30)
  • Returns: Health score (0-100), pass rate, test run count, flaky test count, trend
  • Example: "What's the health of my test suite?"

get_test_history

Get the pass/fail history for a specific test.

  • Input: projectId (required), testName or filePath (one required), limit (optional)
  • Returns: History of runs with status, duration, branch, commit, errors
  • Example: "Is the login test flaky? Check its history"

get_flaky_tests

Get the list of flaky tests in a project.

  • Input: projectId (required), threshold (optional, default: 0.1), days (optional), limit (optional)
  • Returns: List of flaky tests with flip rates, transition counts, run counts
  • Example: "Which tests are flaky in my project?"

list_test_runs

List recent test runs with optional filtering.

  • Input: projectId (required), commitSha (optional), branch (optional), status (optional), limit (optional)
  • Returns: List of test runs with pass/fail/skip counts, commit and branch info
  • Example: "What tests failed in the last commit?"

get_test_run_details

Get parsed test results for a specific test run.

  • Input: testRunId (required), projectId (required), status (optional filter), limit (optional)
  • Returns: Individual test results with name, status, duration, file path, errors
  • Example: "Show me all failed tests from this test run"

get_report

Get URLs for report files uploaded with a test run.

  • Input: testRunId (required)
  • Returns: List of files with filename, size, content type, download URL
  • Example: "Get the Playwright report for the latest test run"

get_report_browser_url

Get a browser-navigable URL for viewing a test report.

  • Input: projectId (required), testRunId (required), filename (optional)
  • Returns: Signed URL valid for 30 minutes
  • Example: "Give me a link to view the test report"

get_slowest_tests

Get the slowest tests in a project, sorted by P95 duration.

  • Input: projectId (required), days (optional), limit (optional), framework (optional), branch (optional)
  • Returns: List of tests with average and P95 duration, run count
  • Example: "Which tests are slowing down my CI pipeline?"

compare_test_metrics

Compare test metrics between two commits or test runs.

  • Input: projectId (required), testName (required), beforeCommit/afterCommit OR beforeRunId/afterRunId
  • Returns: Before/after metrics with duration change and percentage
  • Example: "Did my fix make this test faster?"

get_coverage_summary

Get the coverage metrics summary for a project.

  • Input: projectId (required), days (optional, default: 30)
  • Returns: Line/branch/function coverage percentages, trend, report count, lowest coverage files
  • Example: "What's our test coverage?"

get_coverage_for_file

Get coverage metrics for specific files or paths.

  • Input: projectId (required), filePath (required - exact or partial match)
  • Returns: List of matching files with line/branch/function coverage
  • Example: "What's the coverage for our API routes?"

get_untested_files

Get files with little or no test coverage.

  • Input: projectId (required), maxCoverage (optional, default: 10%), limit (optional)
  • Returns: List of files below threshold sorted by coverage (lowest first)
  • Example: "Which files have no tests?"

find_uncovered_failure_areas

Find code areas with both low coverage AND test failures (high risk).

  • Input: projectId (required), days (optional), coverageThreshold (optional, default: 80%)
  • Returns: Risk areas ranked by score, with file path, coverage %, failure count
  • Example: "Where should we focus our testing efforts?"

get_failure_clusters

Group failed tests by root cause using error message similarity.

  • Input: projectId (required), testRunId (required)
  • Returns: Clusters of failed tests grouped by similar error messages, with representative error and test count
  • Example: "Are these 15 failures from the same bug?"

search_failures

Search past failures by error message, stack trace, or test name — or list every failure in the window.

  • Input: query (optional — omit to return all failures), projectId (required for gaf_ keys), searchIn (optional: errors/names/all, default all), days (optional, default: 30), branch (optional), limit (optional, default: 20)
  • Returns: Matching failures with test name, error message, run and commit context, plus truncated when scan caps cut the list short
  • Example: "Have we seen this connection-refused error before?" / "What failed in the last 7 days?"

get_upload_status

Check if CI results have been uploaded and processed.

  • Input: projectId (required), sessionId (optional), commitSha (optional), branch (optional)
  • Returns: Upload session(s) with processing status, linked test runs and coverage reports
  • Example: "Are my test results ready for commit abc123?"

upload_test_results

Upload structured test results. This is the only function that writes.

Use it when you have results in hand — parsed from CI output or a runner's JSON report — and no Gaffer CLI is available to upload them.

  • Input: projectId (required for gaf_ keys), framework (required), tests (required), branch, commitSha, ciProvider, startedAt, finishedAt, coverage
  • Returns: uploadSessionId, the generated runId, and the derived pass/fail/skip summary
  • Example: "Upload these 42 parsed pytest results so we can track them"

runId, the run timestamps and the summary are derived from tests — pass startedAt/finishedAt only if you know the real wall-clock window.

Two constraints worth knowing:

  • Not idempotent. Each call creates a new run, so a retry after an uncertain failure produces a duplicate. Check get_upload_status instead of retrying.
  • Rate-limited per project, and every call is written to the project's audit log with the id of the credential that made it.

Processing is asynchronous: results take a few seconds to become visible to the read functions.

Agentic CI Workflows

These workflows show how an AI agent diagnoses CI failures, waits for results, and finds coverage gaps. Each step is a codemode function, so a whole chain runs inside one execute_code call rather than one round-trip per step.

Workflow: Diagnose CI Failures

list_test_runs(projectId, status="failed")  → get_test_run_details(projectId, testRunId, status="failed")  → get_failure_clusters(projectId, testRunId)  → get_test_history(projectId, testName="...")  → compare_test_metrics(projectId, testName, beforeCommit, afterCommit)
  1. Find the failed test run
  2. Get individual failure details with stack traces
  3. Group failures by root cause — often 15 failures are 2-3 bugs
  4. Check if each failure is new (regression) or recurring
  5. Verify fixes by comparing before/after

Workflow: Wait for Results

get_upload_status(projectId, commitSha="abc123")  → poll until processingStatus="completed"  → get_test_run_details(projectId, testRunId)
  1. Check if results for a commit have been uploaded
  2. Wait for processing to complete
  3. Use linked test run IDs to get results

Workflow: Find Coverage Gaps

find_uncovered_failure_areas(projectId)  → get_untested_files(projectId)  → get_coverage_for_file(projectId, filePath="src/critical/")
  1. Find files with both low coverage and test failures (highest risk)
  2. Find files with no coverage at all
  3. Drill into specific directories for targeted analysis

Function Quick Reference

Agent QuestionFunction
"What failed?"get_test_run_details
"Same root cause?"get_failure_clusters
"Seen this error before?"search_failures
"Is it flaky?"get_flaky_tests
"Is this new?"get_test_history
"Did my fix work?"compare_test_metrics
"Are results ready?"get_upload_status
"What's untested?"find_uncovered_failure_areas
"What's slow?"get_slowest_tests

Prioritizing Coverage Improvements

When using coverage tools to improve your test suite, combine coverage data with codebase exploration for best results:

1. Understand Code Utilization

Before targeting files purely by coverage percentage, explore which code is actually critical:

  • Find entry points: Look for route definitions, event handlers, exported functions - these reveal what code actually executes in production
  • Find heavily-imported files: Files imported by many others are high-value targets
  • Identify critical business logic: Look for files handling auth, payments, data mutations, or core domain logic

2. Prioritize by Impact

Low coverage alone doesn't indicate priority. Consider:

  • High utilization + low coverage = highest priority - Code that runs frequently but lacks tests
  • Large files with 0% coverage - More uncovered lines means bigger impact on overall coverage
  • Files with both failures and low coverage - Use find_uncovered_failure_areas for this

3. Use Path-Based Queries

The get_untested_files tool may return many frontend components. For backend or specific areas:

# Query specific paths with get_coverage_for_fileget_coverage_for_file(filePath="server/services")get_coverage_for_file(filePath="src/api")get_coverage_for_file(filePath="lib/core")

4. Iterative Improvement

  1. Get baseline with get_coverage_summary
  2. Identify targets with get_coverage_for_file on critical paths
  3. Write tests for highest-impact files
  4. Re-check coverage after CI uploads new results
  5. Repeat

Authentication

User API Keys (Recommended)

User API Keys (gaf_ prefix) provide read-only access to all projects across your organizations. Get your API Key from: Account Settings > API Keys

Project Tokens

Project Tokens (gfr_ prefix) are designed for uploading test results and only provide access to a single project. When you use one, omit projectId — it resolves automatically. User API Keys are preferred for the MCP server because they enable list_projects and read across projects.

Environment Variables

VariableRequiredDescription
GAFFER_API_KEYYesYour Gaffer API Key (starts with gaf_)
GAFFER_API_URLNoAPI base URL (default: https://app.gaffer.sh)

Local Development

bash
pnpm installpnpm build

Test locally with Claude Code (use absolute path to built file):

json
{  "mcpServers": {    "gaffer": {      "command": "node",      "args": ["/absolute/path/to/dist/index.js"],      "env": {        "GAFFER_API_KEY": "gaf_..."      }    }  }}

License

MIT

来源:README.md,提交 7b928de

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.9.0最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分