( workflowId: string, requestId: string, tx?: DbOrTx, throwOnError = false )
| 328 | * transaction owner notifies after commit using the returned server ids. |
| 329 | */ |
| 330 | export async function removeMcpToolsForWorkflow( |
| 331 | workflowId: string, |
| 332 | requestId: string, |
| 333 | tx?: DbOrTx, |
| 334 | throwOnError = false |
| 335 | ): Promise<Array<{ serverId: string }>> { |
| 336 | if (!tx) { |
| 337 | const tools = await db.transaction((transaction) => |
| 338 | removeMcpToolsForWorkflow(workflowId, requestId, transaction, throwOnError) |
| 339 | ) |
| 340 | notifyMcpToolServers(tools) |
| 341 | return tools |
| 342 | } |
| 343 | |
| 344 | try { |
| 345 | const tools = await collectWorkflowMcpToolServerIds(tx, workflowId) |
| 346 | |
| 347 | if (tools.length === 0) return [] |
| 348 | |
| 349 | for (const { serverId } of tools) { |
| 350 | await acquireWorkflowMcpServerLock(tx, serverId) |
| 351 | } |
| 352 | |
| 353 | await tx.delete(workflowMcpTool).where(eq(workflowMcpTool.workflowId, workflowId)) |
| 354 | logger.info(`[${requestId}] Removed MCP tools for workflow: ${workflowId}`) |
| 355 | |
| 356 | return tools |
| 357 | } catch (error) { |
| 358 | logger.error(`[${requestId}] Error removing MCP tools:`, error) |
| 359 | if (throwOnError) throw error |
| 360 | return [] |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | /** |
| 365 | * Publish pubsub events for each unique server affected by a tool change. |
no test coverage detected