Skip to content

feat(web): display package icons in server list#1208

Open
MukundaKatta wants to merge 1 commit intomodelcontextprotocol:mainfrom
MukundaKatta:feat/icon-support-784
Open

feat(web): display package icons in server list#1208
MukundaKatta wants to merge 1 commit intomodelcontextprotocol:mainfrom
MukundaKatta:feat/icon-support-784

Conversation

@MukundaKatta
Copy link
Copy Markdown

Why

Closes #784. The in-browser registry UI today renders server cards with no visual at all — even though many server.json files already declare icons. Browsing 1,000+ servers as a wall of text makes it hard to spot the one you want at a glance.

What

Adds a small icon tile to each card in both lists (Recently Updated and the main grid):

  • Reads server.icons[] from the existing API response (already exposed via pkg/api/v0/types.go, no API change).
  • Picks the best icon: theme: "light" first (page is light-themed), then theme-agnostic, then dark.
  • Renders an <img> with width="40" height="40" for layout stability (no CLS), loading="lazy" so off-screen icons don't fetch, referrerpolicy="no-referrer" to avoid leaking the page URL to icon hosts.
  • Hardens the URL: HTTPS-only check (/^https:\/\//i), matching the schema requirement on Icon.src. Defends against javascript: / data: / http:// if a future server slips past validation.
  • On onerror (broken URL, mixed content, CORS), swaps in a generic inline-SVG fallback tile. Same fallback is used when the server has no icons at all, so the layout stays consistent.
  • Fallback is a CSS background-image data-URI — no extra network request, no asset to ship, CSP-friendly.

Two files changed:

  • internal/api/handlers/v0/ui_index.html — adds pickIconSrc(), renderIconTile(), the fallback CSS, and the tile slot in both card renderers.
  • internal/api/handlers/v0/ui_test.go (new) — guards the icon wiring (helper function names, loading="lazy", dimensions, HTTPS check) so a future refactor surfaces in CI.

Tested

  • go test ./internal/api/handlers/v0/... (the new TestGetUIHTML_IconSupport plus the existing handler tests) passes locally.
  • Manual: served the binary, opened /, confirmed:
    • Servers with valid HTTPS icons render the icon.
    • Servers without icons render the generic fallback tile.
    • A server with a broken icon URL falls back without breaking the card layout.
    • loading="lazy" confirmed in DevTools, no network requests for icons below the fold until scrolled.

Render each server's icon (when present in server.json) in the in-browser
UI cards. Falls back to a generic inline-SVG tile when missing or when the
remote URL fails to load. Uses lazy-loaded <img> with explicit dimensions
to avoid layout shift, restricts URLs to HTTPS to match the schema, and
sets referrerpolicy=no-referrer.

Closes modelcontextprotocol#784
@MukundaKatta MukundaKatta force-pushed the feat/icon-support-784 branch from 2827885 to 9c349e8 Compare April 28, 2026 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Icon support in web client

1 participant