Skip to content

Stop Claude metadata probes from connecting to user MCP servers - #7447

Merged
ymichael merged 3 commits into
get-bb:mainfrom
lanjak:fix-6655-probe-mcp
Nov 16, 2026
Merged

ymichael merged 3 commits into
get-bb:mainfrom
lanjak:fix-6655-probe-mcp

Conversation

@lanjak

@lanjak lanjak commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

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 load settingSources: ["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: adds strictMcpConfig: true. The probe passes no mcpServers, so the CLI starts no MCP server. probeClaudeUsage shares this code path.
  • context-usage-probe.ts: adds strictMcpConfig: true. When the thread has dynamic tools, the bb bridge server is still passed through mcpServers, so those tools are still loaded and counted.
  • __tests__/probe-mcp-isolation.test.ts (new): with a mocked SDK query, checks that both probes set strictMcpConfig and pass no MCP server except the bb bridge.

In @anthropic-ai/[email protected], strictMcpConfig maps to --strict-mcp-config: the CLI uses only the servers given in mcpServers and 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

  • Before the fix (new test on the old probes): AssertionError: expected { cwd: '/tmp/probe', env: {}, ...(3) } to match object { strictMcpConfig: true }, 2 of 2 tests fail.
  • After the fix: pnpm exec turbo run lint lint:type-aware typecheck test --filter=bb-plugin-provider-claude-code passes, 11 of 11 tasks, 31 test files, 444 tests, 0 lint warnings. oxfmt --check passes.
  • Real SDK and bundled CLI (Linux x64, outside the repo, temporary HOME with a user-scope HTTP MCP server on loopback and a fake count_tokens endpoint):
    • Old code: both probes connected to the MCP server on every run (POST /mcp twice per probe). Across 10 context-probe runs, the user MCP tool was reported with 0 tokens and isLoaded: false at most, and totalTokens was 1648 every time.
    • New code, 3 runs each: 0 MCP requests from either probe. The probes still returned 5 models, 44 commands and totalTokens 1648. With dynamic tools, mcp__bb-bridge__probe_tool was still listed.
  • Not verified: macOS, headersHelper, a real Anthropic account, and a run through the bb UI. With a real account, a fast MCP server could in theory answer before getContextUsage and 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

AGENT GENERATED

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
ymichael and others added 2 commits November 16, 2026 13:43
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]>
@ymichael
ymichael merged commit 583b443 into get-bb:main Nov 16, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

claude-code: the context-usage and initialization probes connect to every user-scope MCP server, then abort it (every turn)

2 participants