(options: BuildToolsOptions)
| 81 | * @returns BuildToolsResult with tools array and optional allowedFunctionNames |
| 82 | */ |
| 83 | export async function buildNativeToolsArrayWithRestrictions(options: BuildToolsOptions): Promise<BuildToolsResult> { |
| 84 | const { |
| 85 | provider, |
| 86 | cwd, |
| 87 | mode, |
| 88 | customModes, |
| 89 | experiments, |
| 90 | apiConfiguration, |
| 91 | disabledTools, |
| 92 | modelInfo, |
| 93 | includeAllToolsWithRestrictions, |
| 94 | } = options |
| 95 | |
| 96 | const mcpHub = provider.getMcpHub() |
| 97 | |
| 98 | // Get CodeIndexManager for feature checking. |
| 99 | const { CodeIndexManager } = await import("../../services/code-index/manager") |
| 100 | const codeIndexManager = CodeIndexManager.getInstance(provider.context, cwd) |
| 101 | |
| 102 | // Build settings object for tool filtering. |
| 103 | const filterSettings = { |
| 104 | todoListEnabled: apiConfiguration?.todoListEnabled ?? true, |
| 105 | disabledTools, |
| 106 | modelInfo, |
| 107 | } |
| 108 | |
| 109 | // Check if the model supports images for read_file tool description. |
| 110 | const supportsImages = modelInfo?.supportsImages ?? false |
| 111 | |
| 112 | // Build native tools with dynamic read_file tool based on settings. |
| 113 | const nativeTools = getNativeTools({ |
| 114 | supportsImages, |
| 115 | }) |
| 116 | |
| 117 | // Resolve mode config to get allowedMcpServers for MCP server filtering. |
| 118 | const modeConfig = getModeBySlug(mode ?? defaultModeSlug, customModes) |
| 119 | const allowedMcpServers = modeConfig?.allowedMcpServers |
| 120 | |
| 121 | // Filter native tools based on mode restrictions. The allowlist is forwarded so the |
| 122 | // access_mcp_resource availability check only considers resources from allowed servers; |
| 123 | // otherwise a restricted mode could still read resources from disallowed servers. |
| 124 | const filteredNativeTools = filterNativeToolsForMode( |
| 125 | nativeTools, |
| 126 | mode, |
| 127 | customModes, |
| 128 | experiments, |
| 129 | codeIndexManager, |
| 130 | filterSettings, |
| 131 | mcpHub, |
| 132 | allowedMcpServers, |
| 133 | ) |
| 134 | |
| 135 | // Filter MCP tools based on mode restrictions. |
| 136 | const mcpTools = getMcpServerTools(mcpHub, allowedMcpServers) |
| 137 | const filteredMcpTools = filterMcpToolsForMode(mcpTools, mode, customModes, experiments) |
| 138 | |
| 139 | // Add custom tools if they are available and the experiment is enabled. |
| 140 | let nativeCustomTools: OpenAI.Chat.ChatCompletionFunctionTool[] = [] |
no test coverage detected