Skip to content

fix(identity): carry session identity to builtin app MCP servers - #19801

Merged
iamwhatever merged 2 commits into
kirodotdev:mainfrom
Arna13:fix/app-mcp-session-identity
Oct 13, 2026
Merged

iamwhatever merged 2 commits into
kirodotdev:mainfrom
Arna13:fix/app-mcp-session-identity

Conversation

@Arna13

@Arna13 Arna13 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Builtin app MCP servers that run Kiro Crew's own code, such as Mochi's mochi:mochi, can serve tool calls from a dashboard chat instead of refusing every one.

On the kiro backend, every tool on the mochi:mochi server refuses as identity_unattested (on 0.8.0.9) or identity_unattestable (on main) for session mcp, while kirocrew-core and kirocrew-cron work in the same chat. Mochi never moves, shows bubbles or runs its watchlist, and its background planner hangs on get_watchlist. The kiro_crew app mcp mochi process carries no KIROCREW_STUB_SESSION_TOKEN, while its mcp-core sibling under the same kiro-cli-chat acp process does. Full report in #19798.

Why it matters

On the kiro backend's shared runtime, a user who enables Mochi gets a pet that never does anything, with no hint in the UI why. Mochi is the only shipped builtin with a host-CLI MCP server today, but any builtin that adds one serves through mcp_shared.run_mcp_stdio_loop and would hit the same refusal.

Not a goal

  • gatewayd's pooled path (CONTROL_PLANE_BACKENDS) is unchanged: a pooled app server is still not handed the token.
  • Harnesses other than kiro are unchanged.
  • No change for user apps or for builtin apps that ship their own binary: they are not Kiro Crew's code and get no identity element.

What changed (motivation → approach → change)

Symptom: app server tools refuse for session mcp. Root cause: the per-session identity element session_mcp.kiro_control_plane_servers builds covers only IDENTITY_BOUND_SERVERS, which derives from KIROCREW_BIN_MCP_SERVERS. A builtin app server reaches the spec through bridges._own_mcp_servers and kiro-cli launches it straight from there, so the token attach in runtime._own_stub_session never reaches it. This is the gap #12476 closed for the opt-in Crew servers, left open for app servers.

Change, following the same pattern:

  • apps.execution.builtin_app_host_cli_mcp_launches() lists the servers a shipped, builtin-owned manifest declares as command: "kirocrew" with string args and no url, with their shipped args. It filters _builtin_app_mcp_server_configs(), the one manifest enumeration builtin_app_mcp_servers() now takes its keys from, so every launch is by construction a server that set already trusts.
  • session_mcp.builtin_app_identity_launches() pins each one with bridges._pin_host_cli_command, the same pin registration applies, so the launch is the gateway's own interpreter and never the spec's.
  • kiro_control_plane_servers now re-declares a granted app server after the managed servers, under the same rules: the spec's tools grant, native_mount_withholding, skipping a name a broker stub already carries, and replacing a hand-edited launch with the derived one. PYTHONPATH and KIROCREW_HOME come from the pin, over anything the spec declares.
  • docs/architecture/mcp.md documents the extra population and that gatewayd's set stays the managed servers.
  • apps/execution.py is now black-clean, so its line is pruned from .github/black-baseline.txt.

Backwards compatibility

Compatible: the change only adds a per-session element for a granted builtin app server that today is mounted from the spec and refuses every call. Managed servers keep their elements in the same order.

Removes nothing: the diff adds an element and a helper, and removes no path, record, key or function.

Tests

test/test_app_mcp_session_identity.py:

  • a granted builtin app server gets an identity element with the manifest launch and the pinned PYTHONPATH / KIROCREW_HOME
  • the runtime's token attach reaches that element
  • a hand-edited spec launch is replaced by the manifest one
  • spec env cannot move the data home or PYTHONPATH
  • an ungranted app server, or one outside the shipped set, gets no element
  • a disabledTools restriction keeps the element out and reports it as withheld
  • a name a broker stub already carries is not duplicated
  • only host-CLI servers of builtin-owned manifests count as launches
  • the shipped Mochi manifest stays a host-CLI launch
  • unreadable settings report the app servers as withheld too, not only the managed ones

All 11 fail on main. The existing identity suites (test_session_token_identity.py, test_native_skill_projection_sources.py, test_mcp_gateway_stub_session_token.py, test_member_panel_mount.py) pass unchanged.

Manual verification

On an isolated dev gateway built from this branch (its own KIROCREW_HOME, KIRO_HOME and port, macOS arm64), with Mochi enabled, a dashboard chat with the mochi agent was asked to call get_watchlist:

  • with the change: the kiro_crew app mcp mochi process carries KIROCREW_STUB_SESSION_TOKEN and the call returns {"watchlist": {"version": 1, "items": []}}
  • same gateway with session_mcp.py reverted: the call fails with identity_unattestable: session mcp resolved only from a source the gateway cannot attest

Mount path: with the default configuration, both on that dev gateway and on a stock 0.8.0.9 desktop install, kiro_crew app mcp mochi is spawned directly by the chat's kiro-cli-chat acp process from the agent spec, not through a broker stub or gatewayd's pool. That is the path this change fixes. A pooled or stubbed app server would still get no token, and that path is left for a follow-up, since gatewayd would need the same manifest re-derivation on its side.

