Skip to content

feat(platform): connect coding agents to an organization - #4899

Merged
yannickmonney merged 2 commits into
mainfrom
feat/agent-connections
Oct 12, 2026
Merged

yannickmonney merged 2 commits into
mainfrom
feat/agent-connections

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

Summary

A person can now connect a coding agent to the organization they choose, and the organization keeps a record of it: who connected which app, with which access, when it was last called, and when and why it ended. This is the grants half of agent sign-in; the MCP door that honours the tokens comes next, and sign-in stays off by default until then, so nothing changes for a deployment today.

  • Record — app.agent_connections (migration 0203): one live connection per person, organization and app (a partial unique index plus an advisory lock, so eight consents at once leave one); ended ones stay as history. "Last used" is not stored: it is read from the MCP endpoint's own call counters (app.mcp_client_activity, kind oauth).
  • Consent gate — the sign-in server's consent step now requires an organization the person may hold an API key in, refuses access beyond their role, wants a fresh sign-in for anything beyond reading, ties the consent to the organization, and records the connection before the agent's code is handed over (a fixed reference would have let one consent be reused, so the reference is unique per call).
  • Seeing and ending — GET /api/app/agent-connections (a person's own; an owner or admin can ask for everyone's and the ended ones) and DELETE /api/app/agent-connections/:id. A connection that is someone else's, another organization's or already ended is not found, never forbidden.
  • What ending takes away — the consent and every refresh and access token of that organization's grant, and nothing of the person's other organizations (a revoked-but-present refresh token would make the provider end the whole family, so tokens are deleted, not stamped). Leaving an organization ends the person's agents there; deleting an organization removes what the sign-in server holds for it.
  • Trail — one agent_connection.created / .updated / .revoked audit row each, naming the person (or the platform) and the access before and after, and a hint to the organization.
  • A refresh by someone who left the organization is an invalid_grant, not a 403.

Rules are in backend/domains/agent_connections/spec.md (AGCONN-R1–R10); the manual reference rows and error codes are added.

Checklist

  • bun run check passes — gate run locally on the committed tree: tsc, oxlint, server + pii (88,666), UI (7,685), docs (713), format, links, manual, knip. One timing-bound test in a file this change does not touch (lib/engine/core/record/travels.test.ts, "two million reads", < 250 ms) failed under the full-suite load and passed three times alone.
  • bun run lint:sast — runs in the commit hook, clean.
  • Translations — N/A beyond the three catalogs touched (settings.yml en/de/fr: the disconnect confirmation and notice strings).
  • Docs — N/A here: the user-facing docs, contract and OpenAPI land with the slice that turns sign-in on, so the contract does not describe a door that is off.
  • README — N/A.

Test plan

  • Real Postgres + HTTP lanes checkAgentConnections and checkAgentConsent (91/91 with the rest of the shared checks): the consent drives the real endpoint, the code earns a token that names the organization, a refresh keeps naming it; each refusal (no right, a stranger, no organization, access beyond the role, no reading, a stale session asking for more) has its code and stores nothing; disconnecting and removing a seat end the agent at once; another organization's grant survives; the unique index holds under eight concurrent consents; a teardown removes the provider's rows.
  • Mutation rounds on the gate, the cascade, the ending and the listing: every mutation killed.

A coding agent connected by signing in on the MCP endpoint gets one record
for each person, organization and app, which the MCP door will read on
every call, so ending a connection ends its access at once.

- app.agent_connections (0203): the app, its verified or unverified origin,
  the access allowed, last use, and when and why it ended; one live row per
  person, organization and app, enforced by a partial unique index and a
  lock, so allowing again changes the access instead of adding a second.
- The organization's list (a person's own; an owner or admin may ask for
  everyone's and the ended ones) and the disconnect, which a person or an
  admin may do and anyone else is told does not exist.
- Ending a connection deletes the consent and every refresh token the
  sign-in server holds for this person's grant to this organization, and
  none of another's. They are deleted, never stamped revoked: the provider
  reads a refused token still on file as one used twice and ends the
  person's tokens for the app in every organization.
- A removed member's agents end with the seat; an organization's teardown
  removes its connections and the grants the sign-in server holds for it.
- One audit row for connecting, for a change of access and for each
  disconnect, with who ended it and why, labelled in English, German and
  French; a hint to the organization for each.
…hooses

The consent step of the sign-in server now makes an agent's grant for one
organization, chosen by the person, and records the connection before the
agent's code is handed over.

- The consent endpoint is reached through a gate for agent access. The
  person names an organization they are an active member of and may
  connect an agent to (the rule of holding a personal API key, read for
  that organization alone), with a verified address and no two-factor
  enrollment due; reading and testing are always allowed, nothing beyond
  what the role there allows, and anything beyond reading and reading
  settings needs a session from the last day. Each refusal has its own
  code and stores no consent.
- The organization rides the consent as the provider's reference, carried
  by an async context while the provider makes the consent, so two
  consents at once stay apart. A request around the gate is tied to a
  reference no consent ever has, is sent back to the consent page and
  gets no code.
- An access token for the MCP endpoint names the organization the person
  chose, at the code exchange and at every refresh. A refresh by a person
  who left the organization is an invalid grant, which an agent reads as
  "sign in again"; a code exchange keeps the refusal it had.
- The connection is recorded before the code is handed over; if it cannot
  be, the agent gets none.
- Tale's single sign-on clients are untouched: they ask for no agent scope
  and have no reference.
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