feat(config-audit): add 'mcp' kind to estimateTokens (v5 F2)

Differentiate MCP servers from generic 'item' (flat 15) — they actually
cost 500+ tokens per turn for protocol metadata and tool schemas.

estimateTokens(bytes, 'mcp', {toolCount}) returns max of:
- 500 token floor (base overhead)
- ceil(bytes / 3.5) (json-rate when bytes known)
- 500 + toolCount * 200 (when tool count is detected; Step 14 wires this)

Caller-side migration in next commit (Step 5).

Tests: +4 cases for mcp kind.
This commit is contained in:
Kjell Tore Guttormsen 2026-05-01 06:21:30 +02:00
commit 48d560a209
2 changed files with 42 additions and 2 deletions

View file

@ -165,6 +165,31 @@ describe('estimateTokens', () => {
assert.equal(estimateTokens(-1, 'markdown'), 0);
assert.equal(estimateTokens(NaN, 'markdown'), 0);
});
// v5 F2: differentiated MCP estimate
it('mcp: 0 bytes → at least 500 (base overhead floor)', () => {
assert.ok(estimateTokens(0, 'mcp') >= 500,
`expected >= 500, got ${estimateTokens(0, 'mcp')}`);
});
it('mcp: with toolCount: 10 → at least 2000', () => {
assert.ok(estimateTokens(0, 'mcp', { toolCount: 10 }) >= 2000,
`expected >= 2000, got ${estimateTokens(0, 'mcp', { toolCount: 10 })}`);
});
it('mcp: ratio mcp/item ≥ 30 for 10-tool server', () => {
const mcp = estimateTokens(0, 'mcp', { toolCount: 10 });
const item = estimateTokens(0, 'item');
assert.ok(mcp / item >= 30,
`expected ratio >= 30, got mcp=${mcp} item=${item} ratio=${mcp / item}`);
});
it('mcp: with bytes uses json-rate floor', () => {
// 700 bytes JSON ≈ 200 tokens, but mcp keeps 500 floor
assert.equal(estimateTokens(700, 'mcp'), 500);
// 3500 bytes JSON = 1000 tokens, exceeds floor
assert.equal(estimateTokens(3500, 'mcp'), 1000);
});
});
// ─────────────────────────────────────────────────────────────────────────