Applicability
When to Use
✓When some functionality is better than no functionality
✓When primary services have known outage windows
✓When user experience should not completely break
Overview
How It Works
The Fallback pattern provides alternative behavior when an MCP server is unavailable. Instead of showing an error, the agent falls back to cached data, a simpler alternative, or a static response. This maintains partial functionality during outages.
Fallbacks are defined per-feature, not per-server. Each feature decides what degraded behavior is acceptable: stale cache data, default values, or a user-friendly message explaining reduced functionality.
Implementation
Code Example
typescript
async function withFallback(primary, fallback) {
try {
return await primary();
} catch (error) {
console.warn(`Primary failed, using fallback: ${error.message}`);
return await fallback();
}
}
// Usage
const userData = await withFallback(
() => postgres.query("SELECT * FROM users WHERE id=$1", [userId]),
async () => {
const cached = await redis.get(`user:${userId}`);
if (cached) return { ...JSON.parse(cached), _stale: true };
return { id: userId, name: "Unknown User", _fallback: true };
}
);
const weather = await withFallback(
() => weatherApi.getCurrent({ city }),
() => ({ temp: "N/A", condition: "Weather data temporarily unavailable", _fallback: true })
);Quick Info
Categoryresilience
ComplexityEasy