Skip to content

simplify return types #119

Closed
Closed

Description

@christophsturm

Is your feature request related to a problem? Please describe.
the d.ts files are currently way too complex, for example this is one method of the client api.

    listPrompts(params?: ListPromptsRequest["params"], options?: RequestOptions): Promise<z.objectOutputType<z.objectUtil.extendShape<z.objectUtil.extendShape<{
        _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
    }, {
        nextCursor: z.ZodOptional<z.ZodString>;
    }>, {
        prompts: z.ZodArray<z.ZodObject<{
            name: z.ZodString;
            description: z.ZodOptional<z.ZodString>;
            arguments: z.ZodOptional<z.ZodArray<z.ZodObject<{
                name: z.ZodString;
                description: z.ZodOptional<z.ZodString>;
                required: z.ZodOptional<z.ZodBoolean>;
            }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
                name: z.ZodString;
                description: z.ZodOptional<z.ZodString>;
                required: z.ZodOptional<z.ZodBoolean>;
            }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
                name: z.ZodString;
                description: z.ZodOptional<z.ZodString>;
                required: z.ZodOptional<z.ZodBoolean>;
            }, z.ZodTypeAny, "passthrough">>, "many">>;
        }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
            name: z.ZodString;
            description: z.ZodOptional<z.ZodString>;
            arguments: z.ZodOptional<z.ZodArray<z.ZodObject<{
                name: z.ZodString;
                description: z.ZodOptional<z.ZodString>;
                required: z.ZodOptional<z.ZodBoolean>;
            }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
                name: z.ZodString;
                description: z.ZodOptional<z.ZodString>;
                required: z.ZodOptional<z.ZodBoolean>;
            }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
                name: z.ZodString;
                description: z.ZodOptional<z.ZodString>;
                required: z.ZodOptional<z.ZodBoolean>;
            }, z.ZodTypeAny, "passthrough">>, "many">>;
        }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
            name: z.ZodString;
            description: z.ZodOptional<z.ZodString>;
            arguments: z.ZodOptional<z.ZodArray<z.ZodObject<{
                name: z.ZodString;
                description: z.ZodOptional<z.ZodString>;
                required: z.ZodOptional<z.ZodBoolean>;
            }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
                name: z.ZodString;
                description: z.ZodOptional<z.ZodString>;
                required: z.ZodOptional<z.ZodBoolean>;
            }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
                name: z.ZodString;
                description: z.ZodOptional<z.ZodString>;
                required: z.ZodOptional<z.ZodBoolean>;
            }, z.ZodTypeAny, "passthrough">>, "many">>;
        }, z.ZodTypeAny, "passthrough">>, "many">;
    }>, z.ZodTypeAny, "passthrough">>;

Describe the solution you'd like
a very simple fix would be to just create aliases for the return types and use them:

type ListPromptsResult = z.infer<typeof ListPromptsResultSchema>;
 async listPrompts(
    params?: ListPromptsRequest["params"],
    options?: RequestOptions,
  ): Promise<ListPromptsResult> {
    return this.request(
      { method: "prompts/list", params },
      ListPromptsResultSchema,
      options,
    );
  }

Describe alternatives you've considered
a even better version IMO would be to not use zod at all for the return types, just declare typescript types, and let typescript check if they are compatible.

Activity

  1. added
    enhancement
    on Jan 12, 2025
  2. jspahrsummers commented on Jan 13, 2025

    @jspahrsummers
    Member

    There are already aliases for return types. Have you tried SDK version 1.1.1, incorporating #114? It should make this case better, more akin to just using TS types (but still using Zod under the hood).

  3. christophsturm commented on Jan 14, 2025

    @christophsturm
    Author

    I tried building the git main branch and saw the complex types in the generated d.ts file for example in dist/*/client/index.d.ts. Then I declared the return type of the method and the problem went away.

  4. punkpeye commented on Apr 20, 2025

    @punkpeye

    Related #182

    These types would be a lot more straightforward if it didn't use .passthrough().

  5. dgieselaar commented on Apr 29, 2025

    @dgieselaar

    Hey folks, inferring types from zod schemas is very expensive computationally, and seems unnecessary for a library. Ideally you just have static types - should be fairly easy to generate. I'm sure there are scripts that do this.

  6. added a commit that references this issue on May 2, 2025
  7. benjaminjkraft commented on Jun 11, 2025

    @benjaminjkraft

    These are still pretty bad, even with #114:

    • hovering on the API methods still shows hundreds of lines of zod nonsense
    • in some of our typecheck configurations the types hit TS complexity limits and collapse to any

    Would you be amenable to a PR to simply write out the types that the API exposes explicitly? They aren't that complicated.

  8. punkpeye commented on Jun 11, 2025

    @punkpeye

    Just removing passthrough would make these types 10x better.

    I ended up re-typing all types locally.

  9. benjaminjkraft commented on Jun 11, 2025

    @benjaminjkraft

    Yep, I just wrote a type locally for what I wanted -- which caused me to realize some of our code was already wrong, because, again, the types were complex enough that TS gave up!

  10. benjaminjkraft commented on Jun 11, 2025

    @benjaminjkraft

    With my good friend Claude, and a bit over twelve dollars of my employer's money to power him, I made a PR for this: #612

  11. punkpeye commented on Jul 8, 2025

    @punkpeye

    Needed a workaround because the types from the SDK itself are truly hard to work with:

    https://github.com/punkpeye/mcp-types

  12. added
    ready for work
    P1
    on Oct 24, 2025
  13. KKonstantinov commented on Nov 17, 2025

    @KKonstantinov
    Contributor

    Passthrough is now largely removed and should make this much better.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1enhancementready for work

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions