Description
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:
- Clone https://github.com/stripe/agent-toolkit/blob/main/typescript/src/modelcontextprotocol/register-paid-tool.ts#L22
- Delete the
// @ts-ignore
above paidCallback - In the
typescript/
folder, runpnpm 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!