Fix sandbox proxy ready detection in simple-host example (#47)
Replace Zod schema's internal _def.value access with a direct string literal. The previous approach failed due to multiple Zod instances being bundled, causing schema.shape.method._def.value to return undefined. The fix uses a typed string constant that provides compile-time safety via McpUiSandboxProxyReadyNotification["method"] while avoiding runtime dependency on Zod internals. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
parent
5e78a1ef05
commit
484768c3d1
1 changed files with 5 additions and 6 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { McpUiSandboxProxyReadyNotificationSchema } from "@modelcontextprotocol/ext-apps";
|
import type { McpUiSandboxProxyReadyNotification } from "@modelcontextprotocol/ext-apps";
|
||||||
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
||||||
import { Tool } from "@modelcontextprotocol/sdk/types.js";
|
import { Tool } from "@modelcontextprotocol/sdk/types.js";
|
||||||
|
|
||||||
|
|
@ -8,6 +8,9 @@ export async function setupSandboxProxyIframe(sandboxProxyUrl: URL): Promise<{
|
||||||
iframe: HTMLIFrameElement;
|
iframe: HTMLIFrameElement;
|
||||||
onReady: Promise<void>;
|
onReady: Promise<void>;
|
||||||
}> {
|
}> {
|
||||||
|
const SANDBOX_PROXY_READY_METHOD: McpUiSandboxProxyReadyNotification["method"] =
|
||||||
|
"ui/notifications/sandbox-proxy-ready";
|
||||||
|
|
||||||
const iframe = document.createElement("iframe");
|
const iframe = document.createElement("iframe");
|
||||||
iframe.style.width = "100%";
|
iframe.style.width = "100%";
|
||||||
iframe.style.height = "600px";
|
iframe.style.height = "600px";
|
||||||
|
|
@ -18,11 +21,7 @@ export async function setupSandboxProxyIframe(sandboxProxyUrl: URL): Promise<{
|
||||||
const onReady = new Promise<void>((resolve, _reject) => {
|
const onReady = new Promise<void>((resolve, _reject) => {
|
||||||
const initialListener = async (event: MessageEvent) => {
|
const initialListener = async (event: MessageEvent) => {
|
||||||
if (event.source === iframe.contentWindow) {
|
if (event.source === iframe.contentWindow) {
|
||||||
if (
|
if (event.data && event.data.method === SANDBOX_PROXY_READY_METHOD) {
|
||||||
event.data &&
|
|
||||||
event.data.method ===
|
|
||||||
McpUiSandboxProxyReadyNotificationSchema.shape.method._def.value
|
|
||||||
) {
|
|
||||||
window.removeEventListener("message", initialListener);
|
window.removeEventListener("message", initialListener);
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue