Skip to content

feat: extend MCP sessions for agent subjects - #6072

Open
danielkov wants to merge 7 commits into
integration/aim-197-prerequisitesfrom
daniel/aim-197-feat-extend-existing-mcp-sessions-agent-subjects
Open

feat: extend MCP sessions for agent subjects#6072
danielkov wants to merge 7 commits into
integration/aim-197-prerequisitesfrom
daniel/aim-197-feat-extend-existing-mcp-sessions-agent-subjects

Conversation

@danielkov

@danielkov danielkov commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Extends existing MCP user-session issuance and refresh flows to support agent subjects. Agent sessions retain immutable authorizer and delegated policy provenance while every access and refresh admission resolves the live parent and applies the credential admission boundary.

Motivation

Agent principals need delegated MCP sessions without introducing a parallel OAuth transport or dedicated token persistence model.

Technical details

Credential profile and admission

Agent subjects use the existing session, challenge, token, refresh, and revocation machinery. The stored profile carries the immutable authorizer plus delegated restriction, while admission enforces the effective R ∩ A ∩ O policy against current lifecycle and ownership state.

Refresh and revocation

Refresh rotation preserves the credential profile and re-admits the parent. Replay responses are denied when the authoritative successor session has been directly revoked.

Dependency and retargeting

This PR depends on #6068 (AIM-193 credential admission) and #6066 (AIM-196 prerequisite model work). It temporarily targets integration/aim-197-prerequisites, built from the recorded prerequisite heads. After both dependencies land on main, this branch should be rebased or otherwise reconciled and the PR retargeted to main.

Design context: First-class agent principals and delegated credentials RFC.


Summary by cubic

Extends existing MCP session issuance and refresh flows to support agent subjects, minting delegated MCP sessions from the authorized agent handoff instead of rejecting it.

  • Agent sessions persist an immutable authorizer and delegated policy; every access and refresh re-admits the live parent.
  • Refresh preserves the credential profile, admits the parent atomically inside the rotation transaction, and denies replay when the successor session has been directly revoked.
  • Agent is a first-class session subject (agent:<uuid>) and identity kind, classified separately in tool-execution killswitch coverage, where it fails closed until agent principals are supported.
  • Agent session issuance and access sit behind a rollout flag; when disabled, token, refresh, and replay return 404, and access returns 401.
  • Session creation now derives organization from the owning project for legacy project-tier issuers.
  • Existing human sessions and MCP behavior are unchanged.
  • Depends on feat: enforce live agent credential admission #6068 and feat: add agent selection to MCP authorization challenge #6066; temporarily targets integration/aim-197-prerequisites and should be retargeted to main after those land.

Written for commit 982fd0c. Summary will update on new commits.

Review in cubic

@danielkov
danielkov requested a review from a team as a code owner September 4, 2026 10:39
@linear-code

linear-code Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

AIM-197

@changeset-bot

changeset-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 982fd0c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Running ultrareview automatically — This change introduces a new agent session type with a delegated credential profile, touching session issuance, refresh, validation, and DB schema—core auth paths where a subtle bug could cause unauthorized access or break existing sessions.. I'll post findings when complete.

@danielkov
danielkov force-pushed the integration/aim-197-prerequisites branch from bc9c34e to 08ca0e9 Compare September 4, 2026 10:42
@blacksmith-sh

This comment has been minimized.

@danielkov
danielkov force-pushed the daniel/aim-197-feat-extend-existing-mcp-sessions-agent-subjects branch from 671e349 to dc80739 Compare September 4, 2026 10:49

@cubic-dev-ai cubic-dev-ai Bot 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.

Ultrareview completed in 10m 31s

Review completed against the latest diff

Linked issue analysis

Linked issue: AIM-197: feat: extend existing MCP sessions for agent subjects

Status Acceptance criteria Notes
Create an existing user session for the agent subject with immutable authorizer, endpoint-scoped delegated policy, and supported policy version The token flow mints an agent: subject, stores the authorizer and delegated grants on user_sessions, and tests verify the persisted profile and policy binding.
Preserve the agent subject, authorizer, delegated policy, and policy version across refresh Refresh passes the existing credential fields into mintSession, and tests compare the old and rotated session profiles.
⚠️ Re-admit the live parent agent on access and refresh, denying suspended or otherwise invalid credentials Access and refresh call admitAgentSession, and suspension denial is tested. The diff does not directly demonstrate every required lifecycle case such as deletion, owner loss, cross-tenant mismatch, or live-policy denial.
Honor direct session revocation and deny refresh replay when the successor session is revoked Agent access uses an authoritative non-deleted session lookup, while replay reloads and validates the successor session; a directly revoked successor is covered by a test.
⚠️ Continue using the existing MCP OAuth issuer, client, redirect, PKCE, resource, endpoint, and session contracts without agent-specific OAuth or token persistence surfaces The implementation extends the existing token and session paths and validates endpoint binding, with no dedicated agent endpoint or token store added. The diff does not independently test every exact issuer, redirect, PKCE, and resource contract listed in the issue.
⚠️ Leave existing human sessions and MCP behavior unchanged when agent delegation fields are absent Non-agent minting rejects unexpected delegation fields and the existing session path remains in use, but no focused regression test for unchanged human behavior is included in this diff.

Tip: instead of fixing issues one by one fix them all with cubic

Re-trigger cubic

Comment thread server/internal/mcp/authnchallenge_token.go
Comment thread server/internal/killswitches/mcptoolexecution/principal.go
Comment thread server/internal/mcp/agent_session.go Outdated
Comment thread server/internal/usersessions/queries.sql
Comment thread server/internal/mcp/authnchallenge_token.go Outdated
Comment thread server/internal/urn/session_subject.go
Comment thread server/internal/mcp/authnchallenge_token.go Outdated

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 11 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread server/internal/mcp/authnchallenge_token.go Outdated
Comment thread server/internal/killswitches/mcptoolexecution/principal.go Outdated
Comment thread server/internal/mcp/authnchallenge_token_refresh_test.go Outdated
@blacksmith-sh

This comment has been minimized.

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 13 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Fix all with cubic | Re-trigger cubic

Comment thread server/internal/mcp/authnchallenge_token.go
@danielkov
danielkov force-pushed the daniel/aim-197-feat-extend-existing-mcp-sessions-agent-subjects branch from fad05e3 to 15b9aab Compare September 4, 2026 11:55
@blacksmith-sh

This comment has been minimized.

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Fix all with cubic | Re-trigger cubic

Comment thread server/internal/mcp/authnchallenge_token_refresh_test.go
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.

1 participant