@@ -99,10 +99,15 @@ export function getToolUiResourceUri(tool: {
9999} ) : string | undefined {
100100 const meta = tool . _meta ;
101101 if ( ! meta ) return undefined ;
102- const nested = ( meta . ui as { resourceUri ?: string } | undefined ) ?. resourceUri ;
103- if ( typeof nested === "string" ) return nested ;
104- const flat = meta [ RESOURCE_URI_META_KEY ] ;
105- return typeof flat === "string" ? flat : undefined ;
102+ const ui = meta . ui as { resourceUri ?: unknown } | undefined ;
103+ const candidate = ui && "resourceUri" in ui ? ui . resourceUri : meta [ RESOURCE_URI_META_KEY ] ;
104+ if ( candidate === undefined ) return undefined ;
105+ if ( typeof candidate !== "string" || ! candidate . startsWith ( "ui://" ) ) {
106+ throw new Error (
107+ "Tool _meta.ui.resourceUri must be a string starting with ui://, got: " + JSON . stringify ( candidate ) ,
108+ ) ;
109+ }
110+ return candidate ;
106111}
107112
108113/**
@@ -242,7 +247,7 @@ export class App extends EventDispatcher<AppEventMap> {
242247 event : K ,
243248 params : AppEventMap [ K ] ,
244249 ) : void {
245- if ( event === "hostcontextchanged" ) {
250+ if ( event === "hostcontextchanged" && this . _hostContext !== undefined ) {
246251 this . _hostContext = { ...this . _hostContext , ...( params as McpUiHostContext ) } ;
247252 }
248253 }
@@ -270,7 +275,7 @@ export class App extends EventDispatcher<AppEventMap> {
270275 * Current host context (theme, locale, displayMode, hostStyles, …). Updated
271276 * automatically by `ui/notifications/host-context-changed`.
272277 */
273- getHostContext ( ) : McpUiHostContext {
278+ getHostContext ( ) : McpUiHostContext | undefined {
274279 return this . _hostContext ;
275280 }
276281
@@ -439,7 +444,7 @@ export class App extends EventDispatcher<AppEventMap> {
439444 ) ;
440445 }
441446 /** @deprecated Use {@link openLink `openLink`}. */
442- sendOpenLink : App [ "openLink" ] = ( p , o ) => this . openLink ( p , o ) ;
447+ get sendOpenLink ( ) { return this . openLink ; }
443448
444449 /** Ask the host to download a file to the user's machine. */
445450 downloadFile (
@@ -481,7 +486,7 @@ export class App extends EventDispatcher<AppEventMap> {
481486 return this . ui . sendNotification ( "ui/notifications/size-changed" , params ) ;
482487 }
483488 /** @deprecated Use {@link sendSizeChanged `sendSizeChanged`}. */
484- notifySizeChanged : App [ "sendSizeChanged" ] = ( p ) => this . sendSizeChanged ( p ) ;
489+ get notifySizeChanged ( ) { return this . sendSizeChanged ; }
485490
486491 /**
487492 * Start observing document size and emitting size-changed notifications.
0 commit comments