Skip to content

Commit aa13066

Browse files
refactor: pass specTypeSchema() directly to ExtensionHandle (typescript-sdk#1846 StandardSchemaV1 widening)
setCustomRequestHandler/ExtensionHandle now accept StandardSchemaV1, so specTypeSchema('Name') can be passed directly without z.custom wrapping. Drops zod import from app.ts/app-bridge.ts where no longer needed.
1 parent c8bc264 commit aa13066

File tree

6 files changed

+2131
-52
lines changed

6 files changed

+2131
-52
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,16 @@ function postProcess(content: string): string {
193193
content = content.replace(
194194
'import { z } from "zod";',
195195
`import { z } from "zod/v4";
196-
import { isSpecType } from "@modelcontextprotocol/client";
196+
import { specTypeSchema } 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(
204204
new RegExp(`((?:export )?const ${schema}) = z\\.any\\(\\);`, "g"),
205-
`$1 = z.custom<${typeName}>((v) => isSpecType("${typeName}", v));`,
205+
`$1 = specTypeSchema("${typeName}");`,
206206
);
207207
}
208208

src/app-bridge.ts

Lines changed: 4 additions & 6 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 {
@@ -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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {
1+
specTypeSchema("PaginatedRequestParams"),specTypeSchema("PaginatedRequestParams"),import {
22
Client,
33
type CallToolRequest,
44
type ClientContext,
@@ -20,7 +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";
23+
import { specTypeSchema } from "@modelcontextprotocol/client";
2424
import { z } from "zod/v4";
2525
import {
2626
LATEST_PROTOCOL_VERSION,
@@ -226,9 +226,7 @@ export class App extends EventDispatcher<AppEventMap> {
226226
// Non-spec host→iframe tool surface (renamed from tools/call & tools/list).
227227
this.ui.setRequestHandler(
228228
"ui/call-view-tool",
229-
z.custom<CallToolRequest["params"]>((v) =>
230-
isSpecType("CallToolRequestParams", v),
231-
),
229+
specTypeSchema("CallToolRequestParams"),
232230
async (params, ctx) => {
233231
if (!this._oncalltool) throw new Error("No oncalltool handler set");
234232
return this._oncalltool(params, toExtra(ctx));
@@ -430,7 +428,7 @@ export class App extends EventDispatcher<AppEventMap> {
430428
return this.ui.sendRequest(
431429
"ui/update-model-context",
432430
params,
433-
z.custom<Record<string, never>>((v) => isSpecType("EmptyResult", v)),
431+
specTypeSchema("EmptyResult"),
434432
options,
435433
);
436434
}

0 commit comments

Comments
 (0)