xmcp
Version:
The TypeScript MCP framework
62 lines (61 loc) • 2.22 kB
TypeScript
import type { StandardSchemaWithJSON } from "@modelcontextprotocol/server";
/**
* A single field schema from either zod major. zod v3 (>= 3.24) and zod v4
* both expose `~standard.validate`; zod v4.2+ additionally exposes
* `~standard.jsonSchema`. xmcp operates on fields structurally so user
* schemas keep working regardless of which zod instance created them.
*/
export interface StandardFieldSchema {
"~standard": {
version: number;
vendor: string;
validate: (value: unknown) => {
value: unknown;
issues?: undefined;
} | {
issues: ReadonlyArray<{
message: string;
path?: ReadonlyArray<unknown>;
}>;
} | Promise<{
value: unknown;
issues?: undefined;
} | {
issues: ReadonlyArray<{
message: string;
path?: ReadonlyArray<unknown>;
}>;
}>;
jsonSchema?: {
input: (options: {
target: string;
}) => Record<string, unknown>;
output: (options: {
target: string;
}) => Record<string, unknown>;
};
};
safeParse?: (value: unknown) => {
success: false;
} | {
success: true;
data: unknown;
};
}
export declare function isStandardFieldSchema(value: unknown): value is StandardFieldSchema;
export type RawShape = Record<string, StandardFieldSchema>;
/**
* Assembles a Standard Schema object from a raw `{ field: zodSchema }` shape,
* validating and converting per field. This is what lets xmcp keep its
* `zod ^3 || ^4` peer contract with SDK v2, which registers schemas through
* the Standard Schema interface instead of zod instances: no `z.object()`
* composition happens, so fields never cross zod-instance boundaries.
*
* The returned schema exposes the raw fields as `shape` so the SDK can find
* `completable()` fields for `completion/complete`.
*/
export declare function rawShapeToStandardSchema(shape: RawShape, options?: {
strict?: boolean;
}): StandardSchemaWithJSON<Record<string, unknown>, Record<string, unknown>> & {
shape: RawShape;
};