import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
/**
* Register text replacement strategy prompt
*/
export function registerTextReplacementPrompts(server: McpServer): void {
server.prompt(
"text_replacement_strategy",
"Systematic approach for replacing text in Figma designs",
() => {
return {
messages: [
{
role: "assistant",
content: {
type: "text",
text: `# Intelligent Text Replacement Strategy
## 1. Analyze Design & Identify Structure
- Scan text nodes to understand the overall structure of the design
- Use AI pattern recognition to identify logical groupings:
* Tables (rows, columns, headers, cells)
* Lists (items, headers, nested lists)
* Card groups (similar cards with recurring text fields)
* Forms (labels, input fields, validation text)
* Navigation (menu items, breadcrumbs)
\`\`\`
scan_text_nodes(nodeId: "node-id")
get_node_info(nodeId: "node-id") // optional
\`\`\`
## 2. Strategic Chunking for Complex Designs
- Divide replacement tasks into logical content chunks based on design structure
- Use one of these chunking strategies that best fits the design:
* **Structural Chunking**: Table rows/columns, list sections, card groups
* **Spatial Chunking**: Top-to-bottom, left-to-right in screen areas
* **Semantic Chunking**: Content related to the same topic or functionality
* **Component-Based Chunking**: Process similar component instances together
## 3. Progressive Replacement with Verification
- Create a safe copy of the node for text replacement
- Replace text chunk by chunk with continuous progress updates
- After each chunk is processed:
* Export that section as a small, manageable image
* Verify text fits properly and maintain design integrity
* Fix issues before proceeding to the next chunk
\`\`\`
// Clone the node to create a safe copy
clone_node(nodeId: "selected-node-id", x: [new-x], y: [new-y])
// Replace text chunk by chunk
set_multiple_text_contents(
nodeId: "parent-node-id",
text: [
{ nodeId: "node-id-1", text: "New text 1" },
// More nodes in this chunk...
]
)
// Verify chunk with small, targeted image exports
export_node_as_image(nodeId: "chunk-node-id", format: "PNG", scale: 0.5)
\`\`\`
## 4. Intelligent Handling for Table Data
- For tabular content:
* Process one row or column at a time
* Maintain alignment and spacing between cells
* Consider conditional formatting based on cell content
* Preserve header/data relationships
## 5. Smart Text Adaptation
- Adaptively handle text based on container constraints:
* Auto-detect space constraints and adjust text length
* Apply line breaks at appropriate linguistic points
* Maintain text hierarchy and emphasis
* Consider font scaling for critical content that must fit
## 6. Progressive Feedback Loop
- Establish a continuous feedback loop during replacement:
* Real-time progress updates (0-100%)
* Small image exports after each chunk for verification
* Issues identified early and resolved incrementally
* Quick adjustments applied to subsequent chunks
## 7. Final Verification & Context-Aware QA
- After all chunks are processed:
* Export the entire design at reduced scale for final verification
* Check for cross-chunk consistency issues
* Verify proper text flow between different sections
* Ensure design harmony across the full composition
## 8. Chunk-Specific Export Scale Guidelines
- Scale exports appropriately based on chunk size:
* Small chunks (1-5 elements): scale 1.0
* Medium chunks (6-20 elements): scale 0.7
* Large chunks (21-50 elements): scale 0.5
* Very large chunks (50+ elements): scale 0.3
* Full design verification: scale 0.2
## Sample Chunking Strategy for Common Design Types
### Tables
- Process by logical rows (5-10 rows per chunk)
- Alternative: Process by column for columnar analysis
- Tip: Always include header row in first chunk for reference
### Card Lists
- Group 3-5 similar cards per chunk
- Process entire cards to maintain internal consistency
- Verify text-to-image ratio within cards after each chunk
### Forms
- Group related fields (e.g., "Personal Information", "Payment Details")
- Process labels and input fields together
- Ensure validation messages and hints are updated with their fields
### Navigation & Menus
- Process hierarchical levels together (main menu, submenu)
- Respect information architecture relationships
- Verify menu fit and alignment after replacement
## Best Practices
- **Preserve Design Intent**: Always prioritize design integrity
- **Structural Consistency**: Maintain alignment, spacing, and hierarchy
- **Visual Feedback**: Verify each chunk visually before proceeding
- **Incremental Improvement**: Learn from each chunk to improve subsequent ones
- **Balance Automation & Control**: Let AI handle repetitive replacements but maintain oversight
- **Respect Content Relationships**: Keep related content consistent across chunks
Remember that text is never just text—it's a core design element that must work harmoniously with the overall composition. This chunk-based strategy allows you to methodically transform text while maintaining design integrity.`,
},
},
],
description: "Systematic approach for replacing text in Figma designs",
};
},
);
}