# Saga Compensation Planner AI Agent Connect

> Orchestrates deterministic recovery paths for distributed transactions using the Saga pattern.

## Overview
- **Category:** reliability
- **Price:** Free
- **Endpoint:** https://edge.vinkius.com/vk_preview_lMjX0ajuDbrzqBOXRrJ6VCZvWmp3yKdSZyqzd27C/ai-agent-connect
- **Tags:** saga-pattern, transaction-management, error-recovery, distributed-transactions, orchestrator

## Description

This MCP server provides a deterministic orchestration engine for managing distributed transactions via the Saga pattern. When a multi-agent transaction fails, this tool calculates the exact reverse-order compensation sequence required to revert the system to a consistent state. It determines the necessary compensation steps, calculates total recovery time, and evaluates the final saga state (such as COMPENSATED or REQUIRES_MANUAL_INTERVENTION). Use `plan_compensation_sequence` to map out recovery paths, `get_saga_metadata` to retrieve correlation IDs and idempotency keys, and `evaluate_saga_status` to assess the outcome of compensation attempts.

## Tools

### evaluate_saga_status
Determines the high-level status of the transaction based on the outcome of the compensation attempts

### get_saga_metadata
Retrieves the unique tracking identifiers used to maintain the lifecycle of the specific saga instance

### plan_compensation_sequence
Calculates the exact order of compensation actions and the total projected time required to revert the transaction

## Prompt Examples

**Prompt:** 
```
Calculate the compensation plan for a saga where the failure occurred at step index 2, given these steps: [{stepId: '1', agentId: 'A', action: 'reserve', compensationAction: 'cancel', timeoutMs: 500}, {stepId: '2', agentId: 'B', action: 'pay', compensationAction: 'refund', timeoutMs: 1000}]
```

**Response:** 
```
The compensation sequence will execute 'refund' for step 2, then 'cancel' for step 1. The total compensation time is 1500ms.
```

**Prompt:** 
```
What is the current status of a saga if all compensation attempts were successful?
```

**Response:** 
```
The saga state is COMPENSATED.
```

**Prompt:** 
```
How do I get the idempotency keys for my saga steps?
```

**Response:** 
```
You can use the `get_saga_metadata` tool to retrieve the unique stepIdempotencyKeys for each step in your saga.
```

## Frequently Asked Questions

**What is the purpose of the compensation sequence?**
The compensation sequence provides the exact, reverse-order list of actions needed to undo successful steps after a transaction failure, ensuring system consistency.

**How does the tool handle a failure during the compensation phase?**
If a compensation action fails, the tool identifies the state as FAILED_COMPENSATION or REQUIRES_MANUAL_INTERVENTION to alert the system that automated recovery could not be completed.

**Can I use this to track transactions across multiple agents?**
Yes, by using `get_saga_metadata`, you can retrieve the correlation ID used to trace the transaction across all participating agents.
