optimize_card
Optimizes Adaptive Cards for accessibility, performance, and compatibility with Microsoft Teams, Outlook, and other platforms.
Instructions
Optimize an existing Adaptive Card. Accepts card JSON or a cardId.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| card | Yes | The Adaptive Card JSON object or cardId to optimize | |
| goals | No | Optimization goals. Default: all | |
| host | No | Target host app |
Implementation Reference
- The handleOptimizeCard function is the core handler for the 'optimize_card' tool. It receives a card and a set of optimization goals, iterates through the requested goals, applies corresponding optimization transformations, and returns the optimized card along with a report of the changes and performance improvements.
export function handleOptimizeCard(input: OptimizeCardInput): OptimizeCardOutput { const { card, goals = ["accessibility", "performance", "modern"], host } = input; // Capture before metrics const statsBefore = analyzeCard(card); const accessBefore = checkAccessibility(card); // Deep clone the card for mutation const optimized = JSON.parse(JSON.stringify(card)) as Record<string, unknown>; const changes: Change[] = []; // Apply each optimization goal in order for (const goal of goals) { switch (goal) { case "accessibility": optimizeAccessibility(optimized, changes); break; case "performance": optimizePerformance(optimized, changes); break; case "compact": optimizeCompact(optimized, changes); break; case "modern": optimizeModern(optimized, changes); break; case "readability": optimizeReadability(optimized, changes); break; } } // Capture after metrics const statsAfter = analyzeCard(optimized); const accessAfter = checkAccessibility(optimized); return { card: optimized, changes, improvement: { accessibilityBefore: accessBefore.score, accessibilityAfter: accessAfter.score, elementCountBefore: statsBefore.elementCount, elementCountAfter: statsAfter.elementCount, nestingDepthBefore: statsBefore.nestingDepth, nestingDepthAfter: statsAfter.nestingDepth, }, }; }