(
id: RequestId,
serverId: string,
params: { name: string; arguments?: Record<string, unknown> } | undefined,
executeAuthContext?: ExecuteAuthContext | null,
publicServerOwnerId?: string,
simViaHeader?: string | null,
requestSignal?: AbortSignal
)
| 678 | } |
| 679 | |
| 680 | async function handleToolsCall( |
| 681 | id: RequestId, |
| 682 | serverId: string, |
| 683 | params: { name: string; arguments?: Record<string, unknown> } | undefined, |
| 684 | executeAuthContext?: ExecuteAuthContext | null, |
| 685 | publicServerOwnerId?: string, |
| 686 | simViaHeader?: string | null, |
| 687 | requestSignal?: AbortSignal |
| 688 | ): Promise<NextResponse> { |
| 689 | let abortSignal: ManagedAbortSignal | null = null |
| 690 | try { |
| 691 | if (!params?.name) { |
| 692 | return NextResponse.json(createError(id, ErrorCode.InvalidParams, 'Tool name required'), { |
| 693 | status: 400, |
| 694 | }) |
| 695 | } |
| 696 | abortSignal = createManagedAbortSignal( |
| 697 | requestSignal ?? new AbortController().signal, |
| 698 | getMaxExecutionTimeout() |
| 699 | ) |
| 700 | const abortedBeforeToolLookup = callerAbortedJsonRpcResponse(id, abortSignal) |
| 701 | if (abortedBeforeToolLookup) return abortedBeforeToolLookup |
| 702 | |
| 703 | const matchingTools = await db |
| 704 | .select({ |
| 705 | toolName: workflowMcpTool.toolName, |
| 706 | workflowId: workflowMcpTool.workflowId, |
| 707 | }) |
| 708 | .from(workflowMcpTool) |
| 709 | .where( |
| 710 | and( |
| 711 | eq(workflowMcpTool.serverId, serverId), |
| 712 | eq(workflowMcpTool.toolName, params.name), |
| 713 | isNull(workflowMcpTool.archivedAt) |
| 714 | ) |
| 715 | ) |
| 716 | .orderBy(asc(workflowMcpTool.id)) |
| 717 | .limit(2) |
| 718 | const abortedAfterToolLookup = callerAbortedJsonRpcResponse(id, abortSignal) |
| 719 | if (abortedAfterToolLookup) return abortedAfterToolLookup |
| 720 | if (matchingTools.length > 1) { |
| 721 | return NextResponse.json( |
| 722 | createError(id, ErrorCode.InvalidRequest, `Duplicate tool name: ${params.name}`, { |
| 723 | code: 'duplicate_tool_name', |
| 724 | toolName: params.name, |
| 725 | recovery: 'Rename or remove duplicate workflow MCP tools before calling this tool', |
| 726 | }), |
| 727 | { status: 409 } |
| 728 | ) |
| 729 | } |
| 730 | const [tool] = matchingTools |
| 731 | if (!tool) { |
| 732 | return NextResponse.json( |
| 733 | createError(id, ErrorCode.InvalidParams, `Tool not found: ${params.name}`), |
| 734 | { |
| 735 | status: 404, |
| 736 | } |
| 737 | ) |
no test coverage detected