Skip to content

Typescript version of Quick Start example #1148

@demian85

Description

@demian85

I've been trying to compile any example provided in the Readme with no success.
Typescript is making my life miserable. I cannot decipher the types for this part of the code:

const inputSchema = { sql: z.string() }
const outputSchema = {
  rows: z.array(z.record(z.any(), z.any())),
  rowCount: z.number(),
}

type InputSchema = z.infer<typeof inputSchema>
type OutputSchema = z.infer<typeof outputSchema>

server.registerTool<InputSchema, OutputSchema>(
  'query',
  {
    title: 'SQL Query',
    description: 'Execute SQL queries on the database',
    inputSchema,
    outputSchema,
  },
  async ({ sql }) => {
      // ...
  }
)
Image

I found out about z.infer by searching for a fix, but still it doesn't work.

Can someone please explain how to fix those types?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementRequest for a new feature that's not currently supported

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions