Skip to content

Commit f7490c6

Browse files
fix: alias getters for .toBe() identity; visibility empty-array; getToolUiResourceUri validation (v1 parity)
1 parent 7e8ae10 commit f7490c6

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

src/app-bridge.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export function isToolVisibilityModelOnly(tool: {
161161
_meta?: Record<string, unknown>;
162162
}): boolean {
163163
const v = (tool._meta?.ui as McpUiToolMeta | undefined)?.visibility;
164-
return Array.isArray(v) && !v.includes("app");
164+
return Array.isArray(v) && v.length > 0 && !v.includes("app");
165165
}
166166

167167
/**
@@ -171,7 +171,7 @@ export function isToolVisibilityAppOnly(tool: {
171171
_meta?: Record<string, unknown>;
172172
}): boolean {
173173
const v = (tool._meta?.ui as McpUiToolMeta | undefined)?.visibility;
174-
return Array.isArray(v) && !v.includes("model");
174+
return Array.isArray(v) && v.length > 0 && !v.includes("model");
175175
}
176176

177177
/**
@@ -616,8 +616,7 @@ export class AppBridge extends EventDispatcher<AppBridgeEventMap> {
616616
);
617617
}
618618
/** @deprecated Use {@link teardownResource `teardownResource`}. */
619-
sendResourceTeardown: AppBridge["teardownResource"] = (p, o) =>
620-
this.teardownResource(p, o);
619+
get sendResourceTeardown() { return this.teardownResource; }
621620

622621
/**
623622
* Call a tool the **view** exposes (see {@link app!App.oncalltool}).

src/app.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)