* Executes a tool handler (either regular or task-based).
(
tool: RegisteredTool,
args: unknown,
extra: RequestHandlerExtra<ServerRequest, ServerNotification>
)
| 322 | * Executes a tool handler (either regular or task-based). |
| 323 | */ |
| 324 | private async executeToolHandler( |
| 325 | tool: RegisteredTool, |
| 326 | args: unknown, |
| 327 | extra: RequestHandlerExtra<ServerRequest, ServerNotification> |
| 328 | ): Promise<CallToolResult | CreateTaskResult> { |
| 329 | const handler = tool.handler as AnyToolHandler<ZodRawShapeCompat | undefined>; |
| 330 | const isTaskHandler = 'createTask' in handler; |
| 331 | |
| 332 | if (isTaskHandler) { |
| 333 | if (!extra.taskStore) { |
| 334 | throw new Error('No task store provided.'); |
| 335 | } |
| 336 | const taskExtra = { ...extra, taskStore: extra.taskStore }; |
| 337 | |
| 338 | if (tool.inputSchema) { |
| 339 | const typedHandler = handler as ToolTaskHandler<ZodRawShapeCompat>; |
| 340 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 341 | return await Promise.resolve(typedHandler.createTask(args as any, taskExtra)); |
| 342 | } else { |
| 343 | const typedHandler = handler as ToolTaskHandler<undefined>; |
| 344 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 345 | return await Promise.resolve((typedHandler.createTask as any)(taskExtra)); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | if (tool.inputSchema) { |
| 350 | const typedHandler = handler as ToolCallback<ZodRawShapeCompat>; |
| 351 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 352 | return await Promise.resolve(typedHandler(args as any, extra)); |
| 353 | } else { |
| 354 | const typedHandler = handler as ToolCallback<undefined>; |
| 355 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 356 | return await Promise.resolve((typedHandler as any)(extra)); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | /** |
| 361 | * Handles automatic task polling for tools with taskSupport 'optional'. |
no test coverage detected