mcpField

API Contract Until Match

FeaturedOn demand
Code QualityUp to 10 rounds

About API Contract Until Match

This loop keeps an API implementation aligned with its published contract. Each round runs the contract tests, uses the failures to change the implementation, then re-tests in the next round until the suite passes or the round limit is reached.

Key features

  1. 01Judged by the exit code of the contract test suite
  2. 02Manual trigger, so the user decides when to start
  3. 03Capped at 10 rounds to avoid endless retries
  4. 04Supports Cursor

Use cases

  1. 01Confirming an API still follows its contract after an endpoint change
  2. 02Updating an existing implementation to a new contract version
  3. 03Checking that contract tests pass before merging
Goal
The API implementation matches the published contract and npm run test:contract passes.
Exit when
Stop when the contract test suite exits 0, or after 10 rounds if it still fails.
Between iterations run
npm run test:contract

Launch prompt

Paste into Cursor. The agent repeats the steps below until the exit condition is met.

prompt.md
Start the "API Contract Until Match" loop.
Goal: The API implementation matches the published contract and npm run test:contract passes.
Max iterations: 10.
Step 1: Run contract tests — Execute npm run test:contract and note the exit code and any failing cases. An exit code of 0 means the goal is met. `npm run test:contract`
Step 2: Diagnose failures — Read the failure output against the published contract to see whether the response shape, status code or parameter handling differs.
Step 3: Fix the implementation — Change only the code that deviates from the contract, leaving the contract itself untouched, then start the next round with another test run.
Between iterations run: `npm run test:contract`
Exit when: Stop when the contract test suite exits 0, or after 10 rounds if it still fails.

Steps

Each round runs in order; if the exit condition isn’t met, another round starts, up to 10.

01
Run contract tests

Execute npm run test:contract and note the exit code and any failing cases. An exit code of 0 means the goal is met.

$npm run test:contract
02
Diagnose failures

Read the failure output against the published contract to see whether the response shape, status code or parameter handling differs.

03
Fix the implementation

Change only the code that deviates from the contract, leaving the contract itself untouched, then start the next round with another test run.

Not met → next roundExits when met

Supported agents

Coding agents that can run this loop directly.

Cursor
Claude Code

Comments

Markdown supported