Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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');
}
Expand Down
23 changes: 2 additions & 21 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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');
}
Expand Down
Loading