fix(config-audit): MCP token callers use 'mcp' kind (v5 F2)
Two MCP enumeration paths in readActiveMcpServers now pass kind='mcp' to estimateTokens with optional toolCount derived from def.tools array (populated when callers cache MCP discovery — Step 14 wires that up). Hook callers keep kind='item' (no schema overhead). Visible effect: every active MCP server jumps from estimatedTokens=15 to >= 500 (or higher when toolCount is known). The whats-active output and TOK hotspots now reflect actual MCP cost. Tests: assert mcpServers[].estimatedTokens >= 500 in fixture.
This commit is contained in:
parent
48d560a209
commit
ce7c42f517
2 changed files with 13 additions and 2 deletions
|
|
@ -599,13 +599,14 @@ export async function readActiveMcpServers(repoPath, claudeJsonSlice = null, plu
|
|||
|
||||
// ~/.claude.json project slice
|
||||
for (const [name, def] of Object.entries(slice.mcpServers || {})) {
|
||||
const toolCount = Array.isArray(def?.tools) ? def.tools.length : 0;
|
||||
out.push({
|
||||
name,
|
||||
source: '~/.claude.json:projects',
|
||||
command: describeMcpCommand(def),
|
||||
enabled: !disabled.has(name),
|
||||
disabledBy: disabled.has(name) ? 'disabledMcpjsonServers' : null,
|
||||
estimatedTokens: estimateTokens(0, 'item'),
|
||||
estimatedTokens: estimateTokens(0, 'mcp', { toolCount }),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -624,13 +625,14 @@ async function collectMcpFromFile(path, source, disabled, out) {
|
|||
const parsed = parseJson(content);
|
||||
if (!parsed || !parsed.mcpServers || typeof parsed.mcpServers !== 'object') return;
|
||||
for (const [name, def] of Object.entries(parsed.mcpServers)) {
|
||||
const toolCount = Array.isArray(def?.tools) ? def.tools.length : 0;
|
||||
out.push({
|
||||
name,
|
||||
source,
|
||||
command: describeMcpCommand(def),
|
||||
enabled: !disabled.has(name),
|
||||
disabledBy: disabled.has(name) ? 'disabledMcpjsonServers' : null,
|
||||
estimatedTokens: estimateTokens(0, 'item'),
|
||||
estimatedTokens: estimateTokens(0, 'mcp', { toolCount }),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -528,6 +528,15 @@ describe('readActiveMcpServers', () => {
|
|||
assert.equal(alpha.enabled, true);
|
||||
assert.equal(alpha.disabledBy, null);
|
||||
});
|
||||
|
||||
it('estimatedTokens >= 500 for every MCP server (v5 F2)', async () => {
|
||||
const servers = await readActiveMcpServers(fixture.root);
|
||||
assert.ok(servers.length > 0, 'fixture should produce MCP servers');
|
||||
for (const s of servers) {
|
||||
assert.ok(s.estimatedTokens >= 500,
|
||||
`${s.name} from ${s.source} has estimatedTokens=${s.estimatedTokens}, expected >= 500`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue