Skip to content

fix(kas): name MCP servers KAS will not run, and relay env/headers without a session key - #30643

Merged
buluoray merged 1 commit into
mainfrom
fix/kas-n7-mcp-transport
Nov 6, 2026
Merged

buluoray merged 1 commit into
mainfrom
fix/kas-n7-mcp-transport

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: On the KAS backend, an MCP server that will not run is named in the session notice, and a server's env and headers reach it even when the session has no key yet.

Four MCP setups that work on kiro-cli fail on KAS with no visible cause (KAS gap audit rows P0-22, P0-24, P1-7, P1-8):

  • P0-22, plain http:// to another host. KAS refuses any url that is not https or http to a loopback host (insecure-url, kiro-agent mcp/url-validation.ts). Crew said nothing. If the entry had headers, Crew's local bridge accepted http:// anyway and sent the headers in cleartext.
  • P0-24, MCP registry mode. With agent.mcp_registry_mode on, Crew withholds every server it did not author. When the Kiro profile is registry-governed, KAS also drops every non-registry server of every tier, Crew's own included (kiro-agent mcp/mcp-desired-set.ts, mcp/registry/resolve-registry-entries.ts). Only a log line said so.
  • P1-7 / P1-8, no session key. A background or pooled runtime builds its KAS batch with no session key, so the env launcher and header bridge were skipped. A stdio server started without its env, a streamable-HTTP server without its headers (401).

Why it matters

Users moving from kiro-cli to KAS lose MCP servers with no message. Registry-governed accounts lose Crew's own tools silently. Background and pooled sessions start credentialed servers without their credentials.

Not a goal

  • Changing KAS (kiro-agent) code.
  • Bringing registry-mode servers back. Pre-resolving entries in Crew does not work: KAS drops a resolved entry too. This PR only names them.
  • MCP OAuth (P0-23).
  • A GET notification stream in the header bridge.

What changed (motivation → approach → change)

