feat: support Standard Schema for tool/prompt schemas by felixweinberger · Pull Request #1689 · modelcontextprotocol/typescript-sdk

@felixweinberger @mattzcarey

…ompt schemas

Replace the Zod-specific AnySchema type with StandardJSONSchemaV1 from the
Standard Schema spec for user-provided tool and prompt schemas. Enables any
schema library implementing the spec (Zod v4, Valibot, ArkType) to be used.

- New packages/core/src/util/standardSchema.ts with spec interfaces and utils
- RegisteredTool/RegisteredPrompt accept StandardJSONSchemaV1
- Tool callbacks use StandardJSONSchemaV1.InferOutput<T> for inference
- New ArkType and Valibot examples
- New integration tests for mixed schema libraries

completable() remains Zod-specific (relies on .shape introspection).

Co-authored-by: Matt Carey <mcarey@cloudflare.com>

@felixweinberger mentioned this pull request

Mar 16, 2026

7 tasks

claude[bot]

travisbreaks

claude[bot]

claude[bot]

claude[bot]

claude[bot]

claude[bot]

@felixweinberger

…w fixes

Follow-up to the Standard Schema feature. Completes the schema-agnostic
surface and addresses review findings.

Scope completion:
- Narrow registration types (inputSchema/outputSchema/argsSchema) from
  StandardJSONSchemaV1 to StandardSchemaWithJSON — the SDK needs both
  ~standard.validate and ~standard.jsonSchema, so the type should say so.
  validateStandardSchema drops to 11 lines, no branches.
- Drop resultSchema from experimental.tasks.getTaskResult() — same
  pattern #1606 used for callTool. Returns GetTaskPayloadResult.
- Delete 7 dead exports from schema.ts orphaned by the feature.
- Add fromJsonSchema(schema, validator) adapter for raw JSON Schema
  input (TypeBox, hand-written schemas). Wraps as StandardSchemaWithJSON
  using the SDK's existing AJV/cfWorker validators.

Bug fixes:
- Include issue.path in validation error messages (was dropping the
  field path, e.g. "must be a number" instead of "config.retryCount:
  must be a number").
- Unwrap optional schema in handlePromptCompletion — registration
  checked isCompletable after unwrapping, request handler didn't.
  completable(z.string(), cb).optional() registered but silently
  returned empty. Pre-existing on main.
- Null-safe isOptionalSchema so unwrapOptionalSchema(undefined) doesn't
  crash when the arg name doesn't exist in the schema shape.

Docs and tests:
- Migration guides document the removed exports and use z.object()
  consistently.
- standardSchema.test.ts cleaned to v2 request() API (no schema arg;
  auto-resolved from method name).
- Changeset + tests for fromJsonSchema.

mattzcarey

mattzcarey

This was referenced

Mar 23, 2026

This was referenced

Mar 15, 2026

This was referenced

Mar 25, 2026

This was referenced

Mar 27, 2026

This was referenced

Mar 28, 2026

This was referenced

Mar 30, 2026