Skip to content

applyHostFonts ignores updated fonts from host-context-changed #873

Backlog

Description

@aishwary-dongre

Describe the bug

applyHostFonts injects styles.css.fonts once and then ignores every later call:

// src/styles.ts
if (document.getElementById(styleId)) {
  return;
}

So when a host sends different fonts in ui/notifications/host-context-changed, the View keeps the first fonts. useHostFonts (and useHostStyles) call applyHostFonts from their hostcontextchanged listener and document "apply updated fonts", but the update never takes effect. The spec says a host MAY send host-context-changed "when any context field changes", so a font change after ui/initialize, for example on a theme switch that changes font families, is allowed.

To reproduce

applyHostFonts("@font-face { font-family: A; }");
applyHostFonts("@font-face { font-family: B; }");
// document.getElementById("__mcp-host-fonts").textContent is still the "A" rule

With useHostStyles(app, app.getHostContext()): connect with fonts in the initial host context, then send host-context-changed with a different styles.css.fonts. The style tag keeps the initial CSS.

Expected behavior

A later call replaces the injected font CSS, still using a single <style> tag, so updated fonts apply and repeated calls don't add duplicate tags.

Proposed fix

Reuse the existing #__mcp-host-fonts element and replace its textContent when the CSS differs. I have this with unit tests and can open a PR.

Environment

@modelcontextprotocol/ext-apps main at ea3e9d0 (2.1.0).

AI assistance

I used an AI coding assistant (Claude, in the Kiro IDE) to read the source, write the reproduction, and draft this report. I checked the behavior myself.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions