Skip to content
Join Now Login

MCP Server

The Gaffer MCP server (@gaffer-sh/mcp) connects AI coding assistants to your test history. Ask about test health, investigate flaky tests, and get context about failures without leaving your editor.

The Model Context Protocol (MCP) is an open standard that lets AI assistants access external tools and data sources. By installing the Gaffer MCP server, your AI assistant gains direct access to your test analytics.

  • Test health insights - Ask about pass rates, trends, and overall test suite health
  • Flaky test detection - Identify tests with inconsistent behavior
  • Test history lookup - Check the history of specific tests to understand stability
  • Cross-project access - Query all your projects from a single API key
  • Report file access - Get links to HTML reports, coverage files, and other artifacts
  • Slowest test analysis - Find tests that are slowing down your CI pipeline
  1. A Gaffer account with test results uploaded
  2. An API Key from Account Settings > API Keys

Add to your Claude Code settings (~/.claude.json or project .claude/settings.json):

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

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

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

What tools does the Gaffer MCP server expose?

Section titled “What tools does the Gaffer MCP server expose?”

Three. The server runs in code mode: rather than one MCP tool per API call, it exposes three tools plus a codemode namespace of 16 analytics functions that you call from JavaScript. That keeps 16 tool definitions out of the context window, and it lets one execution chain several calls instead of paying a round-trip each.

MCP toolWhat it does
execute_codeRuns JavaScript against codemode.<function>(). Max 20 API calls, 30s timeout.
search_toolsFinds available functions by keyword. An empty query lists all of them.
list_projectsLists projects. Registered only when your token is a user API Key (gaf_).

You rarely write this code yourself. You ask a question, and the assistant writes the call:

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 };

All 16 are reachable through execute_code. Ask search_tools with an empty query to list them at runtime.

FunctionCategoryReturns
get_project_healthhealthHealth score (0-100), pass rate, run count, flaky count, trend
get_test_historytestingPass/fail history for one test, with branch, commit, and errors
get_flaky_teststestingFlip rates, transition counts, and last-seen timestamps
list_test_runstestingRecent runs, filterable by commit, branch, or status
get_test_run_detailstestingIndividual results for one run, with stack traces
get_failure_clusterstestingFailed tests grouped by error similarity
get_slowest_teststestingSlowest tests by average and P95 duration
compare_test_metricstestingBefore/after metrics across two commits or runs
search_failurestestingPast failures matching an error or test-name pattern
get_coverage_summarycoverageLine, branch, and function coverage, plus trend
get_coverage_for_filecoverageCoverage for an exact or partial file path
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 URL, valid 30 minutes
get_upload_statusuploadsWhether CI results are uploaded and processed

With a project token (gfr_), omit projectId on every function. It resolves automatically.

Once the MCP server is connected, try asking your AI assistant:

  • “What projects do I have in Gaffer?”
  • “What’s the health of my test suite?”
  • “Which tests are flaky in my project?”
  • “Is the login test flaky? Check its history”
  • “What tests failed in the last commit?”
  • “Show me test runs on the main branch”
  • “Which tests are slowing down my CI pipeline?”
  • “Get the Playwright report for the latest test run”
VariableRequiredDescription
GAFFER_API_KEYYesYour Gaffer API Key (starts with gaf_)
GAFFER_API_URLNoAPI base URL (default: https://app.gaffer.sh)

The MCP server uses User API Keys (gaf_ prefix) which provide read-only access to all projects across your organizations. Get your API Key from Account Settings > API Keys in the Gaffer dashboard.

Note: Project Tokens (gfr_ prefix) are designed for uploading test results from CI and only provide access to a single project. For the MCP server, use a User API Key instead.