Skip to main content
When CI goes red, someone has to read the logs, work out which tests failed and why, and decide whether the change broke them or they’re flaky. A coding agent can do that first pass when it gets the failures in a structured form instead of raw logs. Trunk’s MCP server provides them: its investigate-ci-failure tool takes a GitHub Actions run URL and returns each failed test with its error message, leaving out the tests Trunk has quarantined. This recipe sets up a Cursor Automation that runs when CI completes, investigates the failure with Trunk, and opens a pull request with the fix. It extends Cursor’s CI Autofix template.

Before you begin

  • Your repository uploads test results to Trunk.
  • Quarantining is on, so the agent skips failures from known flaky tests.
  • You have your organization API token, from Settings → Developer → API Keys, in the Organization API token (v1) section.

1. Connect Trunk’s MCP server

In Cursor, add Trunk’s MCP server as trunk, with bearer authentication and your organization API token. A cloud automation can’t complete an interactive login, so it needs the token.

2. Create the automation

Create an automation from Cursor’s CI Autofix template, and add the trunk MCP server to its actions.
Configuration for Cursor Automation
This configuration triggers on a completed CI run, has the agent claim the failure so two runs don’t fix it at once, and calls investigate-ci-failure with the run’s URL. Replace <repo> with your repository:
CI Autofix automation
Cursor opens the fix with main as its base. To merge the fix into the failing pull request instead, change the fix’s base branch to that pull request’s branch.

3. Tune the prompt

  • Describe your repository’s conventions and its common failure patterns, so the agent’s fixes match how your team works.
  • Keep the agent on investigate-ci-failure and off the raw CI logs unless it needs them. The logs cost more time and tokens.
  • Put a version in the automation’s name, such as CI Autofix v2, so you can tell which prompt opened a pull request.