fix(examples): improve updateModelContext with structured YAML frontmatter (#271)

* map-server: fix async/await in ontoolresult, remove unused getViewStorageKey

* fix(map-server): improve updateModelContext and fix initialization

- Use structured YAML frontmatter format for model context (like pdf-server)
- Add tool name, altitude, and cleaner data format
- Fix initialization deadlock: app.connect() was inside ontoolresult handler
  which could never fire until connected
- Fix view state persistence: widgetUUID now properly extracted from
  ontoolresult and used to restore persisted camera position
- Server now includes widgetUUID in tool result _meta for widget identification

* fix(pdf-server): use widgetUUID for page persistence

- Add widgetUUID to tool result _meta for widget identification
- Use widgetUUID instead of generated key (pdfUrl+toolId) for localStorage
- Enables reliable page restoration when revisiting PDF widgets

* fix(transcript-server): use structured YAML frontmatter for model context

- Add tool name, listening status, and unsent entry count in frontmatter
- Consistent format with pdf-server and map-server

* update names

* drop bogus altitude

* Update mcp-app.ts
This commit is contained in:
Olivier Chafik 2026-01-14 22:08:09 +00:00 • committed by GitHub
commit 75ecd62384
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -329,18 +329,31 @@ function updateSendButton() {
sendBtn.disabled = unsentEntries.length === 0;
}
/**
* Update model context with structured YAML frontmatter (like pdf-server, map-server).
*/
function updateModelContext() {
const caps = app.getHostCapabilities();
if (!caps?.updateModelContext) return;
const text = getUnsentText();
const unsentCount = getUnsentEntries().length;
log.info("Updating model context:", text || "(empty)");
// Build structured markdown with YAML frontmatter
const frontmatter = [
"---",
"tool: transcribe",
`status: ${isListening ? "listening" : "paused"}`,
`unsent-entries: ${unsentCount}`,
"---",
].join("\n");
const markdown = text ? `${frontmatter}\n\n${text}` : frontmatter;
app
.updateModelContext({
content: text
? [{ type: "text", text: `[Live transcript]: ${text}` }]
: [],
content: [{ type: "text", text: markdown }],
})
.catch((e: unknown) => {
log.warn("Failed to update model context:", e);