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

Function getConversationTokenLimit

server/src/utils/token-limiter.ts:92–109  ·  view source on GitHub ↗
(model?: string, toolCount?: number)

Source from the content-addressed store, hash-verified

90 * @returns Maximum tokens available for conversation history
91 */
92export function getConversationTokenLimit(model?: string, toolCount?: number): number {
93 const limit = MODEL_CONTEXT_LIMITS[model ?? 'default'] ?? MODEL_CONTEXT_LIMITS.default;
94
95 // If tool count is provided, use dynamic calculation
96 if (toolCount !== undefined) {
97 const toolTokens = estimateToolTokens(toolCount);
98 const reserved =
99 TOKEN_BUFFERS.systemPrompt +
100 toolTokens +
101 TOKEN_BUFFERS.prependedContext +
102 TOKEN_BUFFERS.responseBuffer +
103 TOKEN_BUFFERS.safetyMargin;
104 return limit - reserved;
105 }
106
107 // Fall back to default static buffer
108 return limit - RESERVED_TOKENS;
109}
110
111/**
112 * Estimate token count from text using a character-based heuristic.

Callers 4

processMessageMethod · 0.85
processMessageStreamMethod · 0.85

Calls 1

estimateToolTokensFunction · 0.85

Tested by

no test coverage detected