MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / estimateTokens

Function estimateTokens

server/src/utils/token-limiter.ts:122–127  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

120 * Use Anthropic's API for precise counts when needed.
121 */
122export function estimateTokens(text: string): number {
123 if (!text) return 0;
124 // Conservative estimate: ~3.5 characters per token
125 // This slightly overestimates which is safer than underestimating
126 return Math.ceil(text.length / 3.5);
127}
128
129/**
130 * Message turn structure (matches prompts.ts)

Callers 2

trimConversationHistoryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected