8000 Adopting Standard Schema · Issue #164 · modelcontextprotocol/typescript-sdk · GitHub
[go: up one dir, main page]

Skip to content
Adopting Standard Schema #164
Open
Open
@harrysolovay

Description

@harrysolovay

Is your feature request related to a problem? Please describe.

This SDK seems quite coupled to zod. The creator of zod as well as the creators of other popular virtual TS type libs partnered to define the Standard Schema Spec. Given that a lot of these virtual type libs enable JSON schema generation, I see no reason for this SDK to be coupled to zod directly.

Describe the solution you'd like

Let's consider the tool method signature:

tool<Args extends ZodRawShape>(name: string, description: string, paramsSchema: Args, cb: ToolCallback<Args>): void;

This could instead be declared as the following:

tool<Args extends object>(name: string, description: string, paramsSchema: StandardSchemaV1 <Args>, cb: ToolCallback<Args>): void;

^ This isn't exactly what it would need to be, as different virtual type libraries are converted to JSON in different ways... but it's the gist. The real implementation would likely involve a wrapper function and type, similar to Hono's standard validator. Ie. users would wrap their virtual type with an adapter that simply calls whatever JSON-producing method of the virtual type (in this case, an arktype.

import { type } from "arktype"
import { schema } from "arktype-mcp"
//                     ^ hypothetical lib

const MyType = type({
  a: "string | number",
  "b?": {
    c: "'d'"
  },
  e: ["'f'", "'g'"]
})

tool(NAME, DESC, schema(MyType), (v) => {
  v satisfies {
    a: string | number;
    b: {
        c: "d";
    };
    e: ["f", "g"];
  }
})

Describe alternatives you've considered

Virtual type libraries are a critical utility for ensuring a single source of truth. But Zod is not necessarily the best choice depending on use case / preferences. I personally prefer arktype, which is more versatile for modeling nested types, custom scopes and type-safe cycles.

Additional context

^ All of these implement standard schema and can have their static types extracted via T["~standard"], where T is any virtual type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0