Symptom: servers missing on KAS with no reason shown, and credentials missing on keyless batches. Cause: Crew's checks did not match KAS's url and registry rules, and the env/header relay was gated on a session key that only names a file. Change, all in Crew's KAS adapter:

  • kas_env_launch.kas_accepts_url mirrors KAS's isHttpsOrLocalhost, with hosts normalised as KAS's WHATWG URL parser does (127.1, [0:0:0:0:0:0:0:1], 0x7f000001 are loopback; localhost., 127.0.0.2 are not). bridgeable uses it, and the projection records a refused url as insecure-url.
  • kas_env_launch.bridge_url: the snapshot holds the canonical loopback host (127.0.0.1, [::1], localhost), so a spelling like 127.0.0.1. is never resolved through DNS.
  • kas_http_bridge._opener: a plain-http (loopback) bridge ignores environment proxies, because no_proxy matches spellings literally. https keeps the proxy; it tunnels.
  • Registry mode: each withheld server is recorded as registry, each of Crew's own as registry-if-governed. Crew cannot read KAS's access mode, so that part of the notice is conditional.
  • kas_withheld_notice adds a section above the existing one: servers that will not run, with the fix (https://, or kirocrew config set agent.mcp_registry_mode false).
  • build_kas_custom_agents passes a random unkeyed-… launch key when the session has none. The key only names the snapshot file; cleanup reads names off the batch as before. to_client_custom_agent without a key still writes no files.
  • _registry_governed and _relayed_env_references move unchanged into acp/kas_projection_reads.py for the 2,000-line cap; kas_agents imports them back, so the patch target is unchanged.
  • Docs: security.md row and agent-spec-fields.md updated.

Backwards compatibility

Breaking: a header-bearing http:// server on a non-loopback host, which connected through Crew's bridge before, no longer runs on KAS. KAS itself refuses that url, and the old path sent the headers in cleartext. Writer sweep on origin/main @ edd8754: bridgeable has one caller, relay_withheld_headers, changed here; relay_withheld_env and relay_withheld_headers have one caller, _project_mcp_servers, changed here.

Reader: src/kiro_crew/acp/kas_agents.py:_project_mcp_servers -- chat|cron|subagent -- the http entry is still declared, KAS reports it insecure-url, and the notice names it (test_a_plain_http_server_with_headers_is_not_bridged)

Tests

Proof: not provable -- other: the new test module imports constants the fix adds, so prove.py's revert errors at collection; checked by hand that the no-key launch test fails and the old bridge opener carries the env proxy on main

  • test/test_kas_mcp_not_run_notice.py (new): url rule table with WHATWG parity cases; http server not bridged and named; loopback still bridged; snapshot dials the canonical loopback host; registry notice; headers bridged with no session key; loopback bridge ignores http_proxy.
  • test/test_kas_env_launch.py: a session batch with no key starts the server with its env (real launcher process).
  • test/test_kas_withheld_credentials_notice.py: two tests that pinned the no-key loss now use an sse server, which still cannot be carried.

Manual verification

  • Ran 15 url spellings through Node's new URL + KAS's rule and through kas_accepts_url: identical answers.
  • scripts/local-gate.py related set: 9154 passed, 1 failed (test_acp_harness_contract.py::test_a_missing_self_served_binary_names_its_install_command[copilot], also red on clean main on this machine because copilot is installed). black, isort, flake8, mypy, semgrep, line cap, harness parity, docs lint pass.

Related Issues

Fixes #30630

Overlap check: #26786 (merged) added the env/headers notice this extends. Open #28444 and #22375 cover registry-mode identity and skill_search, not this notice. No open PR covers these rows.

Sibling sweep

Swept: git grep -nE "session_key=session_key|bridgeable(|startswith(("https://", "http://"))" -- src/kiro_crew/acp src/kiro_crew/kas_http_bridge.py
Sibling: src/kiro_crew/acp/kas_env_launch.py -- changed here
Sibling: src/kiro_crew/kas_http_bridge.py -- changed here
Sibling: src/kiro_crew/acp/harness/kas.py -- not affected -- passes session_key through to build_kas_custom_agents, which now supplies the launch key

Pattern harvest

Rule candidate: review-prompt
Pattern: a url accepted by a normalising check is later dialled in its original spelling

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.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision ed3721f81f1dc801ff3e5e4e0bceb86605bcfa82 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 5, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

No design-level concerns: the fix mirrors KAS's URL and registry rules in Crew's KAS adapter, and it lists the one thing it takes away (the header-bearing http:// bridge to a non-loopback host).

Notes

  • kas_accepts_url copies KAS's isHttpsOrLocalhost by hand, including how WHATWG parses hosts. If kiro-agent changes that rule, the copy drifts with no warning. A comment naming the kiro-agent version it was checked against would make that drift easier to spot.

[DESIGN-REVIEWED] ed3721f

Description read

[DESCRIPTION-READ] 0ae456e66e90f95ea636cd78c318f73297e295cfd1e8d6860230d90ea9ac1b12

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 5, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of ed3721f81f1dc801ff3e5e4e0bceb86605bcfa82 — 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

Every item maps to an audit row in #30630 or a KAS rule the description cites. The KAS url check overlaps existing loopback helpers in name only: its accept set is deliberately narrower.

What this change ships

Inventory (9 items) — 9 justified

Intent: on the KAS backend, users see which MCP servers will not run, and credentialed servers get their env/headers even in sessions that have no key yet. This is a FIX.

  1. The session notice names plain http:// servers on another host as servers that will not run, and says to switch to https:// — justified
  2. A header-bearing http:// server on a non-loopback host is no longer bridged, so its headers no longer go out in cleartext (breaking change) — justified
  3. With registry mode on, the notice names each withheld server, and names Crew's own servers conditionally, with the config command that turns the mode off — justified
  4. Background and pooled sessions with no key now start stdio servers with their env — justified
  5. Background and pooled sessions with no key now reach streamable-HTTP servers with their headers — justified
  6. Those sessions now write launch snapshots under a random unkeyed- name, removed by the existing batch and boot cleanup — justified
  7. Loopback spellings such as 127.1 or 127.0.0.1. are recognised, and the bridge dials the canonical host instead of resolving the spelling through DNS — justified
  8. The loopback http bridge ignores http_proxy, so headers do not reach a proxy in cleartext — justified
  9. Two config readers move unchanged into kas_projection_reads.py because of the 2,000-line file cap — justified

[FIRST-PRINCIPLES-REVIEWED] ed3721f

Description read

[DESCRIPTION-READ] 03ce2988210d089cc85a6c3ff388cb81984ce4777f38f24a98d1248879809528

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.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] ed3721f

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

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

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] ed3721f

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

@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Nov 5, 2026
@iamwhatever
iamwhatever force-pushed the fix/kas-n7-mcp-transport branch from af53d2f to 069f274 Compare November 5, 2026 18:40
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Fixed in 069f274: src/kiro_crew/acp/kas_env_launch.py:263 trailing-dot loopback host dialled through DNS.

Confirmed in code before fixing: getaddrinfo("127.0.0.1.", AI_NUMERICHOST) fails, so urllib resolved the name. The snapshot now holds the bridge's canonical loopback host (bridge_url: 127.0.0.1, [::1] or localhost), keeping port, path and query and dropping userinfo, which urllib would otherwise hand to the resolver as part of the host. Test: test_the_bridge_dials_the_canonical_loopback_host, which also asserts the host urllib.request.Request resolves.

@iamwhatever
iamwhatever force-pushed the fix/kas-n7-mcp-transport branch from 069f274 to 89a3884 Compare November 5, 2026 19:17
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Fixed in 89a3884: src/kiro_crew/acp/kas_env_launch.py:290 invalid loopback port aborted session creation.

kas_accepts_url now reads parts.port inside its existing try, so a port that does not parse (localhost:abc, :65536) is refused there, matching KAS's own URL parser. That one server is named in the notice and the rest of the batch is built. Tests: the url rule table gains three bad-port rows, and test_a_bad_port_on_one_server_does_not_stop_the_session builds a batch with one such server. The same finding from the Opus lane is closed by this change.

@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 5, 2026
@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 5, 2026
@iamwhatever
iamwhatever force-pushed the fix/kas-n7-mcp-transport branch from 89a3884 to aa98b13 Compare November 5, 2026 20:40
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 5, 2026
…thout a session key

