You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(compat): accept raw Zod shape in registerTool/registerPrompt schemas
v1 allowed passing a raw shape like `{ field: z.string() }` directly as
inputSchema/outputSchema/argsSchema. v2 expects a Standard Schema (e.g.
`z.object({...})`). This restores the v1 shorthand as a deprecated overload:
- core: add isZodRawShape() guard + normalizeRawShapeSchema() that auto-wraps
raw shapes in z.object() and emits a one-time deprecation warning via
deprecate('raw-shape', ...).
- server: convert registerTool/registerPrompt to overload sets with a
@deprecated ZodRawShape-accepting signature so v1 callers typecheck
unchanged. Implementation pipes schemas through normalizeRawShapeSchema.
- server: add ZodRawShape / LegacyToolCallback / LegacyPromptCallback
deprecated type aliases for the legacy callback inference.
The shim warns once per process and will be removed in v3.
v1-compat: `registerTool`/`registerPrompt` accept a raw Zod shape (`{ field: z.string() }`) for `inputSchema`/`outputSchema`/`argsSchema` again. The shape is auto-wrapped in `z.object()` and a one-time deprecation warning is emitted. Wrap in `z.object({...})` to silence the warning; the shim will be removed in v3.
Copy file name to clipboardExpand all lines: packages/server/src/server/mcp.ts
+69-3Lines changed: 69 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,7 @@ import type {
30
30
import{
31
31
assertCompleteRequestPrompt,
32
32
assertCompleteRequestResourceTemplate,
33
+
normalizeRawShapeSchema,
33
34
promptArgumentsFromStandardSchema,
34
35
ProtocolError,
35
36
ProtocolErrorCode,
@@ -873,6 +874,31 @@ export class McpServer {
873
874
_meta?: Record<string,unknown>;
874
875
},
875
876
cb: ToolCallback<InputArgs>
877
+
): RegisteredTool;
878
+
/** @deprecated Pass a Standard Schema (e.g. wrap your raw shape in `z.object({...})`). Raw-shape inputs are auto-wrapped at runtime. Removed in v3. */
thrownewError(`Tool ${name} is already registered`);
@@ -884,8 +910,8 @@ export class McpServer {
884
910
name,
885
911
title,
886
912
description,
887
-
inputSchema,
888
-
outputSchema,
913
+
normalizeRawShapeSchema(inputSchema),
914
+
normalizeRawShapeSchema(outputSchema),
889
915
annotations,
890
916
{taskSupport: 'forbidden'},
891
917
_meta,
@@ -928,6 +954,27 @@ export class McpServer {
928
954
_meta?: Record<string,unknown>;
929
955
},
930
956
cb: PromptCallback<Args>
957
+
): RegisteredPrompt;
958
+
/** @deprecated Pass a Standard Schema (e.g. wrap your raw shape in `z.object({...})`). Raw-shape inputs are auto-wrapped at runtime. Removed in v3. */
0 commit comments