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

Function buildDroppedMessagesSummary

server/src/utils/token-limiter.ts:331–357  ·  view source on GitHub ↗
(droppedMessages: MessageTurn[])

Source from the content-addressed store, hash-verified

329 * @returns A concise summary string, or null if nothing worth summarizing
330 */
331export function buildDroppedMessagesSummary(droppedMessages: MessageTurn[]): string | null {
332 if (droppedMessages.length < 5) return null;
333
334 const toolsUsed = new Set<string>();
335 let userMessageCount = 0;
336
337 for (const msg of droppedMessages) {
338 if (msg.toolCalls) {
339 for (const tc of msg.toolCalls) {
340 toolsUsed.add(tc.name);
341 }
342 }
343 if (msg.role === 'user') userMessageCount++;
344 }
345
346 const parts: string[] = [];
347 parts.push(`## Earlier Conversation Summary`);
348 parts.push(`${droppedMessages.length} earlier messages (${userMessageCount} from the user) were dropped from context.`);
349
350 if (toolsUsed.size > 0) {
351 parts.push(`\n**Tools used earlier:** ${Array.from(toolsUsed).join(', ')}`);
352 }
353
354 parts.push(`\nIf the user references something from earlier that you don't recall, acknowledge the context was trimmed and offer to look it up or suggest starting a new thread.`);
355
356 return parts.join('\n');
357}
358
359/**
360 * Check if a request is likely to exceed context limits.

Callers 2

processMessageMethod · 0.85
processMessageStreamMethod · 0.85

Calls 1

addMethod · 0.80

Tested by

no test coverage detected