MCP Server
The Gaffer MCP server connects AI coding assistants to your test history. Ask about test health, investigate flaky tests, and get context about failures without leaving your editor.
What is MCP?
Section titled “What is MCP?”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.
Features
Section titled “Features”- 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
Prerequisites
Section titled “Prerequisites”- A Gaffer account with test results uploaded
- For Claude Code, claude.ai and Claude Desktop on the hosted endpoint, nothing else: you sign in. For Cursor, CI and the npm package, a user API key (
gaf_) from Account Settings > API Keys at app.gaffer.sh/account/api-keys. It covers every project your account can reach. A project token (gfr_) also works and is limited to one project. See Authentication for what each can do.
There are two ways to connect. Use the hosted endpoint unless your client only supports local stdio servers.
| Hosted endpoint | npm package | |
|---|---|---|
| Install | Nothing | npx runs @gaffer-sh/mcp on your machine |
| Credential | OAuth sign-in, or Authorization: Bearer <key> header | GAFFER_API_KEY environment variable |
| Functions | 17 with a key, same as npm. A signed-in connection has 16: it is read-only, so upload_test_results is listed but refused | All 17 |
execute_code runs | In an isolated sandbox with no network access | In a local Node process |
| Clients | Those that support remote HTTP servers | Any client that can start a stdio server |
Option 1: Hosted endpoint
Section titled “Option 1: Hosted endpoint”The endpoint is https://app.gaffer.sh/mcp (Streamable HTTP, POST only). Each credential is limited to 1,000 requests per hour. Requests without a valid credential get a 401, and requests over the limit get a 429 with a Retry-After header.
Sign in, no key
Section titled “Sign in, no key”Claude Code, claude.ai and Claude Desktop sign in with OAuth. You do not create an API key.
Claude Code
claude mcp add --transport http gaffer https://app.gaffer.sh/mcpThen run /mcp inside Claude Code, select gaffer, and finish the sign-in in your browser.
claude.ai and Claude Desktop
- Open Customize > Connectors, click + Add, then Add custom connector. On Team and Enterprise plans an owner adds it under Organization settings > Connectors, and each member then clicks Connect.
- Enter a name and
https://app.gaffer.sh/mcpas the URL, then click Add and sign in to Gaffer. - On the consent page, pick the organization to connect and approve.
Anthropic’s steps for custom connectors are the reference if the menu names change.
Share it with your team
Commit this .mcp.json at the root of your repository. It holds no secret. Each teammate signs in once with /mcp and Claude Code asks them to approve the project server first.
{ "mcpServers": { "gaffer": { "type": "http", "url": "https://app.gaffer.sh/mcp" } }}What signing in grants
- Access to one organization, the one you pick on the consent page. To use another organization, connect again and pick it.
- Read access only. A signed-in assistant can read test runs, failures, flaky tests and coverage. It cannot call
upload_test_results. - The same limit of 1,000 requests per hour, counted per connected app.
To revoke access, open Account Settings > AI assistants at app.gaffer.sh/account/ai-assistants and click Disconnect next to the app under Connected apps.
With an API key
Section titled “With an API key”Use a key for CI, Cursor, or if you prefer one. A key can also upload results.
Claude Code:
claude mcp add --transport http gaffer https://app.gaffer.sh/mcp --header "Authorization: Bearer gaf_YOUR_KEY"Cursor: add to .cursor/mcp.json in your project, or ~/.cursor/mcp.json for every project:
{ "mcpServers": { "gaffer": { "url": "https://app.gaffer.sh/mcp", "headers": { "Authorization": "Bearer gaf_YOUR_KEY" } } }}Option 2: npm package
Section titled “Option 2: npm package”The package runs locally over stdio and reads your key from GAFFER_API_KEY.
Claude Code
Section titled “Claude Code”claude mcp add gaffer -e GAFFER_API_KEY=gaf_YOUR_KEY -- npx -y @gaffer-sh/mcpOr 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_KEY" } } }}Cursor
Section titled “Cursor”Add to .cursor/mcp.json in your project:
{ "mcpServers": { "gaffer": { "command": "npx", "args": ["-y", "@gaffer-sh/mcp"], "env": { "GAFFER_API_KEY": "gaf_YOUR_KEY" } } }}Claude Desktop
Section titled “Claude Desktop”Open Settings > Developer > Edit Config, or edit the file directly:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
{ "mcpServers": { "gaffer": { "command": "npx", "args": ["-y", "@gaffer-sh/mcp"], "env": { "GAFFER_API_KEY": "gaf_YOUR_KEY" } } }}Quit and restart Claude Desktop after saving. Node.js must be installed.
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 17 analytics functions that you call from JavaScript. That keeps 17 tool definitions out of the context window, and it lets one execution chain several calls instead of paying a round-trip each.
| MCP tool | What it does |
|---|---|
execute_code | Runs JavaScript against codemode.<function>(). Max 20 API calls, 30s timeout. On the hosted endpoint it runs in a sandbox with no network access. |
search_tools | Finds available functions by keyword. An empty query lists all of them. |
list_projects | Lists projects. Registered for a user API Key (gaf_) and for sign-in, not for a project token (gfr_). |
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 };Which functions can the assistant call?
Section titled “Which functions can the assistant call?”All 17 are reachable through execute_code with a key. A signed-in connection is read-only, so upload_test_results is refused and 16 work. Ask search_tools with an empty query to list them at runtime.
| Function | Category | Returns |
|---|---|---|
get_project_health | health | Health score (0-100), pass rate, run count, flaky count, trend |
get_test_history | testing | Pass/fail history for one test, with branch, commit, and errors |
get_flaky_tests | testing | Flip rates, transition counts, and last-seen timestamps |
list_test_runs | testing | Recent runs, filterable by commit, branch, or status |
get_test_run_details | testing | Individual results for one run, with stack traces |
get_failure_clusters | testing | Failed tests grouped by error similarity |
get_slowest_tests | testing | Slowest tests by average and P95 duration |
compare_test_metrics | testing | Before/after metrics across two commits or runs |
search_failures | testing | Past failures matching an error or test-name pattern |
get_coverage_summary | coverage | Line, branch, and function coverage, plus trend |
get_coverage_for_file | coverage | Coverage for an exact or partial file path |
get_untested_files | coverage | Files below a coverage threshold |
find_uncovered_failure_areas | coverage | Files with low coverage and test failures |
get_report | reports | Report file URLs for a test run |
get_report_browser_url | reports | Signed browser URL, valid 30 minutes |
get_upload_status | uploads | Whether CI results are uploaded and processed |
upload_test_results | uploads | Uploads structured test results to a project (the one write function) |
With a project token (gfr_), omit projectId on every function. It resolves automatically. list_projects and get_report are not available with one.
Does gaffer.sh expose WebMCP tools?
Section titled “Does gaffer.sh expose WebMCP tools?”Yes. Every page on gaffer.sh registers four read-only WebMCP tools on document.modelContext, for browser agents rather than MCP clients. They cover the site, not your test data: gaffer.search_docs, gaffer.get_pricing, gaffer.install_mcp, and gaffer.signup_url. As of August 2026 the API is available only in Chrome’s origin trial, and the MCP server above remains the way to give an assistant your test history. Background: WebMCP on gaffer.sh.
Example Prompts
Section titled “Example Prompts”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”
Environment Variables
Section titled “Environment Variables”These apply to the npm package. The hosted endpoint takes a key in the Authorization header, or you sign in with OAuth.
| Variable | Required | Description |
|---|---|---|
GAFFER_API_KEY | Yes | Your Gaffer API Key (starts with gaf_) |
GAFFER_API_URL | No | API base URL (default: https://app.gaffer.sh) |
Authentication
Section titled “Authentication”| Credential | Prefix | Scope | What it can do |
|---|---|---|---|
| OAuth sign-in | none | One organization, chosen at sign-in | Read functions only. No upload_test_results. list_projects lists that organization’s projects. Hosted endpoint only. |
| User API key | gaf_ | Every project your account can reach | Read functions, plus upload_test_results. list_projects lists projects in every organization you belong to. |
| Project token | gfr_ | One project | Read functions and upload_test_results for that project. Omit projectId. |
Create a user API key under Account Settings > API Keys in the Gaffer dashboard. The hosted endpoint and the npm package serve the same functions, so both can upload. Uploads are rate-limited to 300 per hour per project and recorded in the project’s audit log.