- Bridge a remote server only when KAS itself would accept its url (https,
  or http to a loopback host, normalised as KAS's URL parser does). A plain
  http url to another host is named in the session notice instead of being
  bridged with its headers in cleartext.
- A plain-http (loopback) bridge ignores environment proxies, so its headers
  never reach an http_proxy in cleartext.
- In MCP registry mode, the notice names each server Crew withholds, and
  Crew's own servers, which KAS drops when the Kiro profile is
  registry-governed.
- A session batch with no session key yet (background or pooled runtime)
  names its launch snapshots with a random key, so stdio env and
  streamable-HTTP headers still reach the server.
- Move two config reads out of kas_agents.py for its line cap.

Fixes #30630
@iamwhatever
iamwhatever force-pushed the fix/kas-n7-mcp-transport branch from aa98b13 to ed3721f Compare November 5, 2026 22:25
@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 5, 2026

@buluoray buluoray 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.

🤖 Kiro Crew Auto-Pipeline [operator: buluoray]:

Approving ed3721f.

What this does for users: on the KAS backend, an MCP server that will not run is now named in the session notice (a plain http:// url to another host, and servers dropped in MCP registry mode), and background or pooled sessions start credentialed servers with their env and headers instead of without them. Headers are no longer sent in cleartext to another host, and a loopback bridge never goes through an environment proxy.

Evidence:

  • Targeted tests at this head, single process: test_kas_mcp_not_run_notice.py, test_kas_env_launch.py, test_kas_withheld_credentials_notice.py, test_member_memory_mcp_routing.py, test_kas_header_bridge.py, test_kas_agents_mcp_env_relay.py -> 223 passed.
  • One mutation per new guard, each reddened a named test: bridgeable accepting any http (test_a_plain_http_server_with_headers_is_not_bridged), host normalisation (test_kas_accepts_url_matches_the_backends_rule[http://127.1:8080/mcp-True]), canonical bridge host (test_the_bridge_dials_the_canonical_loopback_host), proxy bypass (test_a_loopback_bridge_never_goes_through_an_environment_proxy), the unkeyed launch key (test_headers_reach_the_bridge_without_a_session_key), registry labels (TestRegistryMode::test_every_server_is_named_crews_own_conditionally), and no files written by to_client_custom_agent without a key (test_no_session_key_keeps_the_withholding_projection).
  • The two managed-server sets the registry labels rely on (MANAGED_MCP_SERVER_NAMES, KIROCREW_BIN_MCP_SERVERS) were checked equal at runtime, so the labels match what is withheld.
  • No listener is added or changed; the change only narrows where credentials go.
  • Source-only: Windows inet_aton parity, and the snapshot cleanup path (by batch names, unchanged).

Non-blocking follow-ups:

  1. The registry-mode notice tells the user to run kirocrew config set agent.mcp_registry_mode false. Many users have no terminal, and this setting has no Settings control yet. A follow-up that adds one (and points the notice at it) would make the advice usable.
  2. A snapshot from a payload that never reaches a session (session/new fails) waits for the boot sweep. Unchanged by this PR, but more batches now write snapshots.

@buluoray
buluoray merged commit 50ebe42 into main Nov 6, 2026
98 checks passed
@buluoray
buluoray deleted the fix/kas-n7-mcp-transport branch November 6, 2026 02:54
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 6, 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.

Requesting changes on ed3721f. The naming of servers that will not run, and the env and header relay for a runtime with no session key yet, are good changes, and all 99 checks are green. Two things need to change first.

  1. New regex in product code. kas_env_launch.py adds import re and, in _normalized_host, re.fullmatch(r"[0-9a-fx.]+", candidate). Please replace it with a plain check, for example all(c in "0123456789abcdefx." for c in candidate) and a non-empty test, so the module needs no import re. The behavior stays the same.

  2. A new restriction on a setup that works today. The PR description says it is breaking: a header-bearing http:// server on a non-loopback host connects through Crew's bridge now, and after this change it does not run. That tightens what users can do today, and it is a security-flavored change that I would not take as the default. Please keep today's behavior by default and put the new refusal behind a setting that is off by default (for example an agent config key), with tests for both states, as the other opt-in changes here do. The parts that only name servers that will not run, and the loopback host normalization for the bridge, can stay as they are.

The rest looks fine to me: the registry-mode notice is conditional for Crew's own servers, the random unkeyed- launch key only names the snapshot file, and the plain-http loopback bridge ignoring environment proxies is a good catch.

I will look again when the head moves.

buluoray added a commit that referenced this pull request Nov 6, 2026
… out

#30643 stopped bridging an MCP server's headers to a plain http:// url
on another host. That setup connected through Crew's bridge before, so
it is restored by default, and the refusal moves behind
agent.kas_refuse_plain_http_mcp_headers (off). The bridge bypasses
environment proxies only for a loopback host, so a remote http server
keeps its proxy route. The loopback host reading moves to the
standard-library bridge, without a regex, so both sides share it.
buluoray added a commit that referenced this pull request Nov 6, 2026
… out

#30643 stopped bridging an MCP server's headers to a plain http:// url
on another host. That setup connected through Crew's bridge before, so
it is restored by default, and the refusal moves behind
agent.kas_refuse_plain_http_mcp_headers (off). The bridge bypasses
environment proxies only for a loopback host, so a remote http server
keeps its proxy route. The loopback host reading moves to the
standard-library bridge, without a regex, so both sides share it.
buluoray added a commit that referenced this pull request Nov 6, 2026
… out

#30643 stopped bridging an MCP server's headers to a plain http:// url
on another host. That setup connected through Crew's bridge before, so
it is restored by default, and the refusal moves behind
agent.kas_refuse_plain_http_mcp_headers (off). The bridge bypasses
environment proxies only for a loopback host, so a remote http server
keeps its proxy route. The loopback host reading moves to the
standard-library bridge, without a regex, so both sides share it.
buluoray added a commit that referenced this pull request Nov 6, 2026
… out (#31064)

#30643 stopped bridging an MCP server's headers to a plain http:// url
on another host. That setup connected through Crew's bridge before, so
it is restored by default, and the refusal moves behind
agent.kas_refuse_plain_http_mcp_headers (off). The bridge bypasses
environment proxies only for a loopback host, so a remote http server
keeps its proxy route. The loopback host reading moves to the
standard-library bridge, without a regex, so both sides share it.
buluoray pushed a commit that referenced this pull request Nov 6, 2026
…thout a session key (#30643)

- Bridge a remote server only when KAS itself would accept its url (https,
  or http to a loopback host, normalised as KAS's URL parser does). A plain
  http url to another host is named in the session notice instead of being
  bridged with its headers in cleartext.
- A plain-http (loopback) bridge ignores environment proxies, so its headers
  never reach an http_proxy in cleartext.
- In MCP registry mode, the notice names each server Crew withholds, and
  Crew's own servers, which KAS drops when the Kiro profile is
  registry-governed.
- A session batch with no session key yet (background or pooled runtime)
  names its launch snapshots with a random key, so stdio env and
  streamable-HTTP headers still reach the server.
- Move two config reads out of kas_agents.py for its line cap.

Fixes #30630

Co-authored-by: Joe Guo <12429733+iamwhatever@users.noreply.github.com>
(cherry picked from commit 50ebe42)
buluoray added a commit that referenced this pull request Nov 6, 2026
… out (#31064)

#30643 stopped bridging an MCP server's headers to a plain http:// url
on another host. That setup connected through Crew's bridge before, so
it is restored by default, and the refusal moves behind
agent.kas_refuse_plain_http_mcp_headers (off). The bridge bypasses
environment proxies only for a loopback host, so a remote http server
keeps its proxy route. The loopback host reading moves to the
standard-library bridge, without a regex, so both sides share it.

(cherry picked from commit f0d6dc0)
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.

KAS: plain http:// and registry-mode MCP servers fail silently; env/headers lost without a session key

3 participants