> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trunk.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Fix Flaky Test

> MCP tool reference: fix-flaky-test

## Overview

The `fix-flaky-test` tool retrieves insights and historical failure analysis about a flaky test. This tool allows AI assistants to access investigation results and apply fixes directly in your development environment. For more information, see [Autofix Flaky Tests](../../agents/autofix-flaky-tests).

**Return Type:** Structured analysis data with fix recommendations. Structure: metadata, summary, facts

<Note>
  `fix-flaky-test` does not yet support [test collections](/flaky-tests/test-collections). It works with the test IDs [`search-test`](./search-test) returns for the repository, not for a test collection. If your organization has fully moved to test collections, the tool says so instead of returning an investigation.
</Note>

## Parameters

### Required Parameters

| Parameter | Type | Description |
| - | - | - |
| `repoName` | string | Repository name in `owner/repo` format (e.g., `trunk-io/trunk`) |

<Note>
  You must also provide either `investigationId` or `testCaseId`.
</Note>

### Optional Parameters

| Parameter | Type | Description |
| - | - | - |
| `orgSlug` | string | The name of your organization in the Trunk app |
| `investigationId` | string | Specific fix identifier from a previous investigation query. Provide this or `testCaseId`. |
| `testCaseId` | string | UUID of the test case to retrieve investigations for. Provide this or `investigationId`. |
| `createNewInvestigation` | boolean | Whether or not to trigger a new investigation (may take up to 1 minute) |

<Note>
  Setting `createNewInvestigation` to `true` starts a new investigation, which counts against your repository's and your test's monthly [investigation limits](../../agents/autofix-flaky-tests#investigation-limits). Retrieving an existing investigation by `investigationId` or `testCaseId` does not.
</Note>

## Getting Parameter Values

If your AI assistant doesn't have direct access to Git information, use these commands:

**Get repository name:**

```bash theme={"system"}
git remote -v
```

Look for the repository name in the output (e.g., `trunk-io/trunk` from `git@github.com:trunk-io/trunk.git`)

## Usage Examples

### With Test ID

```
Fix the flaky test with ID <testCaseId>
```

### Create New Investigation

```
Run a new analysis to help me fix flaky test with ID <testCaseId>
```

### With Existing Investigation

```
Retrieve the investigation for test <testCaseId> with investigationId <investigationId>
```

## Error Handling

| Error | Cause | Resolution |
| - | - | - |
| `Investigation {investigationId} not found` | Invalid or non-existent fix ID | Verify the investigationId from the previous query |
| `Please provide either \`investigationId\` or \`testCaseId\`.\` | Neither `investigationId` nor `testCaseId` was provided | Provide one of `investigationId` or `testCaseId` |
| `This investigation was skipped before producing a completed summary.` | The repository or test reached its monthly [investigation limit](../../agents/autofix-flaky-tests#investigation-limits), or investigations are disabled for the repository | Start the investigation by hand from the test's detail page, which is exempt from both limits, or revisit the prerequisites in [Autofix Flaky Tests](../../agents/autofix-flaky-tests) |
| `This investigation failed before producing a completed summary. Please contact Trunk support.` | Investigation error | This feature is still in Beta, please contact support |
| `... cannot investigate a test in a test collection yet` | Your organization has fully moved to [test collections](/flaky-tests/test-collections) | Use [`search-test`](./search-test) to see the test's status and quarantine state in its collection |
| Repository authorization error | Insufficient permissions or invalid repo name | Verify repository name format and your access permissions |
