Skip to content

Conversation

@martinalong
Copy link
Collaborator

Motivation and Context

  • Existing approach to styles only works with system fonts, not custom ones that need to be loaded or google fonts
  • Fonts can't be passed through variables alone, since they require a <link> tag or a @font-face CSS declaration
  • So this PR adds a styles.css.fonts CSS string to Host Context, which apps will inject into a script tag using applyHostFonts or useHostFonts

How Has This Been Tested?

Yes, manually tested

Breaking Changes

None

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@martinalong martinalong force-pushed the martinalong/mcp-apps/custom-fonts branch from 3be22a5 to 4d9cc91 Compare December 16, 2025 06:54
@martinalong martinalong force-pushed the martinalong/mcp-apps/custom-fonts branch from 4d9cc91 to 6397ec1 Compare December 16, 2025 06:54
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 16, 2025

Open in StackBlitz

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/ext-apps@159

commit: 6397ec1

/** CSS blocks that apps can inject */
css?: {
/** CSS for font loading (@font-face rules or @import statements) */
fonts?: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not conceptually different than having an arbitrary css chunk that can be injected, which we didn't want to introduce.
Perhaps we need to make it more restricted somehow?

Copy link
Collaborator Author

@martinalong martinalong Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this was considered, but I think it's worth it b/c this is the most ergonomic and flexible approach by far. Also, the host can already just inject arbitrary css directly into the app HTML anyways. So this doesn't change the "security" at all. We kind of have to trust hosts b/c they're already hosting the app and could do any number of things to it


```typescript
if (hostContext.styles?.css?.fonts) {
applyHostFonts(hostContext.styles.css.fonts);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to refer to specific implementations in the abstract spec itself?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wdym refer to specific implementations? I have more specific examples of how hosts can specify font files elsewhere in this file already if that's what you're asking!


// Check if already loaded
if (document.getElementById(styleId)) {
return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: probably better to update the style tag content instead of returning early

@antonpk1 antonpk1 merged commit 242ec23 into main Dec 17, 2025
9 checks passed
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.

5 participants