Repository navigation
Stop Claude metadata probes from connecting to user MCP servers - #7447
Merged
Merged
Conversation
The initialization probe and the isolated context-usage probe start short-lived Claude Code processes with user, project, and local setting sources. Each process connected to every configured MCP server and then closed while MCP discovery was still in progress. Pass strictMcpConfig to both probes. The CLI then uses only the MCP servers given in mcpServers. The initialization probe gives none. The context-usage probe keeps the bb bridge server when the thread has dynamic tools. Fixes get-bb#6655
Claude Code refuses --strict-mcp-config when an enterprise managed-mcp.json is present, so the probes skip the flag on those machines and let the managed config decide which servers load. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The async check delayed the context-usage probe past the bridge's work flush, so a new report could start after the caller expected it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
bb starts two short-lived Claude Code processes to read session metadata: the initialization probe (
plugins/provider-claude-code/src/bridge/initialization-probe.ts:41) and the isolated context-usage probe (plugins/provider-claude-code/src/bridge/context-usage-probe.ts:26). Both loadsettingSources: ["user", "project", "local"]and do not restrict MCP. So each probe connected to every user, project and plugin MCP server, and then closed about 1 s later while MCP discovery was still in progress. The context probe runs at the start of every turn, so MCP servers saw a dropped connection on every turn (#6655, report).What changed
initialization-probe.ts: addsstrictMcpConfig: true. The probe passes nomcpServers, so the CLI starts no MCP server.probeClaudeUsageshares this code path.context-usage-probe.ts: addsstrictMcpConfig: true. When the thread has dynamic tools, the bb bridge server is still passed throughmcpServers, so those tools are still loaded and counted.__tests__/probe-mcp-isolation.test.ts(new): with a mocked SDKquery, checks that both probes setstrictMcpConfigand pass no MCP server except the bb bridge.In
@anthropic-ai/[email protected],strictMcpConfigmaps to--strict-mcp-config: the CLI uses only the servers given inmcpServersand ignores.mcp.json, user settings, plugins and agent frontmatter (sdk.d.ts:2403).No wire, protocol, CLI or doc change.
Difference from the issue: the issue also suggests reading context usage from the live session or caching it. #5914 moved away from the live session because it blocked conversations, so that is not part of this PR.
How you verified
AssertionError: expected { cwd: '/tmp/probe', env: {}, ...(3) } to match object { strictMcpConfig: true }, 2 of 2 tests fail.pnpm exec turbo run lint lint:type-aware typecheck test --filter=bb-plugin-provider-claude-codepasses, 11 of 11 tasks, 31 test files, 444 tests, 0 lint warnings.oxfmt --checkpasses.count_tokensendpoint):POST /mcptwice per probe). Across 10 context-probe runs, the user MCP tool was reported with 0 tokens andisLoaded: falseat most, andtotalTokenswas 1648 every time.totalTokens1648. With dynamic tools,mcp__bb-bridge__probe_toolwas still listed.headersHelper, a real Anthropic account, and a run through the bb UI. With a real account, a fast MCP server could in theory answer beforegetContextUsageand add its tool tokens to the old number. The new number never includes user MCP tools. No such count was seen in the runs above.Fixes #6655