Skip to content

Commit 2fe270f

Browse files
refactor: pass specTypeSchema() directly to ExtensionHandle (typescript-sdk#1846 StandardSchemaV1 widening)
generated/schema.ts keeps z.custom(isSpecType()) since it composes into Zod chains; specTypeSchema() is used at the ExtensionHandle boundary where the SDK now accepts StandardSchemaV1. app-bridge event-map params type widened ZodType -> StandardSchemaV1. app.ts no longer imports zod.
1 parent c8bc264 commit 2fe270f

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/generate-schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ import { isSpecType } from "@modelcontextprotocol/client";
197197
import type { ${typeImports} } from "@modelcontextprotocol/client";`,
198198
);
199199

200-
// 2. Replace z.any() placeholders for external SDK types with isSpecType-backed z.custom
200+
// 2. Replace z.any() placeholders for external SDK types with specTypeSchema()
201201
for (const schema of EXTERNAL_TYPE_SCHEMAS) {
202202
const typeName = schema.replace(/Schema$/, "");
203203
content = content.replace(

src/app-bridge.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
} from "@modelcontextprotocol/server";
2727

2828
import { EventDispatcher } from "./events";
29-
import { isSpecType } from "@modelcontextprotocol/server";
29+
import { specTypeSchema } from "@modelcontextprotocol/server";
3030
import {
3131
LATEST_PROTOCOL_VERSION,
3232
McpUiAppCapabilities,
@@ -93,9 +93,7 @@ function toExtra(ctx: ServerContext): RequestHandlerExtra {
9393
return { signal: ctx.mcpReq.signal };
9494
}
9595

96-
const LogParamsSchema = z.custom<LoggingMessageNotification["params"]>(
97-
(v) => v != null && typeof v === "object",
98-
);
96+
const LogParamsSchema = specTypeSchema("LoggingMessageNotificationParams");
9997

10098
/** Options for constructing an {@link AppBridge `AppBridge`}. */
10199
export interface HostOptions extends ProtocolOptions {
@@ -124,7 +122,7 @@ export type AppBridgeEventMap = {
124122

125123
const BRIDGE_EVENT_NOTIFICATION_SCHEMAS: Record<
126124
keyof AppBridgeEventMap,
127-
{ method: string; params: z.ZodType }
125+
{ method: string; params: StandardSchemaV1 }
128126
> = {
129127
sizechange: {
130128
method: McpUiSizeChangedNotificationSchema.shape.method.value,
@@ -634,7 +632,7 @@ export class AppBridge extends EventDispatcher<AppBridgeEventMap> {
634632
return this.ui.sendRequest(
635633
"ui/call-view-tool",
636634
params,
637-
z.custom<CallToolResult>((v) => isSpecType("CallToolResult", v)),
635+
specTypeSchema("CallToolResult"),
638636
options,
639637
);
640638
}
@@ -648,7 +646,7 @@ export class AppBridge extends EventDispatcher<AppBridgeEventMap> {
648646
return this.ui.sendRequest(
649647
"ui/list-view-tools",
650648
params,
651-
z.custom<ListToolsResult>((v) => isSpecType("ListToolsResult", v)),
649+
specTypeSchema("ListToolsResult"),
652650
options,
653651
);
654652
}

src/app.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ import {
2020
import { EventDispatcher } from "./events";
2121
export { EventDispatcher, ProtocolWithEvents } from "./events";
2222
import { PostMessageTransport } from "./message-transport";
23-
import { isSpecType } from "@modelcontextprotocol/client";
24-
import { z } from "zod/v4";
23+
import { specTypeSchema } from "@modelcontextprotocol/client";
2524
import {
2625
LATEST_PROTOCOL_VERSION,
2726
McpUiAppCapabilities,
@@ -226,19 +225,15 @@ export class App extends EventDispatcher<AppEventMap> {
226225
// Non-spec host→iframe tool surface (renamed from tools/call & tools/list).
227226
this.ui.setRequestHandler(
228227
"ui/call-view-tool",
229-
z.custom<CallToolRequest["params"]>((v) =>
230-
isSpecType("CallToolRequestParams", v),
231-
),
228+
specTypeSchema("CallToolRequestParams"),
232229
async (params, ctx) => {
233230
if (!this._oncalltool) throw new Error("No oncalltool handler set");
234231
return this._oncalltool(params, toExtra(ctx));
235232
},
236233
);
237234
this.ui.setRequestHandler(
238235
"ui/list-view-tools",
239-
z.custom<ListToolsRequest["params"]>((v) =>
240-
v === undefined || isSpecType("PaginatedRequestParams", v),
241-
),
236+
specTypeSchema("PaginatedRequestParams"),
242237
async (params, ctx) => {
243238
if (!this._onlisttools) throw new Error("No onlisttools handler set");
244239
return this._onlisttools(params, toExtra(ctx));
@@ -430,7 +425,7 @@ export class App extends EventDispatcher<AppEventMap> {
430425
return this.ui.sendRequest(
431426
"ui/update-model-context",
432427
params,
433-
z.custom<Record<string, never>>((v) => isSpecType("EmptyResult", v)),
428+
specTypeSchema("EmptyResult"),
434429
options,
435430
);
436431
}

0 commit comments

Comments
 (0)