MCPcopy Create free account
hub / github.com/Noumena-Network/code / isToolSearchEnabledOptimistic

Function isToolSearchEnabledOptimistic

src/utils/toolSearch.ts:272–322  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

270let loggedOptimistic = false
271
272export function isToolSearchEnabledOptimistic(): boolean {
273 const mode = getToolSearchMode()
274 if (mode === 'standard') {
275 if (!loggedOptimistic) {
276 loggedOptimistic = true
277 logForDebugging(
278 `[ToolSearch:optimistic] mode=${mode}, ENABLE_TOOL_SEARCH=${process.env.ENABLE_TOOL_SEARCH}, result=false`,
279 )
280 }
281 return false
282 }
283
284 // tool_reference is a beta content type that third-party API gateways
285 // (ANTHROPIC_BASE_URL proxies) typically don't support. When the provider
286 // is 'firstParty' but the base URL points elsewhere, the proxy will reject
287 // tool_reference blocks with a 400. Vertex/Bedrock/Foundry are unaffected —
288 // they have their own endpoints and beta headers.
289 // upstream issue context in source history
290 //
291 // HOWEVER: some proxies DO support tool_reference (LiteLLM passthrough,
292 // Cloudflare AI Gateway, corp gateways that forward beta headers). The
293 // blanket disable breaks defer_loading for those users — all MCP tools
294 // loaded into main context instead of on-demand (gh-31936 / CC-457,
295 // likely the real cause of CC-330 "v2.1.70 defer_loading regression").
296 // This gate only applies when ENABLE_TOOL_SEARCH is unset/empty (default
297 // behavior). Setting any non-empty value — 'true', 'auto', 'auto:N' —
298 // means the user is explicitly configuring tool search and asserts their
299 // setup supports it. The falsy check (rather than === undefined) aligns
300 // with getToolSearchMode(), which also treats "" as unset.
301 if (
302 !process.env.ENABLE_TOOL_SEARCH &&
303 getAPIProvider() === 'firstParty' &&
304 !isFirstPartyNoumenaBaseUrl()
305 ) {
306 if (!loggedOptimistic) {
307 loggedOptimistic = true
308 logForDebugging(
309 `[ToolSearch:optimistic] disabled: base URL override=${getFirstPartyBaseUrlOverride() ?? '<default>'} is not a first-party Noumena host. Set ENABLE_TOOL_SEARCH=true (or auto / auto:N) if your proxy forwards tool_reference blocks.`,
310 )
311 }
312 return false
313 }
314
315 if (!loggedOptimistic) {
316 loggedOptimistic = true
317 logForDebugging(
318 `[ToolSearch:optimistic] mode=${mode}, ENABLE_TOOL_SEARCH=${process.env.ENABLE_TOOL_SEARCH}, result=true`,
319 )
320 }
321 return true
322}
323
324/**
325 * Check if ToolSearchTool is available in the provided tools list.

Callers 6

getAllBaseToolsFunction · 0.85
isEnabledFunction · 0.85
normalizeMessagesForAPIFunction · 0.85
buildSchemaNotSentHintFunction · 0.85

Calls 5

getToolSearchModeFunction · 0.85
getAPIProviderFunction · 0.85
logForDebuggingFunction · 0.70

Tested by

no test coverage detected