feat(kas): keep remote MCP sign-ins across sessions by default

Merged
BU
18d ago
+322-51

Problem / Motivation

Goal: On the kas backend, a remote MCP server's OAuth sign-in (Atlassian, Notion, Figma) lasts across new sessions, subagents, crons and restarts without the user first finding a setting, while a broken config or a stored opt-out keeps sign-ins in memory.

An install that never chose a backend now runs KAS. There, agent.kas_persist_mcp_sign_in ships false, so each new KAS process holds its sign-ins only in memory and every new chat asks for the same consent again (#26182, #23135). The kiro backend never had this problem: kiro-cli keeps the same sign-ins host-wide in ~/.aws/sso/cache.

Why it matters

Every KAS user with a remote OAuth MCP server gets a repeated Authorize card that reads as a broken sign-in. It is the most reported remote-MCP failure on KAS, and almost nobody finds the opt-in.

Not a goal

  • Per-user grant vaults. #24677 adds that as a separate, stricter change; this PR neither needs nor blocks it.
  • A governance-ceiling field that lets an admin's security_policy.json decide persistence (#28499 adds one).
  • Changing how the KAS engine refreshes or reuses tokens, or carrying a Settings > Connections sign-in into KAS.
  • A Sign out action for stored grants.

What changed (motivation → approach → change)

Symptom: a new KAS session forgets every MCP sign-in. Cause: the vault from #22625 is opt-in. Change: turn it on, and make every way the new default could fire against the owner's word fail closed.

Defaultagent.kas_persist_mcp_sign_in is true (config/sections_agent.py, config-baseline.json regenerated).
Existing installsThe key was added in #22625 (first in v0.11.0-rc.1) with default false, and it is not in the Settings UI. The Settings page's save and kirocrew config set write only the key being set. The one whole-config write in the code, kirocrew config edit on a home with no config.json (KiroCrewConfig.save()), writes every field, this key's default false included. A stored false is therefore that written-out default or a value set by hand, not a choice made in the UI. A new auto_adopt row in config/superseded_defaults.py moves a stored false to the default once; a false set after that is the owner's opt-out and is kept (the existing one-shot ledger, --keep and the settings-save ack all apply). Keeping this one-time adoption, rather than a report-only row, is Ray's explicit choice, so installs that hold that written-out default also get the fix.
Malformed valueAdded to the read stage's fail-closed agent switches in config/loader_pipeline.py (beside session_control, member_dispatch, crew_panel): a present non-boolean is read as false before validation can drop it and restore the true default.
Unreadable configkas_secret_storage.persistence_enabled returns off when the load raised, config.json or config.local.json was present but unreadable, or the agent section (or the whole config) was degraded, because those builds carry the field default, not the owner's value.
Who reuses a grantEvery session on the gateway, as today with the key on. This is the kiro backend's scope for the same sign-ins and Shared Crew's model (every admitted collaborator has the same rights, shared-crew.md §1).
Decision recorddocs/decisions/2026-11-02-kas-keeps-remote-mcp-sign-ins-by-default.md, plus the README index row.

Docs: setting help text, src/kiro_crew/docs/configuration.md, the acp-client.md and config.md specs, and the comments in acp/kas_secret_storage.py and acp/types.py.

How this relates to the other open PRs on the same key:

  • #24677 (@kyleseaman): per-user grant vaults. Not a dependency. The objection it answers, that the vault is shared by the whole gateway, is answered here by scope parity: main already shares one grant across every session multiplexed on a KAS process, the kiro backend shares it host-wide, and Shared Crew grants every admitted person the same rights, so a per-user vault narrows nothing a collaborator cannot already reach. #24677 can land on top of this unchanged.
  • #27966 (@bolichen97, draft): the same default flip, stacked on #24677 and report-only for stored false. This PR does not depend on #24677 and adopts the stored old default once, so existing installs are fixed too.
  • #28499 (@dodgeblaster, draft): the same default flip plus a new governance-policy field. This PR keeps the vault ungated by governance, as the kiro backend's cache is, and carries the fail-closed config read that GPT asked for on #28499.

Product-shape change: no RFC on main covers it. The decision is recorded in the entry above, and it still needs a maintainer's First Principles override on the head.

Backwards compatibility

Breaking: an install that never stored the key, or stored the old default false, starts keeping remote MCP client registrations and tokens in the existing encrypted grant vault when its next KAS process starts. Writer sweep on origin/main @ e858e5b378: the only reader is kas_secret_storage.persistence_enabled(), called once per spawn by runtime_spawn_launch._with_mcp_sign_in_storage; the loader's read stage and the superseded-default adoption are the only writers this change touches.

The one-shot adoption removes a stored false from config.json:

Reader: src/kiro_crew/acp/kas_secret_storage.py:persistence_enabled -- entry: chat|cron|subagent|crew page -- reads the effective value, now the true default; test_a_false_set_after_the_default_change_turns_it_off
Reader: src/kiro_crew/config/superseded_defaults.py:auto_adoptable -- entry: chat -- one-shot ledger keeps a later false; test_load_adopts_the_stale_sign_in_opt_in_once_and_keeps_a_false_set_back
Reader: website/src/api/acpBackend.ts:kasChatOwnsMcpSignIn -- entry: crew page -- documents that the key does not enter its check; unchanged
Reader: release/0.11.0 src/kiro_crew/acp/kas_secret_storage.py:persistence_enabled -- entry: release -- same reader and loader shape, so a backport carries the same behaviour

Tests

  • test/test_kas_mcp_secret_storage.py: on with no config and with an agent section that omits the key; off for a stored "true", "false", 1, 0, null, [], {}; a false set after the adoption stays off; an unreadable config.json or config.local.json is off; a load that raises is off; a KAS handshake on an unconfigured home declares secretStorage.
  • test/test_config_superseded_defaults.py: the stored old default is adopted once (key removed, ledger records it), and a false written back is kept; the registry's adopting set names the new row.
  • test/test_config_load_pipeline_field_defaults.py: the key is a declared read-stage departure (a wrong-typed value loads false).
  • test/test_config_overload_keys.py: the bool-flip ratchet loads once to let an auto_adopt row adopt its old default, then checks the flip loads as written.

Proof: PROVEN test/test_kas_mcp_secret_storage.py::test_the_key_is_on_by_default_and_read_from_config, test/test_kas_mcp_secret_storage.py::test_a_kas_handshake_with_no_config_declares_secret_storage, test/test_config_superseded_defaults.py::test_load_adopts_the_stale_sign_in_opt_in_once_and_keeps_a_false_set_back (head 09c6290385c9)

Mutation checks: with only the loader_pipeline.py hunk reverted, all 7 test_only_a_real_true_keeps_sign_ins cases fail; with only the kas_secret_storage.py hunk reverted, both test_an_unreadable_config_file_keeps_sign_ins_in_memory cases fail. Local run: 5,329 passed across every test_config_* and test_kas_* file, test_acp_tool_search_wire.py and test_runtime_bindings.py, plus the two files fixed after it (442 passed).

Manual verification

Not run end to end with a real OAuth server here. #22625 recorded the live two-process run against the real KAS engine with the key on (1 consent page instead of 2); this PR changes only when the key is on, which the handshake test drives through the real config read.

Related Issues

Fixes #23135
Refs #26182 (that report also sees a prompt on every message in one chat, which an engine-side drop could cause; this PR fixes the across-session half)

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

Contributed under the project's Apache-2.0 license.