MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / ToolTree

Function ToolTree

packages/react/src/components/tool-tree.tsx:291–489  ·  view source on GitHub ↗
(props: {
  tools: readonly ToolSummary[];
  selectedToolId: string | null;
  onSelect: (toolId: string) => void;
  /** When provided, each row gets a hover-revealed action menu that
   *  applies (or clears) a user policy for that exact node. Leaf rows
   *  emit the tool's full dotted id; group rows emit `prefix.*`. */
  onSetPolicy?: (pattern: string, action: ToolPolicyAction) => void;
  onClearPolicy?: (pattern: string) => void;
  /** Maps the displayed row path into the persisted policy pattern for the
   *  flat tree. Ignored in the account-grouped view, where every row writes a
   *  pattern pinned to its own account (`integration.<owner>.<conn>.<tool>`). */
  patternForDisplay?: (displayPattern: string) => string;
  /** Sorted user-authored policies (most-precedent first). Used to
   *  decide whether a node has its own exact-pattern user rule today
   *  (so the menu can show a "Clear" option). Optional — when absent,
   *  the menu hides "Clear". */
  policies?: ReadonlyArray<{ readonly pattern: string; readonly action: ToolPolicyAction }>;
  /** When true, render top-level sections per (owner, connection) account, each
   *  badged with its owner (Personal / Workspace). The dotted-name tree renders
   *  beneath each section. The same tool name can appear under two accounts (NOT
   *  deduped). When false/unset, render one flat tree (unchanged). */
  groupByConnection?: boolean;
  /** Label shown when this tree has no tools and no active filter. */
  emptyLabel?: string;
})

Source from the content-addressed store, hash-verified

289// ---------------------------------------------------------------------------
290
291export function ToolTree(props: {
292 tools: readonly ToolSummary[];
293 selectedToolId: string | null;
294 onSelect: (toolId: string) => void;
295 /** When provided, each row gets a hover-revealed action menu that
296 * applies (or clears) a user policy for that exact node. Leaf rows
297 * emit the tool's full dotted id; group rows emit `prefix.*`. */
298 onSetPolicy?: (pattern: string, action: ToolPolicyAction) => void;
299 onClearPolicy?: (pattern: string) => void;
300 /** Maps the displayed row path into the persisted policy pattern for the
301 * flat tree. Ignored in the account-grouped view, where every row writes a
302 * pattern pinned to its own account (`integration.<owner>.<conn>.<tool>`). */
303 patternForDisplay?: (displayPattern: string) => string;
304 /** Sorted user-authored policies (most-precedent first). Used to
305 * decide whether a node has its own exact-pattern user rule today
306 * (so the menu can show a "Clear" option). Optional — when absent,
307 * the menu hides "Clear". */
308 policies?: ReadonlyArray<{ readonly pattern: string; readonly action: ToolPolicyAction }>;
309 /** When true, render top-level sections per (owner, connection) account, each
310 * badged with its owner (Personal / Workspace). The dotted-name tree renders
311 * beneath each section. The same tool name can appear under two accounts (NOT
312 * deduped). When false/unset, render one flat tree (unchanged). */
313 groupByConnection?: boolean;
314 /** Label shown when this tree has no tools and no active filter. */
315 emptyLabel?: string;
316}) {
317 const {
318 tools,
319 selectedToolId,
320 onSelect,
321 onSetPolicy,
322 onClearPolicy,
323 patternForDisplay = toPolicyPattern,
324 policies,
325 groupByConnection,
326 } = props;
327 const exactPatterns = useMemo(() => {
328 if (!policies) return new Map<string, ToolPolicyAction>();
329 const m = new Map<string, ToolPolicyAction>();
330 for (const p of policies) m.set(p.pattern, p.action);
331 return m;
332 }, [policies]);
333 const [search, setSearch] = useState("");
334 const searchRef = useRef<HTMLInputElement>(null);
335 const selectedRowRef = useRef<HTMLButtonElement>(null);
336 const ownerDisplay = useOwnerDisplay();
337
338 const terms = search.trim().toLowerCase().split(/\s+/).filter(Boolean);
339
340 const filteredTools = useMemo(() => {
341 if (terms.length === 0) return tools;
342 return tools.filter((t) => {
343 const corpus = [t.name, t.description ?? ""].join(" ").toLowerCase();
344 return terms.every((term) => corpus.includes(term));
345 });
346 }, [tools, terms]);
347
348 // Account sections (only when grouping). Each carries its already-filtered

Callers

nothing calls this directly

Calls 6

useOwnerDisplayFunction · 0.90
accountPolicyPatternFunction · 0.90
ownerLabelFunction · 0.90
buildAccountGroupsFunction · 0.85
setMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected