Skip to content

Commit 707ceee

Browse files
committed
Merge remote-tracking branch 'origin/main' into ochafik/openai-compatibility
2 parents d0c69dc + 3e95d64 commit 707ceee

File tree

19 files changed

+382
-16
lines changed

19 files changed

+382
-16
lines changed

examples/budget-allocator-server/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { z } from "zod";
1616
import {
1717
RESOURCE_MIME_TYPE,
1818
RESOURCE_URI_META_KEY,
19+
registerAppResource,
20+
registerAppTool,
1921
} from "@modelcontextprotocol/ext-apps/server";
2022
import { startServer } from "../shared/server-utils.js";
2123

examples/cohort-heatmap-server/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { z } from "zod";
77
import {
88
RESOURCE_MIME_TYPE,
99
RESOURCE_URI_META_KEY,
10+
registerAppResource,
11+
registerAppTool,
1012
} from "@modelcontextprotocol/ext-apps/server";
1113
import { startServer } from "../shared/server-utils.js";
1214

examples/customer-segmentation-server/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { z } from "zod";
1010
import {
1111
RESOURCE_MIME_TYPE,
1212
RESOURCE_URI_META_KEY,
13+
registerAppResource,
14+
registerAppTool,
1315
} from "@modelcontextprotocol/ext-apps/server";
1416
import { startServer } from "../shared/server-utils.js";
1517
import {

examples/customer-segmentation-server/src/mcp-app.css

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
:root {
33
color-scheme: light dark;
44

5+
/* Font families */
6+
--font-sans: system-ui, -apple-system, sans-serif;
7+
58
/* Background colors */
69
--color-background-primary: light-dark(#ffffff, #111827);
710
--color-background-secondary: light-dark(#f9fafb, #1f2937);
@@ -16,12 +19,19 @@
1619
--color-border-primary: light-dark(#e5e7eb, #374151);
1720
--color-border-secondary: light-dark(#d1d5db, #4b5563);
1821

19-
/* Accent colors */
20-
--color-accent-info: light-dark(#2563eb, #3b82f6);
22+
/* Ring colors */
23+
--color-ring-info: light-dark(#2563eb, #3b82f6);
2124

2225
/* Border radius */
2326
--border-radius-sm: 6px;
2427
--border-radius-md: 8px;
28+
--border-radius-full: 9999px;
29+
30+
/* Border width */
31+
--border-width-regular: 1px;
32+
33+
/* Shadows */
34+
--shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
2535

2636
/* App-specific colors (not from host) */
2737
--color-enterprise: light-dark(#1e40af, #3b82f6);
@@ -33,6 +43,7 @@
3343
html, body {
3444
margin: 0;
3545
padding: 0;
46+
font-family: var(--font-sans);
3647
color: var(--color-text-primary);
3748
overflow: hidden;
3849
}
@@ -94,15 +105,15 @@ html, body {
94105
.select {
95106
padding: 4px 8px;
96107
font-size: 0.8125rem;
97-
border: 1px solid var(--color-border-primary);
108+
border: var(--border-width-regular) solid var(--color-border-primary);
98109
border-radius: var(--border-radius-sm);
99110
background: var(--color-background-secondary);
100111
color: var(--color-text-primary);
101112
cursor: pointer;
102113
}
103114

104115
.select:focus {
105-
outline: 2px solid var(--color-accent-info);
116+
outline: 2px solid var(--color-ring-info);
106117
outline-offset: 1px;
107118
}
108119

@@ -113,7 +124,7 @@ html, body {
113124
background: var(--color-background-secondary);
114125
border-radius: var(--border-radius-md);
115126
padding: 8px;
116-
border: 1px solid var(--color-border-primary);
127+
border: var(--border-width-regular) solid var(--color-border-primary);
117128
}
118129

119130
.chart-container {
@@ -143,15 +154,15 @@ html, body {
143154
font-size: 0.75rem;
144155
cursor: pointer;
145156
padding: 4px 10px;
146-
border-radius: 16px;
147-
border: 1px solid var(--color-border-primary);
157+
border-radius: var(--border-radius-full);
158+
border: var(--border-width-regular) solid var(--color-border-primary);
148159
background: var(--color-background-secondary);
149160
transition: all 0.15s ease;
150161
}
151162

152163
.legend-item:hover {
153164
border-color: var(--color-text-secondary);
154-
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
165+
box-shadow: var(--shadow-sm);
155166
}
156167

157168
.legend-item.hidden {
@@ -192,7 +203,7 @@ html, body {
192203
background: var(--color-background-secondary);
193204
border-radius: var(--border-radius-sm);
194205
padding: 0 12px;
195-
border: 1px solid var(--color-border-primary);
206+
border: var(--border-width-regular) solid var(--color-border-primary);
196207
font-size: 0.8125rem;
197208
}
198209

examples/customer-segmentation-server/src/mcp-app.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
App,
66
PostMessageTransport,
77
applyHostStyleVariables,
8+
applyHostFonts,
89
applyDocumentTheme,
910
} from "@modelcontextprotocol/ext-apps";
1011
import { Chart, registerables } from "chart.js";
@@ -448,14 +449,17 @@ applyDocumentTheme(systemDark ? "dark" : "light");
448449
// Register handlers and connect
449450
app.onerror = log.error;
450451

451-
// Handle host context changes (theme and styles from host)
452+
// Handle host context changes (theme, styles, and fonts from host)
452453
app.onhostcontextchanged = (params) => {
453454
if (params.theme) {
454455
applyDocumentTheme(params.theme);
455456
}
456457
if (params.styles?.variables) {
457458
applyHostStyleVariables(params.styles.variables);
458459
}
460+
if (params.styles?.css?.fonts) {
461+
applyHostFonts(params.styles.css.fonts);
462+
}
459463
// Recreate chart to pick up new colors
460464
if (state.chart && (params.theme || params.styles?.variables)) {
461465
state.chart.destroy();
@@ -472,6 +476,9 @@ app.connect().then(() => {
472476
if (ctx?.styles?.variables) {
473477
applyHostStyleVariables(ctx.styles.variables);
474478
}
479+
if (ctx?.styles?.css?.fonts) {
480+
applyHostFonts(ctx.styles.css.fonts);
481+
}
475482
});
476483

477484
// Fetch data after connection

examples/scenario-modeler-server/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { z } from "zod";
1010
import {
1111
RESOURCE_MIME_TYPE,
1212
RESOURCE_URI_META_KEY,
13+
registerAppResource,
14+
registerAppTool,
1315
} from "@modelcontextprotocol/ext-apps/server";
1416
import { startServer } from "../shared/server-utils.js";
1517

examples/system-monitor-server/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { z } from "zod";
1212
import {
1313
RESOURCE_MIME_TYPE,
1414
RESOURCE_URI_META_KEY,
15+
registerAppResource,
16+
registerAppTool,
1517
} from "@modelcontextprotocol/ext-apps/server";
1618
import { startServer } from "../shared/server-utils.js";
1719

examples/threejs-server/server.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { z } from "zod";
1212
import {
1313
RESOURCE_MIME_TYPE,
1414
RESOURCE_URI_META_KEY,
15+
registerAppResource,
16+
registerAppTool,
1517
} from "@modelcontextprotocol/ext-apps/server";
1618
import { startServer } from "../shared/server-utils.js";
1719

@@ -178,9 +180,8 @@ function createServer(): McpServer {
178180
},
179181
);
180182

181-
// Tool 2: learn_threejs
182-
registerAppTool(
183-
server,
183+
// Tool 2: learn_threejs (not a UI tool, just returns documentation)
184+
server.registerTool(
184185
"learn_threejs",
185186
{
186187
title: "Learn Three.js",

examples/wiki-explorer-server/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { z } from "zod";
1111
import {
1212
RESOURCE_MIME_TYPE,
1313
RESOURCE_URI_META_KEY,
14+
registerAppResource,
15+
registerAppTool,
1416
} from "@modelcontextprotocol/ext-apps/server";
1517
import { startServer } from "../shared/server-utils.js";
1618

specification/draft/apps.mdx

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,11 @@ interface HostContext {
451451
styles?: {
452452
/** CSS variables for theming */
453453
variables?: Record<McpUiStyleVariableKey, string | undefined>;
454+
/** CSS blocks that apps can inject */
455+
css?: {
456+
/** CSS for font loading (@font-face rules or @import statements) */
457+
fonts?: string;
458+
};
454459
};
455460
/** How the UI is currently displayed */
456461
displayMode?: "inline" | "fullscreen" | "pip";
@@ -503,8 +508,11 @@ Example:
503508
"variables": {
504509
"--color-background-primary": "light-dark(#ffffff, #171717)",
505510
"--color-text-primary": "light-dark(#171717, #fafafa)",
506-
"--font-family-sans": "system-ui, sans-serif",
511+
"--font-sans": "Anthropic Sans, sans-serif",
507512
...
513+
},
514+
"css": {
515+
"fonts": "@font-face { font-family: \"Custom Font Name\"; src: url(\"https://...\"); }"
508516
}
509517
},
510518
"displayMode": "inline",
@@ -544,6 +552,7 @@ type McpUiStyleVariableKey =
544552
| "--color-text-success"
545553
| "--color-text-warning"
546554
| "--color-text-disabled"
555+
| "--color-text-ghost"
547556
// Border colors
548557
| "--color-border-primary"
549558
| "--color-border-secondary"
@@ -638,7 +647,46 @@ Example usage of standardized CSS variables:
638647
.container {
639648
background: var(--color-background-primary);
640649
color: var(--color-text-primary);
641-
font: var(--font-style-body);
650+
font-family: var(--font-sans);
651+
}
652+
```
653+
654+
#### Custom Fonts
655+
656+
Hosts can provide custom fonts via `styles.css.fonts`, which can contain `@font-face` rules for self-hosted fonts, `@import` statements for font services like Google Fonts, or both:
657+
658+
```typescript
659+
hostContext.styles.variables["--font-sans"] = '"Font Name", sans-serif';
660+
661+
// Self-hosted fonts
662+
hostContext.styles.css.fonts = `
663+
@font-face {
664+
font-family: "Font Name";
665+
src: url("https://url-where-font-is-hosted.com/.../Regular.otf") format("opentype");
666+
font-weight: 400;
667+
font-style: normal;
668+
font-display: swap;
669+
}
670+
@font-face {
671+
font-family: "Font Name";
672+
src: url("https://url-where-font-is-hosted.com/.../Medium.otf") format("opentype");
673+
font-weight: 500;
674+
font-style: medium;
675+
font-display: swap;
676+
}
677+
`;
678+
679+
// Google Fonts
680+
hostContext.styles.css.fonts = `
681+
@import url('https://fonts.googleapis.com/css2?family=Font+Name&display=swap');
682+
`;
683+
```
684+
685+
Apps can use the `applyHostFonts` utility to inject the font CSS into the document:
686+
687+
```typescript
688+
if (hostContext.styles?.css?.fonts) {
689+
applyHostFonts(hostContext.styles.css.fonts);
642690
}
643691
```
644692

0 commit comments

Comments
 (0)