Repository navigation
Commit 6b42270
authored
feat(ui): display server icons in the registry web client (modelcontextprotocol#1586)
Closes modelcontextprotocol#784.
Servers can declare `icons` in `server.json` and the schema has
supported it for some time, but the web client never rendered them, so
every card looks identical apart from its text. This renders them in
both the "Recently Updated" cards and the main search results.
## Selection
- **HTTPS only at render time.** `validateIcon` already rejects other
schemes at publish, but this UI can be pointed at a staging, local or
custom API base URL from its own settings, so the scheme is re-checked
rather than trusted.
- **Scalable icons win outright** (`sizes: ["any"]`). Otherwise the
smallest icon at least as wide as the rendered size, so it stays crisp
without fetching a needlessly large file.
- **`theme: "dark"` is a fallback only**, used when nothing else is
offered, since this UI has a light background.
## Rendering
- `src` goes through the existing `escapeAttr`, so a quote in a URL
cannot break out of the attribute.
- `alt` is empty on purpose: the icon sits directly beside the server
name, so announcing it again is noise for screen readers.
- `loading="lazy"` stops a full grid of cards fetching every icon at
once.
- `referrerpolicy="no-referrer"` avoids leaking registry URLs to
third-party icon hosts.
- A broken or blocked image removes itself rather than leaving a
placeholder in the layout.
SVG is rendered via `<img src>`, where scripts do not execute, which is
the safe path for the `image/svg+xml` case the schema warns about.
## Testing
Ran the selection logic against the first 100 servers in the production
registry. That covers every icon shape currently published:
| Published shape | Picked |
|---|---|
| no `sizes` field | the only icon |
| single `512x512` | `512x512` |
| `["any"]` (SVG) | the SVG |
| `256x256` + `512x512` | `256x256` |
| single `96x96` | `96x96` |
Also verified that `http://`, `javascript:`, `data:` and null sources
render nothing, that a dark-only icon set still renders, that light is
preferred when both are offered, and that a quote injected into `src` is
escaped rather than breaking the attribute.
Unit tests pass, including `internal/api/handlers/v0`, the package that
embeds this file.
**Two pre-existing failures, noted for transparency:** `make validate`
and `make lint` both fail identically on a clean checkout of `main` with
these changes absent. The lint ones are `gofmt` objecting to CRLF from a
Windows checkout. Neither is introduced here and neither is touched by
this change. Tests ran without `-race`, which needs cgo and a C
toolchain unavailable on my machine.1 parent 909717d commit 6b42270
1 file changed
Lines changed: 54 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
| 321 | + | |
321 | 322 | | |
322 | 323 | | |
323 | 324 | | |
| |||
386 | 387 | | |
387 | 388 | | |
388 | 389 | | |
| 390 | + | |
389 | 391 | | |
390 | 392 | | |
391 | 393 | | |
| |||
544 | 546 | | |
545 | 547 | | |
546 | 548 | | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
547 | 601 | | |
548 | 602 | | |
549 | 603 | | |
| |||
0 commit comments