diff --git a/src/client/index.ts b/src/client/index.ts index 03a6b40b5..ae0e698ec 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -53,15 +53,7 @@ import { } from '../types.js'; import { AjvJsonSchemaValidator } from '../validation/ajv-provider.js'; import type { JsonSchemaType, JsonSchemaValidator, jsonSchemaValidator } from '../validation/types.js'; -import { - AnyObjectSchema, - SchemaOutput, - getObjectShape, - isZ4Schema, - safeParse, - type ZodV3Internal, - type ZodV4Internal -} from '../server/zod-compat.js'; +import { AnyObjectSchema, SchemaOutput, getLiteralValue, getObjectShape, safeParse } from '../server/zod-compat.js'; import type { RequestHandlerExtra } from '../shared/protocol.js'; import { ExperimentalClientTasks } from '../experimental/tasks/client.js'; import { assertToolsCallTaskCapability, assertClientRequestTaskCapability } from '../experimental/tasks/helpers.js'; @@ -339,18 +331,7 @@ export class Client< throw new Error('Schema is missing a method literal'); } - // Extract literal value using type-safe property access - let methodValue: unknown; - if (isZ4Schema(methodSchema)) { - const v4Schema = methodSchema as unknown as ZodV4Internal; - const v4Def = v4Schema._zod?.def; - methodValue = v4Def?.value ?? v4Schema.value; - } else { - const v3Schema = methodSchema as unknown as ZodV3Internal; - const legacyDef = v3Schema._def; - methodValue = legacyDef?.value ?? v3Schema.value; - } - + const methodValue = getLiteralValue(methodSchema); if (typeof methodValue !== 'string') { throw new Error('Schema method literal must be a string'); } diff --git a/src/server/index.ts b/src/server/index.ts index 531a559dd..cd75e5954 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -44,15 +44,7 @@ import { } from '../types.js'; import { AjvJsonSchemaValidator } from '../validation/ajv-provider.js'; import type { JsonSchemaType, jsonSchemaValidator } from '../validation/types.js'; -import { - AnyObjectSchema, - getObjectShape, - isZ4Schema, - safeParse, - SchemaOutput, - type ZodV3Internal, - type ZodV4Internal -} from './zod-compat.js'; +import { AnyObjectSchema, getLiteralValue, getObjectShape, safeParse, SchemaOutput } from './zod-compat.js'; import { RequestHandlerExtra } from '../shared/protocol.js'; import { ExperimentalServerTasks } from '../experimental/tasks/server.js'; import { assertToolsCallTaskCapability, assertClientRequestTaskCapability } from '../experimental/tasks/helpers.js'; @@ -228,18 +220,7 @@ export class Server< throw new Error('Schema is missing a method literal'); } - // Extract literal value using type-safe property access - let methodValue: unknown; - if (isZ4Schema(methodSchema)) { - const v4Schema = methodSchema as unknown as ZodV4Internal; - const v4Def = v4Schema._zod?.def; - methodValue = v4Def?.value ?? v4Schema.value; - } else { - const v3Schema = methodSchema as unknown as ZodV3Internal; - const legacyDef = v3Schema._def; - methodValue = legacyDef?.value ?? v3Schema.value; - } - + const methodValue = getLiteralValue(methodSchema); if (typeof methodValue !== 'string') { throw new Error('Schema method literal must be a string'); }