← reports

#6022 · MCP configuration changes stay outside resident sessions

BugMedium priorityMedium effortprovidersprovider-claude-codepartial-reproGitHub issue

2026-10-21 · trusted base b143a22860944a96bf183605dfb0ffe58b1de283

Verdict: PARTIALLY REPRODUCED · Root-cause confidence: medium

1. TL;DR

A persistent Claude Code SDK session did not discover a newly persisted user MCP server during the observation window. A second session immediately connected to the same local server and discovered its ping tool, ruling out a broken server or configuration. Importantly, calling the SDK's existing reconnectMcpServer also loaded the new server into the original process: restarting the entire application is not a technical requirement of the provider. BB retains resident sessions, filters the native MCP command out of its catalog, and exposes no equivalent reconnect path. This verifies the configuration-refresh gap, not the OAuth claim or a complete macOS BB UI reproduction.

2. Claims vs findings

ClaimStatusEvidence
External user configuration changes are not picked up automatically.Verified, boundedTwo real SDK/CLI runs: configuration remains on disk, but resident MCP status stays empty after 1.5 seconds. No assertion about arbitrarily long waits.
The new server and tools are available to newly constructed sessions.VerifiedBoth fresh positive controls connect and report ping, without model API calls.
BB provides a native MCP refresh trigger.Absent in inspected sourceMCP command is filtered; bridge dispatch and SDK wrapper expose no MCP refresh/reconnect method or config watcher.
The provider itself cannot load a newly added server without restarting.Refuted on tested versionSDK reconnect succeeds and the original process reports connected with ping.
Only a full application quit works, stopping other sessions.UnverifiedNo desktop app or unrelated sessions used. Other construction-triggered per-thread replacements exist in source but were not tested as workarounds.
OAuth changes and project-scope configuration behave identically.UnverifiedNo credentials, OAuth endpoints, or project MCP approval state used.

3. Environment

4. Minimal reproduction

  1. Fetch trusted main and create two detached checkouts at the recorded commit. In each run pnpm install --frozen-lockfile --prefer-offline.
  2. Save repro.mjs outside the checkouts. It resolves existing SDK/MCP dependencies through the selected checkout. Its executable path must match your installed Claude Code binary. No new dependency is installed.
  3. Execute with an empty inherited environment:
    env -i PATH="$PATH" HOME="$PWD" node /absolute/path/repro.mjs /absolute/path/base
    env -i PATH="$PATH" HOME="$PWD" node /absolute/path/repro.mjs /absolute/path/verify
  4. The script starts an empty resident session, lets startup settle, merges a local server into synthetic user config, and checks after 1.5 seconds. It checks persisted config, explicitly reconnects the existing session, and constructs a fresh positive-control session.

Expected under an automatic-refresh policy: the resident session reports local-probe connected before explicit reconnect. Actual: empty status; the final assertion deliberately exits 1. Both positive controls succeed. The assertion isolates the automatic-refresh alternative, not a currently documented BB promise.

initial: []
after config write: []
persisted servers: ["local-probe"]
reconnect: succeeded
fresh session: [{"name":"local-probe","status":"connected","tools":["ping"]}]
original session: [{"name":"local-probe","status":"connected","tools":["ping"]}]
node:internal/modules/run_main:123
    triggerUncaughtException(
    ^

AssertionError [ERR_ASSERTION]: automatic-refresh regression: running session did not discover the new server before an explicit SDK reconnect
    at file://<work>/repro.mjs:91:3
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '==',
  diff: 'simple'
}

Node.js v22.19.0
Complete executable reproduction
import assert from "node:assert/strict";
import { mkdtemp, mkdir, readFile, writeFile, rm } from "node:fs/promises";
import { createRequire } from "node:module";
import { tmpdir } from "node:os";
import { resolve, join } from "node:path";
import { pathToFileURL } from "node:url";

const checkout = resolve(process.argv[2]);
const require = createRequire(join(checkout, "plugins/provider-claude-code/package.json"));
const { query } = await import(pathToFileURL(require.resolve("@anthropic-ai/claude-agent-sdk")));
const scratch = await mkdtemp(join(tmpdir(), "mcp-6022-"));
const home = join(scratch, "home");
const project = join(scratch, "project");
const configDir = join(home, ".claude");
await mkdir(configDir, { recursive: true });
await mkdir(project);
const serverPath = join(scratch, "server.mjs");
await writeFile(serverPath, `
import { McpServer } from ${JSON.stringify(pathToFileURL(require.resolve("@modelcontextprotocol/sdk/server/mcp.js")).href)};
import { StdioServerTransport } from ${JSON.stringify(pathToFileURL(require.resolve("@modelcontextprotocol/sdk/server/stdio.js")).href)};
const server = new McpServer({ name: "local-probe", version: "1.0.0" });
server.registerTool("ping", { description: "Local probe", inputSchema: {} }, async () => ({ content: [{ type: "text", text: "pong" }] }));
await server.connect(new StdioServerTransport());
`);
const configPath = join(configDir, ".claude.json");
await writeFile(configPath, JSON.stringify({ hasCompletedOnboarding: true, mcpServers: {} }));
const env = {
  HOME: home,
  CLAUDE_CONFIG_DIR: configDir,
  PATH: process.env.PATH,
  TMPDIR: scratch,
  LANG: "C.UTF-8",
  DISABLE_AUTOUPDATER: "1",
  CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1",
};
const sessions = [];
function start() {
  const end = new AbortController();
  async function* prompt() {
    await new Promise((resolvePrompt) => end.signal.addEventListener("abort", resolvePrompt, { once: true }));
  }
  const session = query({
    prompt: prompt(),
    options: {
      cwd: project,
      env,
      pathToClaudeCodeExecutable: "/usr/local/bin/claude",
      settingSources: ["user", "project", "local"],
      persistSession: false,
    },
  });
  sessions.push({ session, end });
  return session;
}
function names(statuses) {
  return statuses.map(({ name, status, tools }) => ({ name, status, tools: tools?.map(({ name: toolName }) => toolName) }));
}
try {
  const resident = start();
  await resident.initializationResult();
  console.log("initial:", JSON.stringify(names(await resident.mcpServerStatus())));
  await new Promise((resolveDelay) => setTimeout(resolveDelay, 2500));
  const persisted = JSON.parse(await readFile(configPath, "utf8"));
  const config = { ...persisted, mcpServers: { "local-probe": { type: "stdio", command: process.execPath, args: [serverPath] } } };
  await writeFile(configPath, JSON.stringify(config));
  await new Promise((resolveDelay) => setTimeout(resolveDelay, 1500));
  const afterWrite = await resident.mcpServerStatus();
  console.log("after config write:", JSON.stringify(names(afterWrite)));
  const onDisk = JSON.parse(await readFile(configPath, "utf8"));
  console.log("persisted servers:", JSON.stringify(Object.keys(onDisk.mcpServers ?? {})));
  assert(onDisk.mcpServers?.["local-probe"], "positive control: server configuration remains persisted");
  try {
    await resident.reconnectMcpServer("local-probe");
    console.log("reconnect: succeeded");
  } catch (error) {
    console.log("reconnect:", error.message);
  }
  const fresh = start();
  await fresh.initializationResult();
  let freshStatus = [];
  for (let attempt = 0; attempt < 50; attempt += 1) {
    freshStatus = await fresh.mcpServerStatus();
    if (freshStatus.some(({ name, status }) => name === "local-probe" && status === "connected")) break;
    await new Promise((resolveDelay) => setTimeout(resolveDelay, 200));
  }
  console.log("fresh session:", JSON.stringify(names(freshStatus)));
  assert(freshStatus.some(({ name, status }) => name === "local-probe" && status === "connected"), "positive control: fresh session connects to the new local MCP server");
  const residentStatus = await resident.mcpServerStatus();
  console.log("original session:", JSON.stringify(names(residentStatus)));
  assert(residentStatus.some(({ name, status }) => name === "local-probe" && status === "connected"), "positive control: SDK reconnect refreshes the existing process");
  assert(afterWrite.some(({ name, status }) => name === "local-probe" && status === "connected"), "automatic-refresh regression: running session did not discover the new server before an explicit SDK reconnect");
} finally {
  for (const { session, end } of sessions) {
    end.abort();
    session.close();
  }
  await rm(scratch, { recursive: true, force: true });
}

