Commit 1a12987
feat(mcp): render lesson MDX in the lesson widgets the way the app does
`lessons.content` is MDX — markdown plus the ~30 JSX components the web app
maps in `components/lesson/mdx-components.tsx` (`<Callout>`, `<Quiz>`,
`<Steps>`, `<Table>`, `<Video>`, `<LessonCheckpoint>`, …). The two MCP lesson
widgets ran that source through plain react-markdown, so every authored
component reached the student as literal source text, `JSON.parse('…')`
payloads included, and `embed_code` was dropped entirely.
Widgets can not compile-and-run MDX: `@mdx-js/mdx`'s run() builds the module
with the Function constructor, which the widget CSP sandbox blocks. So parse
only — remark + remark-mdx keeps JSX as mdxJsxFlowElement nodes — and render
that mdast with React. JSX attribute expressions are resolved without a JS
runtime, including the `{JSON.parse('…')}` form the block editor serializes.
- `resources/shared/lesson/`: mdast parser + attribute resolver, the widget
port of the app's lesson component map, and the mdast→React renderer
- both lesson widgets now render video / embed_code / MDX in the same order as
`lesson-content.tsx`; `lms_get_lesson` selects and passes `embed_code`
- unknown tags keep their text, an unparseable lesson falls back to its source,
and an error boundary stops one bad component from blanking the lesson
- `LessonCheckpoint` renders a marker: checkpoint attempts are server-write-only
and need the lesson's checkpoint provider, neither of which exists in a widget
Bundle cost is ~+280 KB raw (~+70 KB gzip) per lesson widget for remark-mdx.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QpttCAB3gFD9H5WFHG4boW1 parent d2cef7c commit 1a12987
15 files changed
Lines changed: 2494 additions & 66 deletions
File tree
- docs/images
- mcp-server
- resources
- lesson-preview
- lesson-viewer
- src/tools
- tests/unit
Loading
Loading
Loading
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
| 44 | + | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
170 | 171 | | |
171 | 172 | | |
172 | 173 | | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
204 | 178 | | |
205 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
206 | 186 | | |
207 | 187 | | |
208 | 188 | | |
| |||
0 commit comments