This example demonstrates how to fix failed tests in CircleCI builds using the MCP Server API.
The example shows how to:
- Retrieve test results and failure logs from a CircleCI build
- Analyze test failure details to identify the root cause
- Automatically fix code issues causing test failures
- CircleCI account with Personal Access Token
- NodeJS 18+ installed
- Create a GitHub repository with contents of this directory
- Create a CircleCI Organization and a project named
fix-failed-testsand connect it to this GitHub repository. - Generate a CircleCI Personal Access Token.
- Push the code to GitHub and trigger a CircleCI build. The build will fail because there's a deliberate error in the math function implementation.
- Now you should see a test failure in the CircleCI pipeline.

- Configure the CircleCI MCP Server in your IDE. View setup instructions here

- Go to the IDE and open chat in agent mode. Ask the agent to
fix failed tests in ci.
- The agent should make the tool call and retrieve the test failure details.

- The agent will identify that the issue is in the math function implementation and fix it.

- Now you can make a commit to the repository and push it to GitHub. This will trigger a new build in CircleCI. You should see the tests passing.
