MCPcopy
hub / github.com/codeaashu/claude-code / mergeAndFilterTools

Function mergeAndFilterTools

src/utils/toolPool.ts:55–79  ·  view source on GitHub ↗
(
  initialTools: Tools,
  assembled: Tools,
  mode: ToolPermissionContext['mode'],
)

Source from the content-addressed store, hash-verified

53 * @returns Merged, deduplicated, and coordinator-filtered tool array.
54 */
55export function mergeAndFilterTools(
56 initialTools: Tools,
57 assembled: Tools,
58 mode: ToolPermissionContext['mode'],
59): Tools {
60 // Merge initialTools on top - they take precedence in deduplication.
61 // initialTools may include built-in tools (from getTools() in REPL.tsx) which
62 // overlap with assembled tools. uniqBy handles this deduplication.
63 // Partition-sort for prompt-cache stability (same as assembleToolPool):
64 // built-ins must stay a contiguous prefix for the server's cache policy.
65 const [mcp, builtIn] = partition(
66 uniqBy([...initialTools, ...assembled], 'name'),
67 isMcpTool,
68 )
69 const byName = (a: Tool, b: Tool) => a.name.localeCompare(b.name)
70 const tools = [...builtIn.sort(byName), ...mcp.sort(byName)]
71
72 if (feature('COORDINATOR_MODE') && coordinatorModeModule) {
73 if (coordinatorModeModule.isCoordinatorMode()) {
74 return applyCoordinatorToolFilter(tools)
75 }
76 }
77
78 return tools
79}
80

Callers 3

computeToolsFunction · 0.85
buildAllToolsFunction · 0.85
useMergedToolsFunction · 0.85

Calls 2

featureFunction · 0.85

Tested by

no test coverage detected