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

Function countToolDefinitionTokens

src/utils/analyzeContext.ts:234–258  ·  view source on GitHub ↗
(
  tools: Tools,
  getToolPermissionContext: () => Promise<ToolPermissionContext>,
  agentInfo: AgentDefinitionsResult | null,
  model?: string,
)

Source from the content-addressed store, hash-verified

232}
233
234export async function countToolDefinitionTokens(
235 tools: Tools,
236 getToolPermissionContext: () => Promise<ToolPermissionContext>,
237 agentInfo: AgentDefinitionsResult | null,
238 model?: string,
239): Promise<number> {
240 const toolSchemas = await Promise.all(
241 tools.map(tool =>
242 toolToAPISchema(tool, {
243 getToolPermissionContext,
244 tools,
245 agents: agentInfo?.activeAgents ?? [],
246 model,
247 }),
248 ),
249 )
250 const result = await countTokensWithFallback([], toolSchemas)
251 if (result === null || result === 0) {
252 const toolNames = tools.map(t => t.name).join(', ')
253 logForDebugging(
254 `countToolDefinitionTokens returned ${result} for ${tools.length} tools: ${toolNames.slice(0, 100)}${toolNames.length > 100 ? '...' : ''}`,
255 )
256 }
257 return result ?? 0
258}
259
260/** Extract a human-readable name from a system prompt section's content */
261function extractSectionName(content: string): string {

Callers 5

toolSearch.tsFile · 0.85
countBuiltInToolTokensFunction · 0.85
countSlashCommandTokensFunction · 0.85
countSkillTokensFunction · 0.85
countMcpToolTokensFunction · 0.85

Calls 3

toolToAPISchemaFunction · 0.85
countTokensWithFallbackFunction · 0.85
logForDebuggingFunction · 0.85

Tested by

no test coverage detected