Repository navigation
fix(acp): keep a repo's unapproved .mcp.json servers off in claude chats - #30765
shubhamkurkure wants to merge 1 commit into
Conversation
44e3140 to
c520480
Compare
c520480 to
e574f35
Compare
e574f35 to
8ecec16
Compare
|
Hi @bolichen97 and @buluoray, when you have a moment, would you mind reviewing this PR? It covers part of #30171: opening a Claude Code chat in a cloned repository no longer starts the MCP servers that repository's Please let me know if you would like anything changed. Thank you for your time! |
Code change approver recommendation: A person should decideWhy: the decider thinks the change is probably fine but estimates a 25% chance that this change introduces a defect, above the 12% limit for approving on its own. The PR closes a real hole: on main, a claude-backend chat opened in a cloned repository starts that repository's .mcp.json server commands without asking. The writer now reads the .mcp.json files once (in _write_claude_local_settings) and lists unapproved names in disabledMcpjsonServers in the inline session settings. It falls back to strictMcpConfig when there is no gate, a name Crew cannot learn, a list over the cap, or an adapter below the floor. Verified in the code: every launch, reset and re-seed path runs the writer first; a missing or raised read leaves no gate, so the session is strict (fails closed); the child environment is merged in the launch's order (gateway env, then agent.env, then extra_env); read errors come back as None, so an unreadable file never breaks the seed; the exclusion and Side Chat sessions and the worker settings are unaffected; the rewind fork now sends the same options as the load after it; every claude_config_dir caller was updated. The spec is updated in the same change and the tests are extensive. Remaining concerns are judgement calls or unconfirmed edge cases, listed as non-blocking notes. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
8ecec16 to
f50c5a5
Compare
f50c5a5 to
8e5ebd3
Compare
8e5ebd3 to
c1ce290
Compare
c1ce290 to
57ad142
Compare
57ad142 to
93f12a8
Compare
93f12a8 to
d32fc9c
Compare
A non-interactive Claude Code session approves every pending project server by itself, so opening a Crew chat in a cloned repository started the commands in its .mcp.json files with no approval. Each session's inline settings (the flag tier) now list those servers in disabledMcpjsonServers, the key Claude Code checks before any approval, except the names approved exactly in the user settings.json of the config directory the claude child reads. Every request that starts a Claude Code process carries the list, so the user's own and plugin servers keep starting. The seed file does not carry it, so the user's own claude in that work dir still asks. A session gets strictMcpConfig, so only Crew's own servers mount, only when the list cannot keep the servers off: no read of the files finished, a name cannot be learned, the list is over 16 KiB as escaped JSON (the SDK passes it as one --settings argument), or the adapter is below the floor the inline settings rely on. A session that leaves the project setting source out never needs it. A rewind's native fork sends the same claudeCode options as the session/load after it, because the fork's process starts its servers first. One warning per session names the .mcp.json paths, never server names, and how to approve them. The .mcp.json files are read once per seed write, bounded, and parsed with loads_user_json; only a JSON syntax error means Claude Code starts nothing, and anything else Python refuses counts as unknown. The walk reads the user settings first, keeps only the names the list would carry, and goes strict as soon as their encoded size passes the cap, before it reads another file. A link is followed one hop at a time; a hop into /proc or /dev/fd, however many leading slashes spell it, a missing target or a sensitive path counts as unknown. The child home's own .mcp.json, where Crew writes its discovered servers, is skipped by resolved path unless the work dir is the home dir. An empty or relative HOME or CLAUDE_CONFIG_DIR names no home and no config dir, so it approves nothing and skips nothing; only an absent one falls back to the account's home. Part of kirodotdev#30171
d32fc9c to
704ad89
Compare
Problem / Motivation
Goal: Opening a Claude Code chat in a cloned repository no longer starts the MCP servers that repository's
.mcp.jsonfiles declare, unless the user approved them.With
agent.acp_backend = claude, an ordinary chat starts every server in every.mcp.jsonfrom the work dir up toward the filesystem root atsession/new, before the first prompt, with no approval step. Claude Code's interactive CLI asks before it starts such a server. The SDK session the adapter runs is non-interactive, and Claude Code then approves each pending project server by itself (by: "non_interactive") while theprojectsetting source is on. So a repository's own server commands run as the user the moment a Crew chat opens in it.Why it matters
Anyone who opens a Crew chat on the claude backend in a repository they did not write runs the server commands of that repository's
.mcp.jsonfiles without being asked. Crew does not send these servers, the dashboard does not show them, and no Crew gate sees them start. A session that leaves theprojecttier out (a project that owns itssettings.local.json) already keeps them off; every other chat does not.Not a goal
strictMcpConfigfor every session) is a separate design decision. This PR keeps them on, except in a session where Crew cannot name every project server or the adapter is too old to carry the list (see Backwards compatibility).settings.jsonof the child's config directory (see Backwards compatibility)..claude/settings.jsonhooks. A committedSessionStartcommand hook still runs atsession/newon this branch (verified live, below); it needs its own issue.ClaudeSharedSessionis built without the chat'sextra_env, so its gate reads approvals from the gateway's config dir while the shared process runs with the chat'sextra_env. The gate still applies there, which main does not do at all, but approvals set only throughextra_envare not followed on that path. Passingextra_envto the shared session's state is a change toharness/claude.pyand belongs in its own PR..mcp.jsonduring one launch, between Crew's read and Claude Code's own read atsession/new. The list is built from Crew's read, so a name added in that gap is not on it. Closing the gap needs Claude Code to start only servers Crew mounts (strictMcpConfigfor every session, the design decision in the first bullet), not a second read.What changed (motivation → approach → change)
Symptom: a repository's
.mcp.jsonservers start with no approval. Root cause: in a non-interactive session Claude Code approves every project server that no setting decides. The one key it checks before any approval isdisabledMcpjsonServers, which rejects by name..mcp.jsondisabledMcpjsonServersin the session's inlinesettings(not in the seed file); does not startenabledMcpjsonServers, or any server underenableAllProjectMcpServers: true, in the usersettings.jsonof the claude child's config dir.claudeor.claude/settings.local.jsonis a link,.claudeis a regular file, the exclusion is refused, or the write fails/proc/self/cwdor any hop under/proc/or/dev/fd/, a missing or sensitive target, an unreadable, oversized or non-regular file, JSON Python refuses but Claude Code reads), a list over 16 KiB, no finished read, or a listed server on an adapter below 0.84.0 or reporting no versionstrictMcpConfig, so nothing but Crew's own servers can mountsession/fork)claudeCode.optionssession/loadafter itprojecttier out (a project-ownedsettings.local.json)strictMcpConfig, so its inline settings (the project's own file) do not grow~/.mcp.json, where Crew writes its discovered serversHOMEnames no home, so nothing is skippedstrictMcpConfigsessionacp/claude_project_mcp.py(project_mcp_gate) lists the servers of every.mcp.jsonfrom the work dir to the root, along the given and the resolved path. Approvals match the exact name, which fails closed; a name the user also disabled stays listed.agent.env, thenextra_env, as the per-chat launch builds it. On Windows,CLAUDE_CONFIG_DIR,HOMEandUSERPROFILEmatch in any case; one of them spelled two ways with different values approves nothing.claude_settings_sources.claude_config_dir(environ)andclaude_home(environ)serve the gate and the four older callers. An empty or relativeCLAUDE_CONFIG_DIRor home resolves to none: Claude Code resolves it against its own cwd, the repository (claude mcp listinwreadw/rel/settings.jsonforCLAUDE_CONFIG_DIR=rel, andw/settings.jsonfor an empty one). Only an absent variable falls back to the account's home.read_claude_settings_bytesand parsed withloads_user_json; only the keys of a top-levelmcpServerscount. Onlyjson.JSONDecodeErrormeans Claude Code starts nothing; any otherValueErrororRecursionErrormeans unknown. A link is resolved one hop at a time, refusing a hop under/proc/or/dev/fd/after collapsing leading slashes. Contents are never logged._claude_project_mcp_gate, aClaudeAcpClientfield, None until a read finishes)._claude_session_metaputs the list into_meta.claudeCode.options.settingson all four requests that start a Claude Code process, on every session that keeps theprojectsetting source. The seed file does not carry it, so the user's ownclaudein that work dir still asks.strictMcpConfigis sent only when the list cannot keep the servers off: no gate, an unknown name, or the adapter belowCLAUDE_ACP_SETTING_SOURCES_MIN_VERSION(0.84.0) while a server is listed. The SDK passesoptions.settingsas one--settingsargument (Linux refuses one over 128 KiB, Windows a command line over 32,767 characters), so a list is strict instead when its escaped JSON, encoded as a JSON string once more, is over 16 KiB. That second encoding is never shorter than Windows' quoting of the argument. The walk keeps only names it would list and goes strict as soon as they pass 16 KiB, before reading another file..mcp.jsonpaths (never server names) and the remedies, which apply in every repository. A rewind's fork and load, or a re-seed of the same files, does not log it again._fork_session(client_claude_session.py) sends{**self._claude_session_meta(), "jetbrains": ...}, because adapter 0.100.0'sunstable_forkSessionstarts the fork's process before Crew'ssession/load.encode_frameturns a lone surrogate in a name into U+FFFD; Claude Code compares names after mapping every character outside[A-Za-z0-9_-]to_, so both match. Spec:claude-code-provider.mdgains a "Project.mcp.jsonservers" section;session.mdnotes the fork's options.Backwards compatibility
Breaking: a server from a
.mcp.jsonthat the user has not approved in the usersettings.jsonof the claude child's config directory no longer starts in a Crew chat on the claude backend. This is fail-closed on purpose and has these visible sides..claude/settings.local.jsonor in the workspace entry of~/.claude.json. An untrackedsettings.local.jsonis the user's own choice: this PR turns its approvals off on the branch where the exclusion is refused, and elsewhere main already leaves a project-ownedsettings.local.jsonout. Such a server stays off until the user adds its name toenabledMcpjsonServersin~/.claude/settings.json(or$CLAUDE_CONFIG_DIR/settings.json), the place Claude Code's own hint names for a lasting approval. Approvals in the managed and project tiers are not honoured either, and an approval spelled differently from the.mcp.jsonkey keeps the server off. The gateway log names the files and both remedies..mcp.jsonit cannot read, such as a crafted link or a padded file, or a list too long for one command-line argument), or whose adapter is older than 0.84.0 while a server is listed, also loses the user's own user-scope and plugin servers for that session, becausestrictMcpConfigis all-or-nothing. The gateway log names the files and the remedy.CLAUDE_CONFIG_DIRandHOME(USERPROFILEon Windows) come from the gateway's environment,agent.envin Crew's config, or the session'sextra_env, which Crew sets. No repository file sets them. If an absolute one points inside a repository, Claude Code itself reads that repository's file as the user tier (settings.jsonthere, or.claude/settings.jsonunder the home), so the gate's approvals follow what Claude Code reads, and the gate skips the.mcp.jsonin that home as the home's own file. Crew does not second-guess that choice: treating such a root as untrusted would turn off approvals that work today.CLAUDE_CONFIG_DIR, or an empty or relativeHOME(USERPROFILEon Windows) with noCLAUDE_CONFIG_DIR, now resolves to no config directory in all five callers: the gate approves nothing and skips no home file,other_sources_define_available_modelsdoes not read a user file, nor doesa_source_decides_thinking(from feat: show the claude-agent-acp surfaces the dashboard drops #37512) when the spawn environment names no config dir, so the claude launch's thinking display is withheld only by the project and managed files there, the transcript cleanup answers not done and deletes nothing, as it already did when no home resolves, and the background-call reader (claude_session_dir, from fix(acp): three handshake, provider and model registry fixes #33279) reads no subagent transcript, so the turn keeps the adapter'sincomplete_tool_callerror. Before, the older callers used a relative path against the gateway's cwd, and an empty value fell back to the gateway's own home; neither is where the claude child reads it.test/test_claude_settings_sources.py::test_empty_claude_config_dir_env_falls_back_to_homepinned that fallback; it is nowtest_empty_claude_config_dir_env_reads_no_home_file.This is on by default, with no Crew setting. On #30308 a maintainer asked that added strictness nobody asked for not be the default; there the strictness overrode a mode the user had chosen. Here the command comes from a file in a cloned repository, not from the user's choice. Claude Code's own CLI asks before it starts such a server; only the non-interactive path the adapter runs skips that question. Main already refuses a tree holding that file for Copilot:
src/kiro_crew/acp/harness/copilot.pylists.mcp.jsonin_PROJECT_CONFIG_FILES(line 294) and refuses the session because those servers "would bypass Kiro Crew's tool approval" (line 441). The user keeps their own user-scope and plugin servers, and approvals in their ownsettings.jsonare honoured; approvals stored elsewhere are not (first bullet). One line in their own<config dir>/settings.jsonbrings main's behaviour back:enableAllProjectMcpServers: true(every project server starts, as on main) or the server's name inenabledMcpjsonServers. Both apply in every repository.Writer sweep on origin/main @ c970398:
git grep -n "disabledMcpjsonServers\|enabledMcpjsonServers\|enableAllProjectMcpServers" origin/main -- src test docsfinds one other writer,test/real_adapters/harness_probe/drive.py(#30640). It writesenableAllProjectMcpServers: trueinto the probe's own throwaway home, which is the claude child's config dir there, so the gate approves every name and lists nothing, and the probe'sclaude-projectdecoy still starts as itsexpectations.jsonsays. The gate run on that layout listed nothing, and listed the decoy once that file was removed; the real-adapter lane itself did not run here. No other writer or reader;disabledMcpjsonServersis new in Crew's payload.Reader: src/kiro_crew/mcp_discovery.py:register_servers_for_cc -- chat -- writes Crew's discovered servers into ~/.mcp.json, which the gate skips by resolved path unless the work dir is the home dir, so those servers start as before (test_the_homes_own_mcp_json_is_skipped, test_the_homes_own_mcp_json_is_skipped_under_a_third_spelling)
Reader: src/kiro_crew/acp/client_claude_seed.py:_share_sibling_settings_seed -- chat -- the seed carries no disabledMcpjsonServers, so the bytes siblings compare are main's (test_a_sharing_sibling_is_strict_exactly_when_a_name_is_unknown, test/test_acp_seed_provenance_sibling_sharing.py passes)
Reader: src/kiro_crew/acp/client_claude_session.py:_exclude_foreign_local_settings -- chat|cron|subagent -- carries the payload inline as on main; the envelope adds no list there, and a list the project's own file holds passes through unchanged (test_the_exclusion_path_adds_no_list, test_an_excluded_sessions_own_list_passes_through)
Reader: src/kiro_crew/acp/claude_settings_sources.py:other_sources_define_available_models -- chat -- passes os.environ to the shared resolver; an absolute or unset CLAUDE_CONFIG_DIR and an absolute home resolve as before (test/test_claude_settings_sources.py passes)
Reader: src/kiro_crew/acp/claude_settings_sources.py:a_source_decides_thinking -- chat|cron|subagent -- passes os.environ to the shared resolver when the claude launch names no config dir; an absolute or unset CLAUDE_CONFIG_DIR and an absolute home resolve as before (test_the_thinking_check_falls_back_to_the_same_config_dir, test/test_claude_thinking_display.py passes)
Reader: src/kiro_crew/agent_sdk/claude_transcripts.py:delete_claude_session_files -- chat|subagent -- passes os.environ to the shared resolver; an absolute or unset CLAUDE_CONFIG_DIR and an absolute home resolve as before (test/test_claude_transcripts.py passes)
Reader: src/kiro_crew/agent_sdk/claude_transcripts.py:claude_session_dir -- chat|subagent -- passes os.environ to the shared resolver; an absolute or unset CLAUDE_CONFIG_DIR and an absolute home resolve as before (test/test_claude_background_incomplete_tool_calls.py passes)
Tests
test/test_claude_project_mcp_gate.py(new, 132 tests):.mcp.json, including a parent seen only through a symlinked work dir, and a walk that reaches the root; a file reached two ways is one source, and a file whose names are all approved is none;enableAllProjectMcpServersonly when it istrue, non-string entries, a normalised spelling that does not approve, a project name the user also disabled, a symlinked usersettings.json, and no config dir;CLAUDE_CONFIG_DIR, the child's home, a relative value, and a relative home, which names neither and skips no.mcp.jsonbeside it; an emptyCLAUDE_CONFIG_DIRbeside an absolute home, an empty home, and an emptyUSERPROFILEon the Windows branch, which name no config dir, approve nothing fromextra_envand skip no.mcp.jsonin the gateway's home, while absent keys fall back to the account's home; the gateway's own config dir when the session names none; the session'sextra_envover an ambient approval;agent.envunderextra_env; on Windows a name spelled two ways approves nothing and skips no home file, and one spelling names the dir; any-case matching is on only on Windows by default;mcpServers, nesting too deep for the parser, a 5,000-digit integer after, before and inside a list besidemcpServers, a BOM, an escaped duplicate key (the last wins), invalid UTF-8 bytes, and a lone surrogate, which reaches the wire frame as U+FFFD; underenableAllProjectMcpServersa name Crew cannot learn is approved;/proc/self/cwd(directly, through a linked directory, through a relative../chain to the root, and spelled//proc, with a decoy file in the test's cwd),//proc,///procand//dev/fdread as process-relative, a link to/dev/stdin, a link to an existing sysfs file read as Claude Code reads it, an oversized file, a directory and too many names; a list over the 16 KiB cap but under 64K characters (45,000 three-byte characters, or 35,000 ASCII ones) is strict and sends no inline list, so are 10 names of 500 quotes, about 10,000 bytes of JSON that Windows quotes to about 20,000 characters, and one under the cap rides inline;enableAllProjectMcpServersonly the user-disabled names are kept, and over 40 files of 2,000 names each the gate's traced peak is about 10 times one file (119 times on57505e402, which held every file's names);strictMcpConfig; each no-seed branch (linked or danglingsettings.local.json, linked.claude, a regular file.claude, refused exclusion, failed write) carries the inline list and no strict flag, is strict with only unknown names, and carries nothing without a project server; below the 0.84.0 floor a listed session is strict and one with no project server is not; the child home's own.mcp.jsonis skipped with the home spelled directly, through a link, with the work dir through that link, and with the work dir through a link the home does not use, and counts in the home dir itself; the strict and the listing notices name the files and the remedies but no server name, the read itself logs nothing, each is logged once across a fork, a load and a re-seed and again after a read that differs, a zero-tool or Side Chat session logs neither, and below the floor an unreadable file is named as the cause; a sharing sibling and a create-race loser that shares are strict exactly when a name is unknown; a raise in the read leaves the session strict and keeps nothing of the earlier read;claudeCode.optionsassession/load.test/test_rewind_native_fork.py::test_a_claude_fork_request_forks_then_loads_the_forkpinned the fork's_metaas the fork point alone. It now pins the fork point beside the sameclaudeCodeblock the load sends, which is this fix.test/test_claude_auto_memory_envelope.py(its_clienthelper, andtest_a_memory_withholding_subagent_turns_auto_memory_offfrom fix: keep withheld memory out of claude sub-agents #32293, whose client comes from the provider factory) andtest/test_acp_session_mcp_client_seam.py::TestClientSeam::test_a_side_session_without_its_deny_rules_never_startsbuilt a client that never read the project files and pinned its empty envelope. Such a client is now strict, which is this fix, so each sets the gate a launch's read of a tree without a.mcp.jsonsets (ProjectMcpGate([], False)); what they check is unchanged.The autouse fixtures patch through
_floor_monkeypatch.Round 5: the new
quoted_on_windowscase fails with the round-4 measure, andtest_the_exclusion_path_adds_no_listandtest_an_excluded_sessions_own_list_passes_throughfail with the list added on the exclusion.A mutation sweep of round 4's 24 mutants is killed by named tests in this file: a relative home kept, the cap counted in characters, in raw UTF-8 bytes or not at all, the list back in the seed, no gate not strict, the gate not reset before a read, the home skip by spelling, never or with no work-dir check, the Side Chat or zero-tool quiet dropped, either notice dedupe key without the gate, the old-adapter wording despite an unreadable file, the ambiguous Windows environment keeping the home, and earlier rounds' strict, inline, exclusion,
//procandenableAllProjectMcpServersmutants.Determinism after the last change: 10 of 10 runs at
-n0of the same three files (164 tests), and 3 of 3 at-n 4 --dist loadgroupwith the four co-tenants (275 tests). Before it: 20 of 20 runs at-n0of this file,test/test_rewind_native_fork.pyandtest/test_claude_auto_memory_envelope.py(163 tests); 10 of 10 runs at-n 4 --dist loadgroup --max-worker-restart=2withtest/test_claude_settings_sources.py,test/test_cc_permission_mode_seed.py,test/test_acp_seed_provenance_sibling_sharing.pyandtest/test_acp_client_settings_restore.pyas co-tenants (274 tests); four shuffled orders of the 163 ids (seeds 7, 1234, 99991, 20261105) all passed.test/test_flake_pattern_ratchet.pypassed. After the rebase onto fix(acp): keep Crew's tools when a claude session asks for default mode #30670, 38 test files that reference the functions this PR or fix(acp): keep Crew's tools when a claude session asks for default mode #30670 changed passed together (2,442 tests). After the rebase onto fix(acp): add an opt-in to move unrequested claude sessions out of auto #30308, the 30 test files that reference the functions this PR or fix(acp): add an opt-in to move unrequested claude sessions out of auto #30308 changed passed together (1,772 tests), once withKIROCREW_CC_PIN_INHERITED_MODEunset and once set to1.After the rebase onto
ad553518b: 30 test files passed together on the final head (2,521 passed, 1 skipped): this PR's 5, the 22 others that fix(acp): keep Crew's tools for a claude session that asks for auto beside a foreign settings file #33847, feat(connections): bridge Crew-owned OAuth per session for claude #33597, fix(session-background): kill oversized and long-parked _bg runtimes #32376, fix(pi): carry the agent spec's own MCP servers into a pi session #30188, fix: keep withheld memory out of claude sub-agents #32293 and fix(acp): exclude a foreign settings file that wins the create race #32471 added or changed beside their edits to the files this PR changes, and the 3 that referenceclaude_transcriptsorclaude_background_calls(fix(acp): three handshake, provider and model registry fixes #33279). Ondb5f8e48athe related-test runner's backend set ran 10,781 tests: 10,764 passed, 13 skipped, and 4 failed, all intest/test_codex_inner_sandbox_approval.py(test_real_codex_acp_*, which drive a real codex binary). The same 4 fail on a cleanad553518bcheckout on this host.test/test_flake_pattern_ratchet.pypassed.After the review of
db5f8e48a:test_nesting_the_parser_refuses_is_unlistedcollects at depth zero and holds the cyclic collector off for the deep parse (no_cyclic_gc_at_the_recursion_limit, as intest/test_acp_client_more_coverage_encode_refusal.py). It passed 20 of 20 runs alone at-n0, and 10 of 10 runs at-n 4 --dist loadgroupbesidetest/test_claude_settings_sources.py,test/test_cc_permission_mode_seed.py,test/test_acp_seed_provenance_sibling_sharing.pyandtest/test_acp_client_settings_restore.py(236 tests). A scratch run planted cyclic garbage whose finalizer recurses 80 frames, undergc.set_threshold(1, 1, 1). With the pure-Python JSON scanner the test without the fixture raised an unraisableRecursionError3 of 3 times, and with it passed 3 of 3. With CPython's C scanner both passed: since 3.12 the collector runs only at bytecode eval-breaker points, and the C parse runs no bytecode at depth.With the absent-or-set check reverted to a truthy one in
claude_home,test_an_empty_home_names_no_home_and_no_config_dir,test_an_empty_value_in_extra_env_approves_nothing[HOME],test_an_empty_home_skips_no_mcp_jsonandtest_on_windows_an_empty_userprofile_names_no_homefail. With it reverted inclaude_config_dir,test_an_empty_config_dir_names_none_beside_an_absolute_home,test_an_empty_value_in_extra_env_approves_nothing[CLAUDE_CONFIG_DIR]andtest_empty_claude_config_dir_env_reads_no_home_filefail.After the rebase onto
06d61fe53and the review of57505e402: 33 test files passed together on the final head (2,769 passed, 1 skipped): this PR's 5, the 25 that fix(acp): keep Crew's tools for a claude session that asks for auto beside a foreign settings file #33847, feat(connections): bridge Crew-owned OAuth per session for claude #33597, fix(session-background): kill oversized and long-parked _bg runtimes #32376, fix(pi): carry the agent spec's own MCP servers into a pi session #30188, fix: keep withheld memory out of claude sub-agents #32293, fix(acp): exclude a foreign settings file that wins the create race #32471 and feat: carry a claude crewmate worker's native-tool excludes #34475 added or changed, and the 3 that referenceclaude_transcriptsorclaude_background_calls. Everytest/test_acp_*.pyandtest/test_claude_*.pyfile passed together (8,704 passed, 16 skipped), andtest/test_flake_pattern_ratchet.pypassed. The two truthy-check reverts above fail the same 4 and 3 tests, and with the list line removed from_claude_session_meta, 21 tests intest/test_claude_project_mcp_gate.pyfail.The walk's bound: on
57505e402test_the_walk_stops_and_goes_strict_once_the_names_pass_the_capfailed (the gate read all 30 files and named them all) andtest_under_enable_all_only_user_disabled_names_are_keptfailed (a traced peak of 15.5 MB, 119 times one file). Both pass now. With the cap checked only after the walk, the first fails. With approved names counted toward the cap,test_approved_names_do_not_count_toward_the_capand the enable-all test fail. With a repeated name counted again,test_a_name_repeated_across_files_counts_oncefails. With the user's disabled names no longer overriding an approval, 3 tests fail. With every file's names held, the enable-all test fails. The six new tests passed 10 of 10 runs alone at-n0, and the file passed 5 of 5 runs at-n 4 --dist loadgroupbesidetest/test_claude_settings_sources.py,test/test_cc_permission_mode_seed.py,test/test_acp_seed_provenance_sibling_sharing.pyandtest/test_acp_client_settings_restore.py.After the rebase onto
4c530d0bd(refactor(acp): move the claude-agent-acp session code off AcpClient into ClaudeAcpClient #37484 moved the claude session code intoClaudeAcpClient), no test changed andtest/test_client_bindings.pyneeded no new digest: this PR adds no member and changes no signature. The 54 test files that reference the functions this PR changed, or that refactor(acp): move the claude-agent-acp session code off AcpClient into ClaudeAcpClient #37484, fix(acp): refuse an option-bound claude session before it spawns #37163, perf(acp): end the post-start drain at once on the claude harness #37154 or fix(acp): read a wrapped claude-agent-acp's version from its handshake #26459 added or changed (among themtest/test_client_bindings.py,test/test_claude_prepare_session.py,test/test_acp_claude_mode_pin_seam.py,test/test_acp_seed_provenance*.py,test/test_acp_session_mcp_client_seam.py,test/test_claude_below_floor_before_spawn.py,test/test_acp_post_session_new_drain.pyandtest/test_acp_refactor_facade.py), passed together (3,375 passed). Everytest/test_acp_*.pyandtest/test_claude_*.pyfile passed together (9,649 passed, 19 skipped), andtest/test_flake_pattern_ratchet.pypassed. The reverts above fail the same tests: 4 and 3 for the two truthy checks, 21 for the list line, 2 for the list on the exclusion, 1 for the cap checked after the walk, 2 for approved names counted, 1 for a repeated name counted, 3 for user-disabled names not overriding an approval, 1 for every file's names held, 2 for the round-4 measure (quoted_on_windowsamong them) and 1 for theplugin:rule. In the new homes, the fork sent without the options fails 4 tests (TestForkandtest_rewind_native_fork.py), the gate not set inClaudeAcpClient.__init__failstest_a_client_whose_files_were_never_read_is_strict, the gate not cleared before the read failstest_a_raise_before_the_gate_answers_leaves_the_session_strict, and no read in the writer fails 58.After the rebase onto
c97039886(feat: show the claude-agent-acp surfaces the dashboard drops #37512 addeda_source_decides_thinking, a fourth older caller ofclaude_config_dir, which now passesos.environlike the others),test/test_claude_settings_sources.py::test_the_thinking_check_falls_back_to_the_same_config_diris new: withCLAUDE_CONFIG_DIRabsent the home's.claude/settings.jsondecides thinking, and with it empty nothing does. It fails with aTypeErrorwith the call left asclaude_config_dir(), and its empty case fails with main's resolution there. It passed 10 of 10 runs alone at-n0, and the file's 48 tests passed in four shuffled orders (seeds 7, 1234, 99991, 20261115). The 79 test files that reference the functions this PR changed, or that refactor(acp): move the claude-agent-acp session code off AcpClient into ClaudeAcpClient #37484, fix(acp): refuse an option-bound claude session before it spawns #37163, perf(acp): end the post-start drain at once on the claude harness #37154, fix(acp): read a wrapped claude-agent-acp's version from its handshake #26459, feat: show the claude-agent-acp surfaces the dashboard drops #37512 or refactor(acp): move the goose session code off AcpClient into GooseAcpClient #37535 added or changed (among themtest/test_claude_thinking_display.py,test/test_claude_harness_notices.py,test/test_claude_raw_sdk_tasks.py,test/test_claude_zero_tools.pyandtest/test_client_bindings.py), passed together (5,048 passed). Everytest/test_acp_*.pyandtest/test_claude_*.pyfile passed together (10,095 passed, 19 skipped), andtest/test_flake_pattern_ratchet.pypassed. The revert set fails the same tests as on93f12a826; theclaude_config_dirtruthy check now fails 4, the new test among them.After the rebase onto
d5fbf0b3e(fix(crew): keep a bot's deny rules when the upgrade moves it #35011 carries a Bot's held limits aspermissions.askrules, and asstrictMcpConfigwhen they cover MCP, in the same_claude_session_meta), only the module docstring's list of fields written conflicted. The held asks and this PR'sdisabledMcpjsonServersride the sameoptions.settingson a seeded session and on a rewind's fork, and an excluded session keeps its inline settings and the asks with no list; a session whose held limits cover MCP is strict already and logs no project-server notice.test/test_mate_held_rules.py::test_a_claude_worker_asks_for_the_built_ins_a_held_limit_covers(fix(crew): keep a bot's deny rules when the upgrade moves it #35011) builds its client with no launch, so this PR's rule for files never read made it strict and it failed. Its client now carries a finished read that found no.mcp.json, as the clients intest/test_claude_auto_memory_envelope.pydo; it passed 10 of 10 runs alone at-n0, and it still fails with fix(crew): keep a bot's deny rules when the upgrade moves it #35011's held-MCPstrictMcpConfigline removed. The 113 test files that reference the functions this PR changed, or that fix(crew): keep a bot's deny rules when the upgrade moves it #35011, feat(acp): ClaudeHarness, claude-agent-acp on the shared runtime with per-session setup (not routed) #37521, feat(acp): route claude Agent-tool children per session on the shared runtime #37601, feat(acp): let claude dashboard chats share one ACP process, switch off by default #37540 or the earlier rounds' main commits added or changed (among themtest/test_mate_held_rules.py,test/test_claude_prepare_session.py,test/test_client_bindings.py,test/test_claude_shared_runtime.pyandtest/test_claude_shared_children.py), passed together (7,934 passed). Everytest/test_acp_*.pyandtest/test_claude_*.pyfile passed together (10,235 passed, 16 skipped), andtest/test_flake_pattern_ratchet.pypassed. Each revert above fails the number of tests named; no read in the writer fails 57, the same 57 as ond32fc9c83.Proof: PROVEN test/test_claude_project_mcp_gate.py::TestSession::test_names_it_cannot_list_mount_only_crews_servers, test/test_claude_project_mcp_gate.py::TestSession::test_unknown_names_on_a_branch_no_seed_reaches_are_strict[symlinked_local_settings], test/test_claude_project_mcp_gate.py::TestSession::test_unknown_names_on_a_branch_no_seed_reaches_are_strict[dangling_local_settings], test/test_claude_project_mcp_gate.py::TestSession::test_unknown_names_on_a_branch_no_seed_reaches_are_strict[symlinked_claude_dir], test/test_claude_project_mcp_gate.py::TestSession::test_unknown_names_on_a_branch_no_seed_reaches_are_strict[regular_file_claude] (head 704ad89)
Gate proof: tree b396b645d4ad; ran 24; skipped none
Manual verification
Kiro Crew's real
AcpClientdrove claude-agent-acp 0.100.0 (Node 24.20.0, Claude Code 2.1.318) tosession/new, with no prompt, on this branch's final tree. It used a scratchCLAUDE_CONFIG_DIR,KIROCREW_HOMEandKIRO_HOME, and a gateway cwd holding a decoyservers.jsonwith no servers. Each canary is a stdio server that writes a marker file when it starts: a user server in.claude.json,canary_projandcanary_approvedin the work dir's.mcp.json,canary_parentin the parent's,canary_approvednamed in the user'senabledMcpjsonServers, andcanary_wirein Crew's array._meta.claudeCode.optionssettings.disabledMcpjsonServers; the seed file holds no liste33330f8f, run in the first round), plain repository{}.claudecommitted as a linkstrictMcpConfigsettings.local.jsonand a session that requestsacceptEdits, a mode other thandefault(the exclusion is refused; run after the rebase onto #30670)strictMcpConfigsettings.local.jsonand a session that requestsdefault(since #30670 the exclusion is taken; run after the rebase)settingSources: ["user"], no list, nostrictMcpConfig.claudea link, plus a server whose name holds a lone surrogateSessionStartcommand hook.mcp.jsontwo levels higherstrictMcpConfig.mcp.json -> /proc/self/cwd/servers.jsonstrictMcpConfig.mcp.json -> //proc/self/cwd/servers.jsonstrictMcpConfig.mcp.jsonpadded with a 5,000-digit integerstrictMcpConfigsettings.local.jsonand the/proc/self/cwdlinksettingSources: ["user"], no list, nostrictMcpConfig(re-run after the last change)/proc/self/cwdlink withenableAllProjectMcpServers: truein the user'ssettings.json{}strictMcpConfig, no inline list; on the previous head (a 64K-character cap)session/newfailed withspawn E2BIGand no server startedstrictMcpConfig, no inline listHOME=h, work dir<gateway cwd>/h/repo,canary_homein<gateway cwd>/h/.mcp.jsoncanary_hometoo, which stays off; on the previous head it was skipped as the home's own file and startedOn this branch every session that lists servers logged one warning naming the
.mcp.jsonpaths and the config dir'ssettings.json; the excluded session and theenableAllProjectMcpServerssession logged none. The two long-name runs also logged the gate's "more MCP servers than Crew writes" line once per read (the seed and the re-seed after model capture). Thehookrun shows the residual named under Not a goal: a committedSessionStarthook ran atsession/newwhile the.mcp.jsonservers stayed off. Claude Code's ownclaude mcp listwas used to check how it reads a.mcp.json. A comment or a trailing comma makes it read the file as invalid and start nothing from it. It accepts a UTF-8 BOM, keeps the last of duplicate keys, accepts integers of any length, and accepts names with spaces,plugin:prefixes, lone surrogates and invalid bytes. Python'serrors="replace"decode produced the same names as Claude Code on 11 invalid UTF-8 sequences.After the last change, the plain-repository and excluded runs were repeated on the final tree. The excluded session sent no list and
canary_parentstayed off; the plain one sent[canary_parent, canary_proj]and both stayed off. After the rebase onto #30670, the two requested-mode runs were repeated on the rebased tree. Withdefaultthe session took the exclusion, sent no list and nostrictMcpConfig, mounted Crew's array, and no project server started. WithacceptEditsit sent[canary_parent, canary_proj]and both stayed off.After the review of
db5f8e48a, Claude Code 2.1.310'sclaude mcp listran in a scratchwwhose.mcp.jsonholds a servercanary, withHOMEat a scratch home. With the approval only inw/settings.json,canarywas pending withCLAUDE_CONFIG_DIRabsent and started with it set to"". With the approval only in the home's.claude/settings.json, it started with the variable absent and stayed pending with it set to""or" ". Its config root isCLAUDE_CONFIG_DIR ?? join(homedir(), ".claude"). An emptyHOMEwas not run, becausehomedir()might then fall back to the account's real home and its~/.claude.json; Node'sos.homedir()returns""for it, which would make the user tier the work dir's own.claude. Crew names no home there either way.The native fork was not run live, because a fork needs a prompted source session. The unit tests pin what it sends, and the adapter source (
unstable_forkSession→getOrCreateSession→createSessionreading_meta.claudeCode.options) is quoted above.Open questions for a maintainer:
settings.local.json, with the same git-tracked check Claude Code uses), so that users are not pushed to approvals that apply by name in every repository? That would be a follow-up, not this PR..claude/settings.jsonhook still runs a repository's command atsession/new(thehookrun). Should that be its own issue, and does it change whether this.mcp.json-only fix ships on by default?enableAllProjectMcpServers: truein the user'ssettings.jsonan acceptable off switch, or do you want a Crew setting too?strictMcpConfig. Should such a session be stopped instead, as a zero-tool session is below that floor, or doesstrictMcpConfigneed its own floor?Related Issues
Part of #30171
Still out of scope from that issue: the user's own user-scope servers and plugin servers, which the harness still mounts beside Crew's array.
#30241 (claude Bot workers, by another contributor) has landed and edits the same block in
_claude_session_meta; this branch is rebased on it. Its worker rule runs first, so a worker session is already strict and logs no project-server notice. It is not a duplicate: it changes Bot workers only and leaves #30171 to this PR.#30308 (the
KIROCREW_CC_PIN_INHERITED_MODEopt-in) has merged, and this branch is rebased on it. Only the module docstring's list of fields read conflicted; it now names both_claude_project_mcp_gateand_mcp_mount_servers. The pin runs aftersession/neworsession/loadhas sent its_meta, so it does not change which sessions getdisabledMcpjsonServersorstrictMcpConfig: a scratch run of 128 start layouts sent the sameclaudeCode.optionswith the setting off and on.This branch is rebased on
ad553518b. Only the module docstrings' field lists conflicted, inclient_class.py,client_claude_seed.pyandclient_claude_session.py; each now names this PR's fields beside #33847'sclaude_mode_pinned_noticeand #32293's_include_memory. #33279 addedclaude_session_dir, a fourth caller ofclaude_config_dir, which now passesos.environlike the other callers; without it, 8 tests intest/test_claude_background_incomplete_tool_calls.pyfail with aTypeError. #32293's new envelope test sets the gate as the_clienthelper there does (Tests). A scratch run on the rebased tree checked main's new settings paths. A session that asks forautoorbypassPermissionsbeside a project-ownedsettings.local.jsonnow takes the exclusion (#33847), so it sendssettingSources: ["user"]and no list. A create-race loser that takes the exclusion (#32471) does the same; one whose exclusion is refused sends the list, orstrictMcpConfigwhen a name is unknown. With a bridged Connection (#33597) and with a sub-agent's memory off (#32293), the session still sends the list beside theirpermissions.askrule andenvswitch. With the list line removed, the 5 cases that expect the list failed.This branch is now rebased on
06d61fe53. Onlyclient_claude_session.pyconflicted, with #34475 (a claude Bot worker whose crewmate file excludes a native tool gets a narrowedtoolsoption): the module docstring's list of fields read, and the worker block of_claude_session_meta. Both sides are kept. #34475'stoolsline runs right after the worker rule and before this PR's list, and the field list names_claude_project_mcp_gatebeside_claude_worker_builtin_tools. #34475 does not change which sessions are workers or strict, and it adds no settings key, sincetoolsis its own option. So a worker is still strict and logs no project-server notice, and its seed carries the same deny rules and no list. A scratch run on the rebased tree built a narrowed worker and an ordinary chat with an ask rule, each over a.mcp.jsonwith two unapproved servers. Each sent the same options twice. The chat sentpermissionsthendisabledMcpjsonServersinsettingsand nostrictMcpConfig; the worker sent itstools,strictMcpConfigand the list.This branch is now rebased on
4c530d0bd. #37484 moved the claude-only members offAcpClientintoClaudeAcpClient, soclient_class.py,client_start.py,client_claude_seed.pyandclient_claude_session.pyconflicted.client_class.pyandclient_start.pyare now main's. The two fields are set inClaudeAcpClient.__init__(client_claude.py); the fork's options moved with_fork_sessiontoclient_claude_session.pyand need no backend check there, since only claude forks (ACP_BACKENDS_FORK_AT_MESSAGE); the other two files conflicted only in their field lists. No hook was added, and the kiro path is main's. #37163 refuses an option-bound session below the floor before it spawns, after the writer's read but before any_metais built, so that session sends no list and logs no notice. One refused at the handshake instead (a wrapper whose version cannot be read) logs none either, because a Side Chat, zero-tool or worker session is already strict and an excluded one gets no list. #37154 shortens the drain aftersession/new, which this PR reads nothing from. #26459 changes only the pre-handshake version that the exclusion and #37163 read; the list's old-adapter rule reads the session's own handshake version on all four requests. #30062 can keep a resumed session's cwd inside its rejoined scratch tree; the walk starts from whatever work dir the session gets, as before. A scratch run on the rebased tree checked the #37163 and #26459 cases, and that a kiro client carries none of these fields and forks nothing.This branch is now rebased on
c97039886. Onlyclaude_settings_sources.pyconflicted, in its module docstring, with #37512, which addeda_source_decides_thinking: both texts are kept, and its fallback passesos.environ(Tests). Its user tier is the spawn environment'sCLAUDE_CONFIG_DIRwhen that is set and not empty, else the gateway's config dir; the gate still reads only the child config dir'ssettings.jsonand the.mcp.jsonfiles, through the same_settings_objectandread_claude_settings_bytes. #37512 also addsemitRawSDKMessagesbesideoptionsin_claude_session_meta; the list, strict and notice block and its dedupe are unchanged, and the native fork, which sends the wholeclaudeCodeblock, carries it too, as thesession/loadafter it does (claude-agent-acp 0.97.0 counts it in the session fingerprint). Its harness notices are the adapter's ownnoticeand mode updates, read inside a turn; this PR's project-server notice stays a gateway log line, so the open question on reaching the chat stands. #37535 (goose) touches none of this PR's code.Sibling sweep
Swept:
git grep -n "strictMcpConfig\|\.mcp\.json\|CLAUDE_CONFIG_DIR\|def claude_config_dir" -- src/kiro_crew/acp src/kiro_crew/agent_sdkSibling: src/kiro_crew/acp/claude_project_mcp.py -- changed here
Sibling: src/kiro_crew/acp/claude_settings_sources.py -- changed here
Sibling: src/kiro_crew/acp/client_claude.py -- changed here
Sibling: src/kiro_crew/acp/client_claude_seed.py -- changed here
Sibling: src/kiro_crew/acp/client_claude_session.py -- changed here
Sibling: src/kiro_crew/acp/harness/copilot.py -- not affected -- the Copilot harness refuses a session whose tree carries a .mcp.json
Sibling: src/kiro_crew/agent_sdk/backends_mcp.py -- not affected -- a comment on the zero-tool strictMcpConfig contract
Sibling: src/kiro_crew/agent_sdk/host_auth.py -- not affected -- names CLAUDE_CONFIG_DIR as a credential home override, not the approvals file
Sibling: src/kiro_crew/agent_sdk/native_allow_stores.py -- not affected -- locates Claude Code's native allow stores, not the approvals file
Sibling: src/kiro_crew/agent_sdk/provider_identity.py -- not affected -- a docstring naming the config dir
Sibling: src/kiro_crew/agent_sdk/tool_gate.py -- not affected -- a comment on relocated credential homes
Pattern harvest
Not generalizable: the hole is one Claude Code rule (non-interactive sessions approve pending project servers), closed at the one place Crew builds Claude's settings and on each request that creates a Claude Code process.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
This contribution is offered under the project's Apache-2.0 license. It adds or updates no third-party dependency.