( permissionContext: ToolPermissionContext, mcpTools: Tools, )
| 348 | * @returns Combined, deduplicated array of built-in and MCP tools |
| 349 | */ |
| 350 | export function assembleToolPool( |
| 351 | permissionContext: ToolPermissionContext, |
| 352 | mcpTools: Tools, |
| 353 | ): Tools { |
| 354 | const builtInTools = getTools(permissionContext) |
| 355 | |
| 356 | // Filter out MCP tools that are in the deny list |
| 357 | const allowedMcpTools = filterToolsByDenyRules(mcpTools, permissionContext) |
| 358 | |
| 359 | // Keep built-ins as a contiguous prefix ordered by the product tool policy. |
| 360 | // MCP tools stay name-sorted behind them for deterministic prompt cache keys. |
| 361 | // uniqBy preserves insertion order, so built-ins win on name conflict. |
| 362 | const byName = (a: Tool, b: Tool) => a.name.localeCompare(b.name) |
| 363 | return uniqBy( |
| 364 | sortToolsByPolicy(builtInTools).concat(allowedMcpTools.sort(byName)), |
| 365 | 'name', |
| 366 | ) |
| 367 | } |
| 368 | |
| 369 | /** |
| 370 | * Get all tools including both built-in tools and MCP tools. |
no test coverage detected