MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / assembleToolPool

Function assembleToolPool

source code/tools.ts:347–369  ·  view source on GitHub ↗
(
  permissionContext: ToolPermissionContext,
  mcpTools: Tools,
)

Source from the content-addressed store, hash-verified

345 * @returns Combined, deduplicated array of built-in and MCP tools
346 */
347export function assembleToolPool(
348 permissionContext: ToolPermissionContext,
349 mcpTools: Tools,
350): Tools {
351 const builtInTools = getTools(permissionContext)
352
353 // Filter out MCP tools that are in the deny list
354 const allowedMcpTools = filterToolsByDenyRules(mcpTools, permissionContext)
355
356 // Sort each partition for prompt-cache stability, keeping built-ins as a
357 // contiguous prefix. The server's claude_code_system_cache_policy places a
358 // global cache breakpoint after the last prefix-matched built-in tool; a flat
359 // sort would interleave MCP tools into built-ins and invalidate all downstream
360 // cache keys whenever an MCP tool sorts between existing built-ins. uniqBy
361 // preserves insertion order, so built-ins win on name conflict.
362 // Avoid Array.toSorted (Node 20+) — we support Node 18. builtInTools is
363 // readonly so copy-then-sort; allowedMcpTools is a fresh .filter() result.
364 const byName = (a: Tool, b: Tool) => a.name.localeCompare(b.name)
365 return uniqBy(
366 [...builtInTools].sort(byName).concat(allowedMcpTools.sort(byName)),
367 'name',
368 )
369}
370
371/**
372 * Get all tools including both built-in tools and MCP tools.

Callers 5

resumeAgentBackgroundFunction · 0.85
callFunction · 0.85
computeToolsFunction · 0.85
buildAllToolsFunction · 0.85
useMergedToolsFunction · 0.85

Calls 2

getToolsFunction · 0.85
filterToolsByDenyRulesFunction · 0.85

Tested by

no test coverage detected