MCPcopy Index your code
hub / github.com/codeaashu/claude-code / calculateDeferredToolDescriptionChars

Function calculateDeferredToolDescriptionChars

src/utils/toolSearch.ts:340–365  ·  view source on GitHub ↗

* Calculate total deferred tool description size in characters. * Includes name, description text, and input schema to match what's actually sent to the API.

(
  tools: Tools,
  getToolPermissionContext: () => Promise<ToolPermissionContext>,
  agents: AgentDefinition[],
)

Source from the content-addressed store, hash-verified

338 * Includes name, description text, and input schema to match what's actually sent to the API.
339 */
340async function calculateDeferredToolDescriptionChars(
341 tools: Tools,
342 getToolPermissionContext: () => Promise<ToolPermissionContext>,
343 agents: AgentDefinition[],
344): Promise<number> {
345 const deferredTools = tools.filter(t => isDeferredTool(t))
346 if (deferredTools.length === 0) return 0
347
348 const sizes = await Promise.all(
349 deferredTools.map(async tool => {
350 const description = await tool.prompt({
351 getToolPermissionContext,
352 tools,
353 agents,
354 })
355 const inputSchema = tool.inputJSONSchema
356 ? jsonStringify(tool.inputJSONSchema)
357 : tool.inputSchema
358 ? jsonStringify(zodToJsonSchema(tool.inputSchema))
359 : ''
360 return tool.name.length + description.length + inputSchema.length
361 }),
362 )
363
364 return sizes.reduce((total, size) => total + size, 0)
365}
366
367/**
368 * Check if tool search (MCP tool deferral with tool_reference) is enabled for a specific request.

Callers 1

checkAutoThresholdFunction · 0.85

Calls 3

isDeferredToolFunction · 0.85
jsonStringifyFunction · 0.85
zodToJsonSchemaFunction · 0.85

Tested by

no test coverage detected