Skip to content

fix(kas): exclude the mcp.json servers under KIRO_HOME too - #36145

Merged
buluoray merged 1 commit into
mainfrom
crew/slack/kas-folder-agent-kiro-home-mcp
Nov 14, 2026
Merged

buluoray merged 1 commit into
mainfrom
crew/slack/kas-folder-agent-kiro-home-mcp

Conversation

@buluoray

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: On KAS, an agent that does not opt in to mcp.json no longer gets the global MCP servers when KIRO_HOME is not ~/.kiro.

On KAS an agent that does not opt in to mcp.json should load only the servers it declares (#31533). Kiro Crew names every mcp.json server and tells KAS to leave the undeclared ones out.

Kiro Crew builds its global path as Path.home() / ".kiro" / "settings" / "mcp.json" (agent._KIRO_MCP_JSON), which does not follow KIRO_HOME. KAS reads its global file under KIRO_HOME. When the two differ, Kiro Crew never sees the servers of $KIRO_HOME/settings/mcp.json, sends no exclusion for them, and KAS starts them. A folder agent, which can never opt in, then lists tools from a server that nobody enabled for it.

Why it matters

Every Dev Fleet pod runs this way: a pod keeps the real HOME and sets KIRO_HOME to <pod home>/kiro. So does a user who sets KIRO_HOME by hand. For them the rule from #31533 does not hold for the global file, and an agent from a cloned folder reaches global servers.

Not a goal

What changed (motivation → approach → change)

Symptom: in a pod, the folder agent probe-proj (tools: ["*"], no includeMcpJson) listed tool::probejson::probe_ping from the pod's kiro/settings/mcp.json. A server in the workspace's own mcp.json was left out as it should be.

Cause: kas_settings_mcp._file_servers takes the global names from session_mcp.native_settings_sources, which reads agent._KIRO_MCP_JSON. Under KIRO_HOME that is not the file that KAS reads, so excluded_whole has no name to exclude.

Change: _file_servers now also names the servers of $KIRO_HOME/settings/mcp.json when KIRO_HOME is set and that file is not Kiro Crew's own global file (_kiro_home_servers). The order follows KAS: Kiro Crew's global file, then the KIRO_HOME file, then the workspace file.

The new read only adds names. It can add an @server exclusion or carry a server's glob disabledTools; it cannot lift an exclusion or a restriction that main applies today. I did not point agent._KIRO_MCP_JSON itself at KIRO_HOME: that constant also feeds the restrictions that the dashboard writes to ~/.kiro, and moving it would drop them under KIRO_HOME.

Security note (read against the builder-security skill): the PR adds no listener, route, bind, auth or storage change. It narrows what a KAS session loads. One choice to state: when the KIRO_HOME file exists but cannot be read, the session still starts, one notice line names the file, and its servers are not excluded. That is what main does for that file in every case today, and a session that refuses to start was ruled out.

Backwards compatibility

Compatible: with KIRO_HOME unset, or set to Kiro Crew's own ~/.kiro, the stamp is the same as on main. With KIRO_HOME set to another folder, a not-opted-in agent stops getting the servers of $KIRO_HOME/settings/mcp.json, which #31533 already meant. An agent that opts in, and an agent file on the #30712 list, keep them.

Reader: src/kiro_crew/acp/kas_settings_mcp.py:excluded_whole -- chat -- reads fileServers as before; an opted-in or listed agent still gets an empty set (test_an_opted_in_agent_keeps_it_and_gets_its_glob_disabled_tools)
Reader: src/kiro_crew/acp/kas_settings_mcp.py:without_excluded_stubs -- chat -- drops pooled stubs by the same names; a KIRO_HOME-only server has no pooled stub, so nothing more is dropped
Reader: src/kiro_crew/acp/kas_subagent_targets.py:stamp_settings_mcp -- subagent -- sub-agent targets take the same stamp and get the same added names

Tests

test/test_kas_settings_mcp_kiro_home.py (new, 8 tests):

  • a server that is only in the KIRO_HOME file is excluded;
  • an opted-in agent keeps it and gets its glob disabledTools;
  • the KIRO_HOME entry wins over Kiro Crew's global entry and loses to the workspace entry;
  • with KIRO_HOME unset only Kiro Crew's global file is read;
  • a KIRO_HOME that is Kiro Crew's own folder is read once;
  • an unreadable KIRO_HOME file adds one notice line and the stamp is still built;
  • a folder agent's KAS session, through session_extras and attach_kas_custom_agents, sends excludedTools: ["@homeonly"] with KIRO_HOME set and no exclusion without it.

Five of them fail on main; the three that pin today's behaviour pass both ways.

Proof: PROVEN test/test_kas_settings_mcp_kiro_home.py::test_a_server_only_in_the_kiro_home_file_is_excluded, test/test_kas_settings_mcp_kiro_home.py::test_the_kiro_home_entry_wins_over_crews_global_and_loses_to_the_workspace, test/test_kas_settings_mcp_kiro_home.py::test_a_folder_agents_kas_session_carries_the_exclusion[True] (head 04949b4)

Also run on the head: the 15 test files that mention this code plus test_flake_pattern_ratchet.py (1,100 passed, 2 skipped, 1 failed). The one failure is test_acp_harness_contract.py::test_a_missing_self_served_binary_names_its_install_command[copilot]; it reads a .mcp.json in this machine's home folder and fails the same way in a worktree without this change.

Manual verification

In an isolated pod on this branch (KAS, a real model turn):

  1. probejson in <pod home>/kiro/settings/mcp.json; folder agent probe-proj with tools: ["*"].
  2. A new chat on probe-proj, asked to list its tools whose name contains "probe": it answered NO-PROBE-TOOL and said that it has a shell tool. The session started normally.

Before the change the same steps listed tool::probejson::probe_ping.

The pod's frontend bundle was copied from another worktree, because npm run build fails on main until #36124 merges. This PR changes no frontend file.

Related Issues

Closes #36144

Sibling sweep

Swept: git grep -nE 'Path.home()[^#]*.kiro' -- src/kiro_crew, and git grep -n "_KIRO_MCP_JSON" -- src/kiro_crew
Sibling: src/kiro_crew/acp/kas_settings_mcp.py -- changed here -- _file_servers names the KIRO_HOME file's servers for exclusion
Sibling: src/kiro_crew/acp/session_mcp.py:1462 -- tracked in #12986 -- native_settings_sources and _global_settings read restrictions from agent._KIRO_MCP_JSON; the dashboard writes them there, so moving the read alone would drop them
Sibling: src/kiro_crew/agent.py:589 -- tracked in #12986 -- the constant itself; many readers and the test floor pin it
Sibling: src/kiro_crew/agent_materialization/mcp_sources.py:432 -- tracked in #12986 -- copies global servers into the specs Kiro Crew writes; those specs pin includeMcpJson: false, so KAS does not add its own file to them
Sibling: src/kiro_crew/dashboard/handlers/mcp_config_files.py:62 -- tracked in #12986 -- the dashboard's editor of the global file
Sibling: src/kiro_crew/mcp_discovery_server_info.py:66 -- tracked in #12986 -- names the scope of a discovered server
Sibling: src/kiro_crew/apps/bridges_mcp.py:117 -- tracked in #12986 -- an app bridge's read of the shared file
Sibling: src/kiro_crew/apps/bridges_agents.py:91 -- tracked in #12986 -- an app bridge's read of the shared file

The cli.json read for mcp.initTimeout (kas_settings_mcp._init_timeout_ms) uses the same folder; it sets a timeout only and is not changed. The Path.home() paths for skills, hooks, prompts and steering are other files and are not part of this sweep.

Pattern harvest

Rule candidate: review-prompt
Pattern: a path under ~/.kiro built from Path.home() where the engine reads the same file under KIRO_HOME

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners November 12, 2026 22:34
@buluoray
buluoray requested a review from mbriones98 November 12, 2026 22:34
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 12, 2026
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 7fe490a06aa97ca8602f229e12ebf847e35f50b6 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 7fe490a06aa97ca8602f229e12ebf847e35f50b6 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the fix is additive, scoped to KAS exclusion naming, and leaves the dashboard-owned ~/.kiro restriction path alone.

Notes

[DESIGN-REVIEWED] 7fe490a

Description read

[DESCRIPTION-READ] 810e703a7badae5ec19ecf51ec5b9b710ab98bbf5d933c65a81d57f73a239a24

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 7fe490a06aa97ca8602f229e12ebf847e35f50b6 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. The fix works at the mechanism level, and the description names the deeper cause (agent._KIRO_MCP_JSON ignores KIRO_HOME) and defers it to #12986 with a stated reason.

What this change ships

Inventory (6 items) — 6 justified

Intent: when KIRO_HOME points somewhere other than ~/.kiro, a KAS agent that has not opted in to mcp.json stops getting the global MCP servers. This is a FIX.

  1. A server named only in $KIRO_HOME/settings/mcp.json is now excluded for a KAS agent that has not opted in — justified
  2. When both global files name the same server, it keeps the glob disabledTools from both files, and whether it is muted follows the KIRO_HOME entry — justified
  3. An opted-in agent now gets the glob disabledTools of a KIRO_HOME-only server — justified
  4. If the KIRO_HOME file cannot be read, the session-start notice gets one line naming it and the session still starts — justified
  5. If Crew's own global file cannot be read or resolved, the KIRO_HOME exclusions still apply — undeclared
  6. The acp-client.md spec now describes the KIRO_HOME read — justified

[FIRST-PRINCIPLES-REVIEWED] 7fe490a

Description read

[DESCRIPTION-READ] 8cb92a46abd8687929fc97632baaf5c6bbf48a6e49c1b6b7cadfbf5a1bc9b0f2

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@buluoray
buluoray enabled auto-merge (squash) November 12, 2026 22:37
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 7fe490a06aa97ca8602f229e12ebf847e35f50b6 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 7fe490a

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 7fe490a06aa97ca8602f229e12ebf847e35f50b6 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 7fe490a06aa97ca8602f229e12ebf847e35f50b6 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 7fe490a

Verdict parsed from the review's SHA-scoped output markers for commit 7fe490a06aa97ca8602f229e12ebf847e35f50b6.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 7fe490a06aa97ca8602f229e12ebf847e35f50b6 false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 12, 2026
@buluoray
buluoray force-pushed the crew/slack/kas-folder-agent-kiro-home-mcp branch from 04949b4 to b9d0704 Compare November 13, 2026 19:27
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 13, 2026
@buluoray

Copy link
Copy Markdown
Contributor Author

span=657c0b2e43d0

fixed in b9d0704: a server that Crew's global mcp.json and $KIRO_HOME/settings/mcp.json both name now keeps the union of both files' glob disabledTools (_shared_entry), so a tool the dashboard turned off stays off on KAS; whether that server is muted follows the KIRO_HOME entry, the file KAS reads.
Tests test_a_shared_servers_globs_from_one_file_survive_the_other (only-crews, kiro-home-malformed) and test_a_mandatory_shared_server_keeps_crews_globs are red on 04949b4 ([] == ['@s/a*']) and green on b9d0704; test_kas_settings_mcp*.py 79 passed.

  • A server in both global files loses Crew's disabledTools (src/kiro_crew/acp/kas_settings_mcp.py:156)

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 13, 2026
On KAS an agent that does not opt in to mcp.json loads only the
servers it declares: Kiro Crew names every mcp.json server and tells
KAS to leave the undeclared ones out. Kiro Crew's global path is
~/.kiro/settings/mcp.json and does not follow KIRO_HOME, while KAS
reads its global file under KIRO_HOME. With KIRO_HOME set to another
folder, as in every Dev Fleet pod, the servers of that file were never
named, so a folder agent got them.

The settings stamp now also names the servers of
$KIRO_HOME/settings/mcp.json when that is another file. It is read
only to add exclusions and to carry disabledTools. A file that cannot
be read adds one notice line and the session still starts. With
KIRO_HOME unset nothing changes.

Closes #36144
@buluoray
buluoray force-pushed the crew/slack/kas-folder-agent-kiro-home-mcp branch from b9d0704 to 7fe490a Compare November 14, 2026 02:28
@buluoray

Copy link
Copy Markdown
Contributor Author

span=0a950f28cea2

fixed in 7fe490a: the _KIRO_MCP_JSON.resolve() comparison now catches OSError and RuntimeError. An unresolvable Crew path counts as a different file, so the KIRO_HOME file still goes through the guarded settings reader and the session starts. A red-first test puts a self-looping symlink at Crew's global mcp.json and checks that the KIRO_HOME exclusions and the unreadable-file notice both survive. It was the only .resolve() this PR adds.

  • Guard the global-path comparison against resolution failures (src/kiro_crew/acp/kas_settings_mcp.py:114)

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 14, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the whole diff on this head, and all checks are green.

  • This applies main's existing rule to a path it missed. On main, a KAS agent that has not opted in is told to exclude the servers of the global mcp.json. But Crew reads that file at agent._KIRO_MCP_JSON, which does not follow KIRO_HOME, while KAS reads $KIRO_HOME/settings/mcp.json. With KIRO_HOME set elsewhere, the servers only KAS's file names slipped past the exclusion. Naming them closes that gap. It adds no rule of its own, so it is not added strictness.
  • KIRO_HOME unset, or set to Crew's own folder, reads only Crew's file, exactly as on main, and both cases have a test. An opted-in agent keeps the servers and gets their disabledTools globs, as it already does for Crew's file.
  • For a server both files name, the disabledTools of both are kept and neither lifts the other's. So a tool the dashboard turned off in Crew's file stays off. Muting follows the KIRO_HOME entry, the one KAS starts the server from.
  • Failures stay non-fatal, matching main's pattern. An unreadable Kiro-home file adds one notice line and names nothing, and the session still starts. An unresolvable Crew path does not hide the Kiro-home exclusions (the looping-symlink test).
  • No regex. The spec text matches the code.

Approving. Auto-merge is already armed by its holder, so I leave it as is.

@buluoray
buluoray merged commit 19f781c into main Nov 14, 2026
97 of 98 checks passed
@buluoray
buluoray deleted the crew/slack/kas-folder-agent-kiro-home-mcp branch November 14, 2026 04:07
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Post-merge note from the review of head 7fe490a, which finished after this merged. The items below now apply to main, so a follow-up PR would fix them.

  1. src/kiro_crew/acp/kas_settings_mcp.py:160-193: the _shared_entry merge goes past the goal and changes what main stamps for shared servers.
    • Trigger: a server named in both Crew's global mcp.json and the KIRO_HOME one, for an opted-in or mandatory agent.
    • What happens: the goal needs only the KIRO_HOME server names, because excluded_whole reads just the key set of fileServers. _shared_entry and the NATIVE_SOURCE_GLOBAL branch only decide glob disabledTools and muting for names both files share. Those globs never reach the agents the goal covers. They also make the stamp narrower than main's: in your kiro-home-muted case, Crew's {"disabledTools": ["a*"]} plus a muted KIRO_HOME entry gives [], so the @s/a* exclusion that main sends is gone while the gateway still pools Crew's copy of s. That goes against the body's line that the change cannot lift a restriction main applies today.
    • Smallest fix: merge as servers = {**_kiro_home_servers(notices), **global_source.servers}, then apply the workspace update as on main. Then drop _shared_entry, the NATIVE_SOURCE_GLOBAL import and the branch at lines 163-167, plus the shared-entry tests. Crew's entry wins a shared name, so every shared-name stamp stays the same as main. Names that only KIRO_HOME has are still excluded whole and keep their globs. This also resolves the earlier finding about Crew's disabledTools being dropped. If you need the KIRO_HOME-wins mute semantics for this goal, please say why in the body instead.

Optional:

  • test_a_looping_crew_global_file_keeps_the_kiro_home_exclusions sleeps about 4 s in the settings reader's retry backoff. Stub it with monkeypatch.setattr(session_mcp, "_sleep", lambda _s: None), the same way the sibling tests do.
  • The Tests and Proof lines describe an older head (04949b4) and a test that no longer exists. Re-run the proof on the current head and update the test count.
  • test_a_kiro_home_that_is_crews_own_folder_is_read_once still passes with the same-file skip removed. Using a malformed file and asserting len(notices) == 1 would pin the skip.

buluoray added a commit that referenced this pull request Nov 14, 2026
On KAS an agent that does not opt in to mcp.json loads only the
servers it declares: Kiro Crew names every mcp.json server and tells
KAS to leave the undeclared ones out. Kiro Crew's global path is
~/.kiro/settings/mcp.json and does not follow KIRO_HOME, while KAS
reads its global file under KIRO_HOME. With KIRO_HOME set to another
folder, as in every Dev Fleet pod, the servers of that file were never
named, so a folder agent got them.

The settings stamp now also names the servers of
$KIRO_HOME/settings/mcp.json when that is another file. It is read
only to add exclusions and to carry disabledTools. A file that cannot
be read adds one notice line and the session still starts. With
KIRO_HOME unset nothing changes.

Closes #36144

(cherry picked from commit 19f781c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readiness: passed Eligible automated validation passed for the current revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KAS: a folder agent gets global MCP servers when KIRO_HOME is not ~/.kiro

3 participants