Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion examples/say-server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,13 +672,15 @@ def generate_sync():
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="color-scheme" content="light dark">
<title>Say View</title>
<script src="https://unpkg.com/@babel/[email protected]/babel.min.js"></script>
<script type="importmap">
{
"imports": {
"react": "https://esm.sh/[email protected]",
"react-dom/client": "https://esm.sh/[email protected]/client",
"@modelcontextprotocol/ext-apps": "https://esm.sh/@modelcontextprotocol/[email protected][email protected]&external=react,react-dom",
"@modelcontextprotocol/ext-apps/react": "https://esm.sh/@modelcontextprotocol/[email protected]/[email protected]&external=react,react-dom"
}
}
Expand Down Expand Up @@ -769,8 +771,14 @@ def generate_sync():
.infoPopup a:hover { text-decoration: underline; }
.infoPopup ul { margin: 0; padding-left: 16px; }
.infoPopup li { margin: 4px 0; }
/* Dark mode: host-provided theme via data-theme attribute */
[data-theme="dark"] {
--color-text-primary: #eee;
--color-text-secondary: #666;
}
/* Fallback: system preference when running standalone without host */
@media (prefers-color-scheme: dark) {
:root {
:root:not([data-theme]) {
--color-text-primary: #eee;
--color-text-secondary: #666;
}
Expand All @@ -783,6 +791,7 @@ def generate_sync():
import React, { useState, useCallback, useEffect, useRef, StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { useApp } from '@modelcontextprotocol/ext-apps/react';
import { applyDocumentTheme, applyHostStyleVariables, applyHostFonts } from '@modelcontextprotocol/ext-apps';

function SayView() {
const [hostContext, setHostContext] = useState(undefined);
Expand Down Expand Up @@ -1251,6 +1260,16 @@ def generate_sync():
if (params.displayMode) {
setDisplayMode(params.displayMode);
}
// Apply host theme and styles
if (params.theme) {
applyDocumentTheme(params.theme);
}
if (params.styles?.variables) {
applyHostStyleVariables(params.styles.variables);
}
if (params.styles?.css?.fonts) {
applyHostFonts(params.styles.css.fonts);
}
};
},
});
Expand All @@ -1265,6 +1284,16 @@ def generate_sync():
if (ctx?.displayMode) {
setDisplayMode(ctx.displayMode);
}
// Apply initial host theme and styles
if (ctx?.theme) {
applyDocumentTheme(ctx.theme);
}
if (ctx?.styles?.variables) {
applyHostStyleVariables(ctx.styles.variables);
}
if (ctx?.styles?.css?.fonts) {
applyHostFonts(ctx.styles.css.fonts);
}
}, [app]);

// Speak lock: coordinate with other TTS Views
Expand Down
Loading