Skip to content

feat: support Standard Schema for tool/prompt schemas - #1689

Merged
felixweinberger merged 2 commits into
mainfrom
fweinberger/standard-schema
Mar 23, 2026
Merged

felixweinberger merged 2 commits into
mainfrom
fweinberger/standard-schema

Conversation

@felixweinberger

Copy link
Copy Markdown
Contributor

Supersedes #1473 — rebased, with follow-up fixes from review.

Replace the Zod-specific AnySchema type with StandardSchemaWithJSON from the Standard Schema spec for tool and prompt schemas. Any library implementing both ~standard.validate and ~standard.jsonSchema works — Zod v4, ArkType, Valibot.

Motivation and Context

The SDK was tightly coupled to Zod for user-provided schemas. This makes it library-agnostic: registerTool / registerPrompt now accept any schema that can both validate incoming arguments and emit JSON Schema for tools/list.

Zod v4 schemas work unchanged — Zod v4 implements the spec natively.

// ArkType
import { type } from 'arktype';
server.registerTool('greet', { inputSchema: type({ name: 'string' }) }, handler);

// Valibot
import * as v from 'valibot';
import { toStandardJsonSchema } from '@valibot/to-json-schema';
server.registerTool('greet', { inputSchema: toStandardJsonSchema(v.object({ name: v.string() })) }, handler);

How Has This Been Tested?

  • All existing tests pass (406)
  • New integration tests for ArkType and Valibot: registration, validation (happy + error paths), mixed libraries in one server, error message quality, type inference
  • Examples build and typecheck

Breaking Changes

  • inputSchema / outputSchema / argsSchema now typed StandardSchemaWithJSON instead of Zod AnySchema. Zod v4 schemas satisfy this without changes.
  • experimental.tasks.getTaskResult() no longer accepts a resultSchema parameter (returns GetTaskPayloadResult; cast at call site).
  • Removed unused exports from @modelcontextprotocol/core: SchemaInput, schemaToJson, parseSchemaAsync, getSchemaShape, getSchemaDescription, isOptionalSchema, unwrapOptionalSchema.
  • completable() remains Zod-specific (relies on .shape introspection).

Types of changes

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the MCP Documentation
  • My code follows the repository style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Changes on top of #1473:

  • Narrowed the registration type from StandardJSONSchemaV1 (JSON Schema only) to StandardSchemaWithJSON (both validate + JSON Schema) — the SDK needs both, so the type should say so. This let validateStandardSchema drop its fallback branches.
  • Dropped resultSchema from experimental.tasks.getTaskResult() — consistent with v2 refactor!: remove Zod schema parameter from public-facing APIs #1606 removing user-supplied Zod schemas for response parsing.
  • Cleaned up exports that the new implementation orphaned.

Co-authored with @mattzcarey.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to pass in JSON schema on McpServer Decouple from Zod, allow any validator (bring your own)

4 participants