useMergedTools.ts
hooks/useMergedTools.ts
45
Lines
1645
Bytes
1
Exports
5
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with tool-system. It contains 45 lines, 5 detected imports, and 1 detected exports.
Important relationships
Detected exports
useMergedTools
Keywords
toolstoolpermissioncontextinitialtoolsassembletoolpoolmcptoolsreplparamassembledusememoreact
Detected imports
react../Tool.js../tools.js../state/AppState.js../utils/toolPool.js
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
// biome-ignore-all assist/source/organizeImports: ANT-ONLY import markers must not be reordered
import { useMemo } from 'react'
import type { Tools, ToolPermissionContext } from '../Tool.js'
import { assembleToolPool } from '../tools.js'
import { useAppState } from '../state/AppState.js'
import { mergeAndFilterTools } from '../utils/toolPool.js'
/**
* React hook that assembles the full tool pool for the REPL.
*
* Uses assembleToolPool() (the shared pure function used by both REPL and runAgent)
* to combine built-in tools with MCP tools, applying deny rules and deduplication.
* Any extra initialTools are merged on top.
*
* @param initialTools - Extra tools to include (built-in + startup MCP from props).
* These are merged with the assembled pool and take precedence in deduplication.
* @param mcpTools - MCP tools discovered dynamically (from mcp state)
* @param toolPermissionContext - Permission context for filtering
*/
export function useMergedTools(
initialTools: Tools,
mcpTools: Tools,
toolPermissionContext: ToolPermissionContext,
): Tools {
let replBridgeEnabled = false
let replBridgeOutboundOnly = false
return useMemo(() => {
// assembleToolPool is the shared function that both REPL and runAgent use.
// It handles: getTools() + MCP deny-rule filtering + dedup + MCP CLI exclusion.
const assembled = assembleToolPool(toolPermissionContext, mcpTools)
return mergeAndFilterTools(
initialTools,
assembled,
toolPermissionContext.mode,
)
}, [
initialTools,
mcpTools,
toolPermissionContext,
replBridgeEnabled,
replBridgeOutboundOnly,
])
}