|
| 1 | +# Severity Signaling in Markdown - Rich Content Improvements |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Enhanced the MCP 2.0 rich content blocks with standardized Markdown formatting for severity levels, making findings and violations immediately scannable in Cursor IDE. |
| 6 | + |
| 7 | +## Problem Statement |
| 8 | + |
| 9 | +Previously, violation and finding blocks were difficult to scan quickly: |
| 10 | +- No clear visual hierarchy for different severity levels |
| 11 | +- Users had to read entire blocks to understand importance |
| 12 | +- Mixed formatting styles across different content types |
| 13 | +- Hard to prioritize which issues to fix first |
| 14 | + |
| 15 | +## Solution Implemented |
| 16 | + |
| 17 | +Introduced standardized severity labels with Markdown headers and blockquotes: |
| 18 | + |
| 19 | +```markdown |
| 20 | +[🔴 HIGH SEVERITY] - Critical architectural flaws |
| 21 | +[🟡 ADVISORY] - Important improvements |
| 22 | +[🔵 INFO] - Informational notes |
| 23 | +``` |
| 24 | + |
| 25 | +## Key Improvements |
| 26 | + |
| 27 | +### 1. Scannable Headers |
| 28 | + |
| 29 | +**Before:** |
| 30 | +```markdown |
| 31 | +🔴 high **Effect.fail should use TaggedError** |
| 32 | +``` |
| 33 | + |
| 34 | +**After:** |
| 35 | +```markdown |
| 36 | +## [🔴 HIGH SEVERITY] Effect.fail should use TaggedError |
| 37 | +``` |
| 38 | + |
| 39 | +**Benefits:** |
| 40 | +- H2/H3 headers create visual breaks in the IDE |
| 41 | +- Color-coded emoji immediately signals importance |
| 42 | +- Semantic HTML structure improves accessibility |
| 43 | + |
| 44 | +### 2. Blockquoted Descriptions |
| 45 | + |
| 46 | +**Before:** |
| 47 | +```markdown |
| 48 | +Effect.fail without a TaggedError is deprecated in v4. |
| 49 | +``` |
| 50 | + |
| 51 | +**After:** |
| 52 | +```markdown |
| 53 | +> **Issue:** Effect.fail without a TaggedError is deprecated in v4. |
| 54 | +``` |
| 55 | + |
| 56 | +**Benefits:** |
| 57 | +- Blockquotes visually separate content from code |
| 58 | +- Creates indented emphasis in most renderers |
| 59 | +- Improves visual hierarchy |
| 60 | +- Better distinction between content types |
| 61 | + |
| 62 | +### 3. Structured Sections |
| 63 | + |
| 64 | +**Before:** |
| 65 | +```markdown |
| 66 | +**Example of violation:** |
| 67 | +[code block] |
| 68 | +**Remediation:** |
| 69 | +[remediation text] |
| 70 | +``` |
| 71 | + |
| 72 | +**After:** |
| 73 | +```markdown |
| 74 | +### Problematic Pattern |
| 75 | +[code block] |
| 76 | + |
| 77 | +### How to Fix |
| 78 | +> [remediation text] |
| 79 | +``` |
| 80 | + |
| 81 | +**Benefits:** |
| 82 | +- Clear subsections with headers |
| 83 | +- Consistent formatting across all violations |
| 84 | +- Easy navigation within long findings lists |
| 85 | + |
| 86 | +## API Functions |
| 87 | + |
| 88 | +### `createSeverityBlock(severity, title, description, relatedCode?)` |
| 89 | + |
| 90 | +Creates a single scannable finding block: |
| 91 | + |
| 92 | +```typescript |
| 93 | +createSeverityBlock( |
| 94 | + "high", |
| 95 | + "Missing Error Types", |
| 96 | + "All Effect.fail calls must use typed errors via Data.TaggedError", |
| 97 | + ` |
| 98 | + // ❌ Don't do this |
| 99 | + Effect.fail(new Error("Something went wrong")) |
| 100 | + |
| 101 | + // ✅ Do this |
| 102 | + Effect.fail(new UserError({ id: 123 })) |
| 103 | + ` |
| 104 | +) |
| 105 | +``` |
| 106 | + |
| 107 | +### `createFindingsSummary(findings)` |
| 108 | + |
| 109 | +Generates a findings summary grouped by severity: |
| 110 | + |
| 111 | +```typescript |
| 112 | +createFindingsSummary([ |
| 113 | + { |
| 114 | + severity: "high", |
| 115 | + title: "Untyped Errors", |
| 116 | + description: "Error types must be explicit", |
| 117 | + code: "Effect.fail(new Error(...))", |
| 118 | + }, |
| 119 | + { |
| 120 | + severity: "medium", |
| 121 | + title: "Missing Documentation", |
| 122 | + description: "Service requires JSDoc comments", |
| 123 | + }, |
| 124 | + { |
| 125 | + severity: "low", |
| 126 | + title: "Code Style", |
| 127 | + description: "Consider using const instead of let", |
| 128 | + }, |
| 129 | +]) |
| 130 | +``` |
| 131 | + |
| 132 | +Produces: |
| 133 | + |
| 134 | +```markdown |
| 135 | +## Findings Summary (3 total) |
| 136 | + |
| 137 | +### 🔴 High Severity (1) |
| 138 | +#### [🔴 HIGH SEVERITY] Untyped Errors |
| 139 | +> **Issue:** Error types must be explicit |
| 140 | +
|
| 141 | +[code block] |
| 142 | + |
| 143 | +### 🟡 Advisory (1) |
| 144 | +#### [🟡 ADVISORY] Missing Documentation |
| 145 | +> **Issue:** Service requires JSDoc comments |
| 146 | +
|
| 147 | +### 🔵 Info (1) |
| 148 | +#### [🔵 INFO] Code Style |
| 149 | +> **Issue:** Consider using const instead of let |
| 150 | +``` |
| 151 | + |
| 152 | +### `buildViolationContent(ruleName, severity, message, remediation, example?)` |
| 153 | + |
| 154 | +Enhanced violation blocks with severity signaling: |
| 155 | + |
| 156 | +```typescript |
| 157 | +buildViolationContent( |
| 158 | + "async-await-in-effect", |
| 159 | + "🔴 high", |
| 160 | + "Using async/await in Effect context", |
| 161 | + "Replace with Effect combinators like Effect.promise or Effect.tryPromise", |
| 162 | + ` |
| 163 | + // ❌ Don't |
| 164 | + async function getData() { |
| 165 | + const data = await fetchUser(); |
| 166 | + return data; |
| 167 | + } |
| 168 | + |
| 169 | + // ✅ Do |
| 170 | + const getData = () => Effect.tryPromise({ |
| 171 | + try: () => fetchUser(), |
| 172 | + catch: (error) => new FetchError({ cause: error }) |
| 173 | + }) |
| 174 | + ` |
| 175 | +) |
| 176 | +``` |
| 177 | + |
| 178 | +## Rendering Examples |
| 179 | + |
| 180 | +### High Severity Finding |
| 181 | + |
| 182 | +Renders as: |
| 183 | + |
| 184 | +``` |
| 185 | +## [🔴 HIGH SEVERITY] Untyped Error Handling |
| 186 | +
|
| 187 | +> **Issue:** Effect.fail() requires typed errors via Data.TaggedError |
| 188 | +> for proper error tracking and type safety. |
| 189 | +
|
| 190 | +### Problematic Pattern |
| 191 | +
|
| 192 | +```typescript |
| 193 | +export const getUser = (id: number) => |
| 194 | + Effect.fail(new Error('User not found')) // ❌ Untyped |
| 195 | +``` |
| 196 | + |
| 197 | +### How to Fix |
| 198 | + |
| 199 | +> Define a TaggedError type for each error scenario, then use it |
| 200 | +> consistently across your service. |
| 201 | +``` |
| 202 | +
|
| 203 | +### Medium Severity Finding |
| 204 | +
|
| 205 | +Renders as: |
| 206 | +
|
| 207 | +``` |
| 208 | +### [🟡 ADVISORY] Missing Error Boundaries |
| 209 | + |
| 210 | +> **Issue:** This service lacks proper error handling at its boundaries. |
| 211 | +
|
| 212 | +### How to Fix |
| 213 | + |
| 214 | +> Wrap async operations with Effect.tryPromise and handle potential errors |
| 215 | +> using Effect.catchTag for specific error types. |
| 216 | +``` |
| 217 | +
|
| 218 | +### Low Severity Finding |
| 219 | +
|
| 220 | +Renders as: |
| 221 | +
|
| 222 | +``` |
| 223 | +#### [🔵 INFO] Code Style Note |
| 224 | + |
| 225 | +> Consider using const instead of let for better immutability semantics. |
| 226 | +``` |
| 227 | +
|
| 228 | +## Benefits for Users |
| 229 | +
|
| 230 | +### 1. Immediate Scannability |
| 231 | +- Users see severity at a glance |
| 232 | +- Color-coded emoji provides instant visual feedback |
| 233 | +- No need to read entire block to understand importance |
| 234 | +
|
| 235 | +### 2. Better Prioritization |
| 236 | +- High severity findings appear first |
| 237 | +- Clear visual separation between priority levels |
| 238 | +- Easier to focus on critical issues |
| 239 | +
|
| 240 | +### 3. Improved Readability |
| 241 | +- Markdown headers create natural breaks |
| 242 | +- Blockquotes emphasize important information |
| 243 | +- Consistent structure across all findings |
| 244 | +
|
| 245 | +### 4. IDE Integration |
| 246 | +- Cursor IDE renders headers with proper styling |
| 247 | +- Blockquotes appear indented and emphasized |
| 248 | +- Emoji support for visual distinction |
| 249 | +
|
| 250 | +## Usage in Code Review Tools |
| 251 | +
|
| 252 | +Perfect for: |
| 253 | +- Code analysis tool outputs |
| 254 | +- Pattern violation reports |
| 255 | +- Migration guidance documents |
| 256 | +- Architecture review findings |
| 257 | +- Anti-pattern detection results |
| 258 | +
|
| 259 | +## Backward Compatibility |
| 260 | +
|
| 261 | +The new functions are additions to the existing API: |
| 262 | +- Existing functions remain unchanged |
| 263 | +- New functions follow the same conventions |
| 264 | +- Easy gradual migration path |
| 265 | +- No breaking changes |
| 266 | +
|
| 267 | +## Implementation Details |
| 268 | +
|
| 269 | +### Priority Mapping |
| 270 | +
|
| 271 | +Severity levels map to MCP annotation priorities: |
| 272 | +
|
| 273 | +```typescript |
| 274 | +severity: "high" → priority: 1 (highest) |
| 275 | +severity: "medium" → priority: 2 (medium) |
| 276 | +severity: "low" → priority: 3 (lowest) |
| 277 | +``` |
| 278 | + |
| 279 | +### Audience Tagging |
| 280 | + |
| 281 | +All severity blocks tagged with: |
| 282 | +```typescript |
| 283 | +audience: ["user"] // Visible to end users |
| 284 | +``` |
| 285 | + |
| 286 | +### Markdown Structure |
| 287 | + |
| 288 | +Follows semantic HTML conventions: |
| 289 | +- H1: Document title |
| 290 | +- H2: Major sections (Before/After, Severity groups) |
| 291 | +- H3: Subsections (Issues to Address, Key Improvements) |
| 292 | +- Blockquotes: Emphasis and recommendations |
| 293 | +- Code fences: Code examples |
| 294 | + |
| 295 | +## Testing |
| 296 | + |
| 297 | +All new functions maintain: |
| 298 | +- Type safety with TypeScript |
| 299 | +- Proper Markdown rendering |
| 300 | +- Consistent annotation structure |
| 301 | +- MCP 2.0 compliance |
| 302 | + |
| 303 | +See `mcp-content-builders.test.ts` for examples. |
| 304 | + |
| 305 | +## Future Enhancements |
| 306 | + |
| 307 | +Potential additions: |
| 308 | +- Custom color schemes per severity |
| 309 | +- Expandable/collapsible sections |
| 310 | +- Interactive severity filters |
| 311 | +- Export to different formats (HTML, PDF) |
| 312 | +- Integration with IDE quick fixes |
| 313 | + |
| 314 | +## References |
| 315 | + |
| 316 | +- [MCP 2.0 Specification](https://modelcontextprotocol.io/docs/spec/2.0/protocol) |
| 317 | +- [Markdown Guide](https://www.markdownguide.org) |
| 318 | +- [Semantic HTML](https://developer.mozilla.org/en-US/docs/Glossary/Semantics) |
0 commit comments