-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Description
Summary
The current zod-compat.ts implementation fails to correctly identify standard Zod v4 schemas (e.g. from zod@4.1.13) because it relies on checking for an internal _zod property, which is absent in standard builds. This causes Zod v4 schemas to be treated as v3, wrapped in v3 objects, and subsequently lose metadata like description in prompt arguments and additionalProperties: false in tool input schemas.
Reproduction
- Install
zod@4alongside the SDK. - Register a prompt with arguments using
.describe():server.prompt("test", "test prompt", { arg: z.string().describe("My description") }, ...);
- Call
listPrompts(). - Expected: The argument has
description: "My description". - Actual: The
descriptionfield is missing.
Root Cause Analysis
In src/server/zod-compat.ts:
export function isZ4Schema(s: AnySchema): s is z4.$ZodType {
// Present on Zod 4 (Classic & Mini) schemas; absent on Zod 3
const schema = s as unknown as ZodV4Internal;
return !!schema._zod;
}Standard Zod v4 schemas do not have _zod.
Consequently, objectFromShape falls through to the v3 path:
if (allV3) return z3rt.object(shape as Record<string, z3.ZodTypeAny>);It wraps the Zod v4 schema in a Zod v3 object. This mismatch appears to break getSchemaDescription or the schema normalization process down the line.
Context
This is relevant to #1251 (Migrate to Zod 4).
Metadata
Metadata
Assignees
Labels
No labels