Skip to content

simplify return types #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
christophsturm opened this issue Jan 12, 2025 · 4 comments
Open

simplify return types #119

christophsturm opened this issue Jan 12, 2025 · 4 comments
Labels
enhancement New feature or request

Comments

@christophsturm
Copy link

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.

@christophsturm christophsturm added the enhancement New feature or request label Jan 12, 2025
@jspahrsummers
Copy link
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).

@christophsturm
Copy link
Author

christophsturm commented Jan 14, 2025

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.

@punkpeye
Copy link

Related #182

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

@dgieselaar
Copy link

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.

Pizzaface pushed a commit to RewstApp/mcp-inspector that referenced this issue May 2, 2025
…/ashwin/font

feat: use monospace font for all input fields in sidebar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants