Skip to content

Replace Zod with Standard Schema for validation #26

Closed
@jacksteamdev

Description

@jacksteamdev

Background

FastMCP currently uses Zod directly for schema validation. However, the Standard Schema specification has been developed as a common interface for JavaScript/TypeScript schema libraries. The creators of Zod (along with Valibot and ArkType) designed this specification to make it easier for ecosystem tools to accept user-defined type validators without needing custom adapters for each library.

Request

Please consider replacing direct Zod usage with Standard Schema in FastMCP. This would allow users to:

  1. Choose their preferred validation library (Zod, Valibot, ArkType, etc.)
  2. Benefit from the "integrate once, validate anywhere" philosophy of Standard Schema
  3. Follow best practices recommended by schema library authors

Rationale

From the Standard Schema documentation:

"The spec was designed by the creators of Zod, Valibot, and ArkType. Recent versions of these libraries already implement the spec."

Many ecosystem tools are already adopting Standard Schema, including tRPC, TanStack Form, TanStack Router, and others. This change would align FastMCP with this emerging ecosystem standard.

Implementation Notes

The change should be fairly straightforward since:

  1. Zod already implements the Standard Schema interface (in v3.24.0+)
  2. The Standard Schema interface is designed to be minimal and easy to integrate

Example

Current implementation:

server.addTool({
  name: "add",
  parameters: z.object({
    a: z.number(),
    b: z.number(),
  }),
  // ...
});

Potential Standard Schema implementation:

server.addTool({
  name: "add",
  parameters: anyStandardSchema, // Could be Zod, Valibot, ArkType, etc.
  // ...
});

Thank you for considering this request!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions