Skip to content

"Type instantiation is excessively deep and possibly infinite" typescript error when importing ToolCallback type #494

Open
@matv-stripe

Description

@matv-stripe

Describe the bug
Hi! I am working on a wrapper tool around server.tool that allows you to define a tool with custom options called registerPaidTool.

I am trying to have registerPaidTool have a similar function signature to server.tool where the paramsSchema type defines the callback function:

export async function registerPaidTool<Args extends ZodRawShape>(
  mcpServer: McpServer,
  toolName: string,
  toolDescription: string,
  paramsSchema: Args,
  // @ts-ignore
  paidCallback: ToolCallback<Args>,
  options: PaidToolOptions
) {

However, the line paidCallback: ToolCallback<Args> results in "Type instantiation is excessively deep and possibly infinite.ts(2589)" (hence the @ts-ignore). I have also noticed this slows down the Typescript server in my IDE.

Full code here:
https://github.com/stripe/agent-toolkit/blob/main/typescript/src/modelcontextprotocol/register-paid-tool.ts#L22

To Reproduce
Steps to reproduce the behavior:

  1. Clone https://github.com/stripe/agent-toolkit/blob/main/typescript/src/modelcontextprotocol/register-paid-tool.ts#L22
  2. Delete the // @ts-ignore above paidCallback
  3. In the typescript/ folder, run pnpm run build

Expected behavior
I would expect this error not to show up.

I am curious if anyone has run into this problem - am I doing something incorrect here, or is ToolCallback<Args> inherently too complex for the TS compiler since it has multiple zod schemas under the hood?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions