MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / validateToolUse

Function validateToolUse

src/core/tools/validateToolUse.ts:32–63  ·  view source on GitHub ↗
(
	toolName: ToolName,
	mode: Mode,
	customModes?: ModeConfig[],
	toolRequirements?: Record<string, boolean>,
	toolParams?: Record<string, unknown>,
	experiments?: Record<string, boolean>,
	includedTools?: string[],
)

Source from the content-addressed store, hash-verified

30}
31
32export function validateToolUse(
33 toolName: ToolName,
34 mode: Mode,
35 customModes?: ModeConfig[],
36 toolRequirements?: Record<string, boolean>,
37 toolParams?: Record<string, unknown>,
38 experiments?: Record<string, boolean>,
39 includedTools?: string[],
40): void {
41 // First, check if the tool name is actually a valid/known tool
42 // This catches completely invalid tool names like "edit_file" that don't exist
43 if (!isValidToolName(toolName, experiments)) {
44 throw new Error(
45 `Unknown tool "${toolName}". This tool does not exist. Please use one of the available tools: ${validToolNames.join(", ")}.`,
46 )
47 }
48
49 // Then check if the tool is allowed for the current mode
50 if (
51 !isToolAllowedForMode(
52 toolName,
53 mode,
54 customModes ?? [],
55 toolRequirements,
56 toolParams,
57 experiments,
58 includedTools,
59 )
60 ) {
61 throw new Error(`Tool "${toolName}" is not allowed in ${mode} mode.`)
62 }
63}
64
65const EDIT_OPERATION_PARAMS = [
66 "diff",

Callers 2

presentAssistantMessageFunction · 0.90

Calls 2

isValidToolNameFunction · 0.85
isToolAllowedForModeFunction · 0.85

Tested by

no test coverage detected