The desktop pet window itself was not exercised.

Related Issues

Fixes #19798

Pattern harvest

Rule candidate: review-prompt
Pattern: a new server that serves through mcp_shared.run_mcp_stdio_loop must be in a set that receives the per-session token on every mount path, or every call refuses.

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

I agree that this contribution is made under the project's Apache-2.0 license.

A builtin app whose manifest runs the host CLI (mochi:mochi) was mounted
by kiro-cli straight from the agent spec with no session token, so every
tool call refused as identity_unattested for session mcp.
kiro_control_plane_servers now re-declares a granted one after the
managed servers, with the launch re-derived from the shipped manifest
and pinned as registration pins it, so the token attach reaches it.
@Arna13
Arna13 requested review from a team and KiroCrewCaptain as code owners October 13, 2026 10:45
@Arna13
Arna13 requested a review from mbriones98 October 13, 2026 10:45
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 13, 2026
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision 2f55b88a9c886666cc58bca811c7aff4df5a8816 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 2f55b88a9c886666cc58bca811c7aff4df5a8816 via the fork AI-review pipeline — 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/CONCERNS are advisory.

First-Principles-Verdict: PASS

Mochi was only checked on macOS through the direct spec mount. Someone should confirm that a default Linux or Windows install never sends mochi:mochi through the stub or pooled path, where calls still refuse.

What this change ships

Inventory (6 items) — 5 justified

Intent: let tools on builtin app MCP servers that run Kiro Crew's own code (Mochi) work from a dashboard chat instead of refusing every call. This is a FIX.

  1. On the kiro backend, a granted mochi:mochi server now gets a per-session identity element, so it receives the session token and its calls succeed — justified
  2. That element's launch, PYTHONPATH and KIROCREW_HOME come from the shipped manifest's pinned launch, never from the spec — justified
  3. Apps that are not Kiro Crew's code get no element: user apps, shadowed builtins, own-binary or url servers — justified
  4. When settings are unreadable, the builtin app servers are reported as withheld too, not only the managed ones — justified
  5. _builtin_app_mcp_server_configs becomes the one manifest enumeration that both builtin_app_mcp_servers and the new launch list read — justified
  6. Whole-file black reformat of apps/execution.py and its line pruned from the baseline — rides along, follows the AGENTS.md baseline rule

[FIRST-PRINCIPLES-REVIEWED] 2f55b88

Description read

[DESCRIPTION-READ] 4edd1eff5cf4a3c5588a04bfc7bd0459fd717ba8deb43b10db4db00041699d5e

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 Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 2f55b88a9c886666cc58bca811c7aff4df5a8816 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check that the gateway is right to give the session token to mochi:mochi. That process's launch comes from the manifest, but its other env still comes from the spec, through _managed_element_env.

[DESIGN-REVIEWED] 2f55b88

Description read

[DESCRIPTION-READ] df3f5930ec6e85b0c7f9b019a9385ed20f1257ede35b5e42b5a25eac1abbe26d

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 Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 2f55b88a9c886666cc58bca811c7aff4df5a8816 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 2f55b88

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 2f55b88a9c886666cc58bca811c7aff4df5a8816 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 2f55b88

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision readiness: action required A blocking check or review needs attention labels Oct 13, 2026
The settings-unreadable return now names the builtin app servers among
its withheld verdicts, and the host-CLI launch helper filters the same
manifest enumeration builtin_app_mcp_servers() takes its keys from, so
a launch can never name a server that set does not trust.
@Arna13
Arna13 force-pushed the fix/app-mcp-session-identity branch from 0ee1a83 to 2f55b88 Compare October 13, 2026 14:23
@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 Oct 13, 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.

Verdict: APPROVE at 2f55b88a9c

What it fixes

On the Kiro backend, kiro-cli mounts mochi:mochi straight from the spec, so it starts without KIROCREW_STUB_SESSION_TOKEN and every Mochi tool call refuses as identity_unattested for session mcp. The pet never moves and its watchlist never runs. kiro_control_plane_servers now re-declares a granted builtin app server that runs Kiro Crew's own code, with the same per-session element the managed kirocrew-* servers get. Same class as #12476, fixed at the same seam.