5. Root cause

plugins/provider-claude-code/src/bridge/sdk-session.ts:248 constructs the SDK query with user/project/local sources. This wrapper has no MCP refresh operation. The experiment shows that a fresh query loads the new config, while the existing query does not automatically refresh in the observed interval.

plugins/provider-claude-code/src/bridge/bridge.ts:1450 returns the resident session unless its stream ended or BB queued a restart. plugins/provider-claude-code/src/bridge/bridge.ts:2397 also keeps a same-provider session when construction settings match. External MCP edits do not enter that comparison.

plugins/provider-claude-code/src/bridge/provider-commands.ts:30 filters mcp through HIDDEN_COMMANDS. plugins/provider-claude-code/src/bridge/bridge.ts:2209 dispatches bridge requests without an MCP refresh action. Source inspection finds no provider caller of reconnectMcpServer or setMcpServers.

The deeper gap is a product refresh lifecycle and user trigger, not inability of the SDK to attach a newly added server. The successful live reconnect means an unconditional restart is not justified. Wholesale replacement of dynamic MCP servers could also disrupt BB's own bridge server.

6. Proposed fix and safety decision

Define a per-thread refresh action, or explicitly choose an automatic file/state observation policy. For an explicit action, expose provider reconnect through the supported control path with visible status/errors and matching UI, SDK, and CLI access. Preserve scopes, approvals, bridge tools, and in-flight turns. Test additions, reauthentication, deletion, failed reconnect, and unaffected sibling sessions.

No fix PR: the full report is only partially reproduced. A safe implementation needs a product/API contract and likely server/daemon wire work, outside the no-protocol-change, one-subsystem simple-fix gate. No production patch or fix branch was made.

7. Related issues and PRs

Repository metadata lists #5843 in the resident-session family. This reproduction uses native user-configured MCP rather than plugin bridge tools and does not establish a duplicate. Cross-reference metadata and an open-PR search for #6022 found no linked open PR. No PR branch or diff was executed.

8. Verification

The same agent repeated the exact script in a second clean checkout at the recorded base with separately installed frozen dependencies and a fresh synthetic home/project/temp directory. Command: env -i PATH="$PATH" HOME="$PWD" node /absolute/path/repro.mjs /absolute/path/verify. Exit 1 at the same intended assertion; persisted config, fresh connection, and original-process reconnect passed. This is a second clean repetition, not independent verification.

Report correction: an exploratory run overwrote synthetic startup metadata while the CLI was still updating config; its positive control failed and it was discarded. The final script waits for startup, merges existing synthetic config, and asserts persistence. Both final runs agree. The earlier theory that live provider reconnect cannot load a new server is rejected.

initial: []
after config write: []
persisted servers: ["local-probe"]
reconnect: succeeded
fresh session: [{"name":"local-probe","status":"connected","tools":["ping"]}]
original session: [{"name":"local-probe","status":"connected","tools":["ping"]}]
node:internal/modules/run_main:123
    triggerUncaughtException(
    ^

AssertionError [ERR_ASSERTION]: automatic-refresh regression: running session did not discover the new server before an explicit SDK reconnect
    at file://<work>/repro.mjs:91:3
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '==',
  diff: 'simple'
}

Node.js v22.19.0

9. Appendix

> AGENT GENERATED