Test-Lab.aiDocs

MCP server

Install the test-lab MCP server so AI agents in Claude Code, Cursor, or Codex can create, run, and manage tests as callable tools, with the same auth as the CLI.

MCP server

@test-lab-ai/mcp is test-lab's first-party Model Context Protocol server. It exposes the same operations as the testlab CLI (test plans, projects, credentials, data fixtures, labels, scripts, and test runs) as tools an AI agent can call directly. The agent that writes your code can create and run its tests in the same session.

It reuses the CLI's own modules under the hood, so auth, retries, and error handling behave exactly like the CLI.

Playwright MCP drives a browser one action at a time. The test-lab MCP is a different layer: it manages and runs your tests. You can use both, the agent explores with Playwright MCP and persists durable tests with test-lab. See test-lab MCP vs Playwright MCP.

Install

The server runs over stdio, so your MCP client launches it for you. There is nothing to install globally:

npx -y @test-lab-ai/mcp

It needs Node.js 18 or newer.

Authenticate

Auth resolves exactly like the CLI: the TESTLAB_API_KEY environment variable, then ~/.test-lab/config.json. So if you have already run testlab login, the server is authenticated with no extra step.

Otherwise set the key in the server's env (below), or call the login tool once. It runs the same browser approval flow the CLI uses and writes the same config file. Get a key at Settings, API keys.

Setup

Add it to your MCP client. The command is the same everywhere; omit TESTLAB_API_KEY if you have already run testlab login.

Claude Desktop / Claude Code (claude_desktop_config.json or .mcp.json):

{
  "mcpServers": {
    "test-lab": {
      "command": "npx",
      "args": ["-y", "@test-lab-ai/mcp"],
      "env": { "TESTLAB_API_KEY": "tl_your_key_here" }
    }
  }
}

Cursor (~/.cursor/mcp.json, or .cursor/mcp.json in one project):

{
  "mcpServers": {
    "test-lab": {
      "command": "npx",
      "args": ["-y", "@test-lab-ai/mcp"],
      "env": { "TESTLAB_API_KEY": "tl_your_key_here" }
    }
  }
}

Codex CLI (~/.codex/config.toml):

[mcp_servers.test-lab]
command = "npx"
args = ["-y", "@test-lab-ai/mcp"]
env = { TESTLAB_API_KEY = "tl_your_key_here" }

Claude Code, one-liner:

claude mcp add test-lab --env TESTLAB_API_KEY=tl_your_key_here -- npx -y @test-lab-ai/mcp

Tools

The server exposes 16 tools, the same resources as the CLI plus triggering runs:

  • Identity: login, whoami
  • Test plans: list_test_plans, create_test_plan
  • Projects: list_projects
  • Credentials: set_credential, list_credentials
  • Labels: list_labels, create_label
  • Data fixtures: list_data_fixtures, create_data_fixture
  • Scripts: get_script, upload_script
  • Bulk import: import_bundle (credentials, labels, fixtures, and plans in one call, with pre-steps topologically sorted)
  • Runs: run_tests (by plan ids, project, or label; returns a results URL per job)
  • Reference: examples (the full JSON shape for every resource)

run_tests consumes credits on pay-as-you-go accounts, the same as a run started from the dashboard.

Reference syntax (inside a plan prompt)

The same tokens the CLI uses are available when an agent authors a plan:

  • {{credentials.<key>}} a stored secret (never shown to the AI model)
  • {{data.<fixture>.<field>}} a value from a data fixture
  • {{run.shortId}} a unique per-run id (for unique emails, names, and so on)

Updating

Your client runs npx -y @test-lab-ai/mcp, which always fetches the latest published version, so there is nothing to update by hand.

On this page

MCP server | Test-Lab.ai