What I verified

  • Only Kiro Crew's own code gets the token. builtin_app_host_cli_mcp_launches (apps/execution.py) admits a server only when a shipped, builtin-owned manifest declares command: "kirocrew" with string args and no url. It reads the same enumeration as builtin_app_mcp_servers, so the two cannot disagree. A user app, a shadowing app and a builtin shipping its own binary get nothing.
  • The launch is never the spec's. It is re-derived from the manifest and pinned through bridges._pin_host_cli_command, exactly as registration pins it. A pin that comes back as bare kirocrew is skipped. A hand-edited mochi:mochi command in the spec cannot obtain the element.
  • Env is owned the same way as the managed servers. _managed_element_env sanitizes the spec env first, then the pin's PYTHONPATH / KIROCREW_HOME go on top, so a spec cannot move the data home.
  • Restrictions still win. The app candidates go through the same allow.grants, native_mount_withholding (mute, disabledTools, non-stdio) and existing_names checks. Unreadable settings now name the app servers in the withheld verdict too.
  • Off the event loop. The only caller, runtime._unpooled_control_planes, runs it under asyncio.to_thread, so the manifest reads do not block other sessions.
  • test/test_app_mcp_session_identity.py: 11 passed in a detached worktree of this head (confirmed the worktree's kiro_crew was loaded).
  • Mutations, one at a time, tree clean after:
    • host-CLI filter removed → test_only_host_cli_servers_of_builtin_owned_apps_are_launches
    • builtin-owned narrowing removed → the same test
    • grant check on app servers removed → test_an_ungranted_app_server_gets_no_element
    • pinned env not applied → test_granted_builtin_app_server_gets_an_identity_element, test_spec_env_cannot_move_the_app_data_home

On the scope question (gatewayd)

Leaving gatewayd's pooled set at the managed servers is the right scope for this PR. mcp_gateway.stub_servers is empty by default, so on a default install no broker runs and Mochi goes through exactly the path this PR fixes. A pooled mochi:mochi only exists if an operator stubs it from MCP Management; in that case the session-side element is skipped (existing_names) and the call still has no attestation. That is an opt-in edge, and handing a pooled app backend a session token is a different trust question, so a follow-up issue is better than widening this one.

Blocking

None.

Non-blocking follow-ups

  • The command == "kirocrew" skip in builtin_app_identity_launches (an unpinned launch would resolve kirocrew through PATH) is not pinned: removing it leaves all 11 tests green. A test where _pin_host_cli_command returns the input unchanged would cover it.
  • The diff also black-formats untouched code in apps/execution.py and drops it from black-baseline.txt. That is allowed, but it makes the security-relevant lines harder to find; worth calling out in the description.
  • Please open a follow-up issue for a stubbed (pooled) mochi:mochi, so that case is tracked rather than silently still failing.

Not verified

  • I did not run a live gateway with Mochi; the end-to-end claim is the author's.
  • I did not run the full suite or the pooled topology.

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

This PR gives builtin app MCP servers that run Kiro Crew's own code (today mochi:mochi) the same per-session identity element that the managed kirocrew-* servers already get on the kiro backend. That fixes the root cause of #19798: the token attach only reached IDENTITY_BOUND_SERVERS, so a spec-mounted app server refused every call as unattested. I read session_mcp.py, the execution.py split and the new tests. Since this hands a session token to a process, I tried to break the narrowing. A user app that shadows a builtin name is dropped by builtin_owns_installed. A hand-edited mochi:mochi entry with a different command gets the manifest launch from _pin_host_cli_command instead. Spec env cannot move PYTHONPATH or KIROCREW_HOME (the pin wins the merge) and cannot inject loader or launcher-exec variables (_managed_element_env sanitizes them exactly as it does for kirocrew-core). An app that ships its own binary or a url server never qualifies, and an ungranted or disabledTools-restricted server gets no element. Pin or manifest failures fail soft, leaving today's behaviour. The pooled/stub path is declared out of scope, the 11 new tests fail on main, checks are green, and buluoray has already approved. — crew-pr-reviewer (deep re-check)

@iamwhatever
iamwhatever enabled auto-merge (squash) October 13, 2026 17:30
@iamwhatever
iamwhatever merged commit ac8a96a into kirodotdev:main Oct 13, 2026
107 of 114 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 13, 2026
buluoray added a commit that referenced this pull request Nov 3, 2026
On the KAS backend every mochi:mochi tool refused as
identity_unattestable. The kiro-cli path re-declares a builtin app
server that runs Kiro Crew's own code with the signed session token
(#19801), but KAS never reaches it, and the KAS hoist tokened only the
managed kirocrew-* names, so the app server launched with no token.

The KAS harness now resolves those app servers off the loop with the
payload, and the hoist moves them to the session-level array, relaunched
from the shipped manifest launch and stamped with the token. A server a
settings file restricts, or every one when settings are unreadable,
keeps its native declaration, the same verdict the kiro-cli mount
reaches. The manifest's no-op disabled: false no longer keeps the entry
out of the hoist. Fixes the KAS half of #19798.
buluoray added a commit that referenced this pull request Nov 3, 2026
On the KAS backend every mochi:mochi tool refused as
identity_unattestable. The kiro-cli path re-declares a builtin app
server that runs Kiro Crew's own code with the signed session token
(#19801), but KAS never reaches it, and the KAS hoist tokened only the
managed kirocrew-* names, so the app server launched with no token.

The KAS harness now resolves those app servers off the loop with the
payload, and the hoist moves them to the session-level array, relaunched
from the shipped manifest launch and stamped with the token. A server a
settings file restricts, or every one when settings are unreadable,
keeps its native declaration, the same verdict the kiro-cli mount
reaches. The manifest's no-op disabled: false no longer keeps the entry
out of the hoist. Fixes the KAS half of #19798.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Builtin app MCP servers (e.g. mochi:mochi) never get the session token, every tool call fails with identity_unattested

3 participants