suggest_fix
Generate AI-powered code patches for accessibility and UX findings
suggest_fix
Generate AI-powered code patches to fix accessibility and UX issues. This is the key remediation tool that provides actionable fixes with confidence scores.
Description
The suggest_fix tool analyzes a finding and generates a code patch that resolves the issue. It returns a search/replace pattern that can be applied to your source code.
This is the "aha moment" tool - getting AI-suggested fixes from natural language requests is what makes the MCP integration powerful.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| finding_id | string | required | Single finding ID to fix |
| audit_id | string | required | Parent audit containing the finding |
| finding_ids | string[] | optional | Array of finding IDs for batch fixes |
| file_content | string | optional | Source code content for more accurate patches |
| file_path | string | optional | Path to the file being fixed (for context) |
Response
typepropertiesConfidence Levels
| Level | Percentage | Meaning | Action |
|---|---|---|---|
| HIGH | 80-100% | Safe to apply | Apply directly |
| MEDIUM | 50-79% | Likely correct | Review before applying |
| LOW | 0-49% | Significant changes | Careful manual review required |
Even HIGH confidence fixes should be tested. AI suggestions are not guaranteed to be perfect.
Example Conversations
Single Fix
"Suggest a fix for finding fnd_xyz789"
suggest_fix({
finding_id: "fnd_xyz789",
audit_id: "aud_abc123"
})Fix with Source Context
"Suggest a fix for this button issue. Here's my Button.tsx file: [code]"
Providing file content improves patch accuracy:
suggest_fix({
finding_id: "fnd_xyz789",
audit_id: "aud_abc123",
file_content: "// Your Button.tsx content...",
file_path: "src/components/Button.tsx"
})Batch Fixes
"Fix all critical findings from the last audit"
suggest_fix({
audit_id: "aud_abc123",
finding_ids: ["fnd_001", "fnd_002", "fnd_003"]
})Returns an array of patches.
Natural Language Request
"The audit found a missing alt text issue. Can you fix it?"
Claude will identify the relevant finding and call suggest_fix automatically.
Applying Patches
Manual Application
- Find the
searchstring in your code - Replace with the
replacestring - Verify the change works
Search/Replace Pattern
The patch uses a literal search/replace model:
// Original (search)
<button onClick={handleSubmit}>
<Icon name="check" />
</button>
// Fixed (replace)
<button onClick={handleSubmit} aria-label="Submit form">
<Icon name="check" />
</button>Editor Integration
Most editors support find/replace:
- VS Code: Ctrl/Cmd + H
- Cursor: Ctrl/Cmd + H
- Vim:
:%s/search/replace/g
Example Patches
Button Accessibility
// Search
<button onClick={handleClick}>
<TrashIcon />
</button>
// Replace
<button onClick={handleClick} aria-label="Delete item">
<TrashIcon />
</button>Confidence: HIGH (92%) Explanation: Icon-only buttons need aria-label for screen readers.
Color Contrast
/* Search */
.hero-text {
color: #999999;
}
/* Replace */
.hero-text {
color: #595959;
}Confidence: HIGH (88%) Explanation: Changed color to meet 4.5:1 contrast ratio.
Missing Form Label
// Search
<input
type="email"
placeholder="Enter your email"
/>
// Replace
<label>
<span className="sr-only">Email address</span>
<input
type="email"
placeholder="Enter your email"
/>
</label>Confidence: MEDIUM (72%) Explanation: Added programmatic label association. Review the sr-only class implementation.
When needs_human_review is True
The needs_human_review flag indicates:
- Complex changes affecting multiple elements
- Changes that might affect functionality
- Framework-specific patterns that need verification
- Low confidence fixes
When true, carefully review:
- The suggested change makes sense
- It doesn't break existing functionality
- It follows your project's patterns
Verification
After applying a fix:
- Run the hint: Use the
verification_hint(e.g., test with screen reader) - Re-audit: Run
audit_urlagain to confirm the issue is resolved - Test functionality: Ensure the element still works correctly
Workflow
Complete fix workflow:
1. audit_url → Get audit ID
2. get_findings → Find issues
3. explain_finding → Understand (optional)
4. suggest_fix → Get patch
5. Apply patch manually or use generate_pr
6. audit_url → Verify fix workedRelated
- explain_finding - Understand before fixing
- get_findings - Get finding IDs
- Tools Reference - All available tools
- SDK: Audits - Programmatic approach
Was this page helpful?