| name | api-contract-sync |
| description | Ensures frontend and backend agree on API request/response shapes using Apidog MCP as the single source of truth. Replaces manual contracts.md files. Use when implementing or reviewing API endpoints and their consumers. Automatically loaded by team-lead, backend-dev, web-dev, mobile-dev, and reviewer. |
| user-invokable | false |
API Contract Sync Protocol
Apidog MCP is the single source of truth for all API contracts in this project.
Every agent that implements or consumes an API endpoint MUST verify against Apidog.
Contract Flow
Apidog Specification (source of truth)
│
├──→ team-lead: defines shared types/models matching spec
│
├──→ backend-dev: implements endpoints matching spec exactly
│
├──→ web-dev / mobile-dev: consumes endpoints using typed clients
│
├──→ test-worker: validates against spec in tests
│
└──→ reviewer: verifies all implementations match spec
Note: For mobile-only projects without a backend (e.g., apps consuming third-party APIs),
API contracts are defined by the external API documentation. Use Apidog to document the
external API surface your app consumes, or skip this protocol if no API layer exists.
For Team Lead
Before spawning workers for any API-related feature:
-
Query Apidog MCP for the relevant endpoint specifications
-
Create or update shared types/models that match the spec:
Web/TypeScript Projects:
- Create interfaces in
src/types/ for request bodies, response types, path/query params
Flutter/Dart Projects:
- Create model classes in
lib/core/models/ for request DTOs, response models, enums
Other Projects:
- Define types/models in the appropriate shared location for the detected stack
-
Include the Apidog project reference in each worker's spawn prompt
If the endpoint doesn't exist in Apidog yet:
- Define the endpoint specification first
- Get it documented in Apidog before spawning workers
- Reference the spec in spawn prompts
For Backend Workers
When implementing an API endpoint:
-
Query Apidog MCP for the endpoint specification before writing code
-
Match exactly: Your route handler must:
- Accept the documented request shape
- Return the documented response shape
- Handle all documented error codes
-
Validate input using schemas/validators that match the Apidog spec:
Web/TypeScript (Zod example):
const CreateItemSchema = z.object({
name: z.string().min(1).max(200),
description: z.string().min(1).max(5000),
});
Flutter/Dart (freezed/json_serializable example):
// Model must match Apidog spec for the endpoint
@freezed
class CreateItemRequest with _$CreateItemRequest {
factory CreateItemRequest({
required String name,
required String description,
}) = _CreateItemRequest;
factory CreateItemRequest.fromJson(Map<String, dynamic> json) =>
_$CreateItemRequestFromJson(json);
}
-
Return consistent error shapes appropriate to your stack
-
If you must deviate from the spec, STOP and notify the team-lead
For Frontend Workers
When consuming an API endpoint:
-
Query Apidog MCP for the endpoint specification before coding
-
Import shared types/models — never define API types locally
- Web/TypeScript: import from
src/types/
- Flutter/Dart: import from
lib/core/models/
-
Handle all documented status codes appropriately for your stack:
Web/TypeScript:
const response = await fetch(`/api/items/${id}`, {
method: 'POST',
body: JSON.stringify(data),
});
if (!response.ok) {
const error = await response.json();
}
Flutter/Dart:
final response = await dio.post('/api/items/$id', data: data.toJson());
// Handle error status codes documented in Apidog
// Use either try/catch with DioException or response status checks
-
If the API is not ready yet (backend-dev hasn't finished):
- Use mock data that matches the Apidog spec exactly
- Mark with a TODO comment referencing the Apidog spec endpoint ID
For Reviewer
When reviewing API-related changes:
- Query Apidog MCP for each endpoint touched in the changeset
- Verify backend matches spec: request validation, response shape, error codes
- Verify frontend matches spec: types used, error codes handled, shapes correct
- Flag mismatches as Critical: any deviation from the Apidog spec must be fixed
- Check shared types: ensure shared types/models match the Apidog spec
Anti-Patterns to Avoid
- Creating
contracts.md files manually — use Apidog MCP instead
- Defining API types in both frontend and backend — use shared types from the central location
- Implementing endpoints without checking Apidog first — spec drift risk
- Using
any for API response types — defeats the purpose of contract sync