Skip to content

feat(platform): add the sign-in server for coding agents - #4898

Merged
yannickmonney merged 3 commits into
mainfrom
feat/agent-oauth-server
Oct 12, 2026
Merged

yannickmonney merged 3 commits into
mainfrom
feat/agent-oauth-server

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

What

The first step of OAuth sign-in for coding agents on the MCP endpoint: the sign-in server. Better Auth's OAuth provider, which already signs people in to the organizations' own applications, learns to sign in agents beside them. It is off by default — nothing is advertised or opened until an operator turns a way in on, because no token it earns can be used yet (the organization a grant is for, the door that accepts the token and the page that asks the person are the next steps).

  • Scopes (lib/shared/agent-access.ts): tale:mcp and the five beyond it, offline_access, the three cumulative access levels, and the most a role may grant — derived from the abilities the app already checks, so the consent page, the server and the MCP door will read one rule.
  • Resource: the MCP endpoint is an OAuth resource on every address the deployment answers on (base path kept), seeded after the boot migrations through the boot's database wait; RFC 9728 metadata at the endpoint's own path and at the root, and the issuer's RFC 8414 metadata at the issuer's path. The edge proxy and the dev proxy route both from the host root.
  • Clients: identified by a client metadata document (@better-auth/cimd 1.7.5, pinned-address transport, never from the deployment's own host) or self-registered (restricted to the agent scopes, loopback/app redirects and known agents' web hosts, native apps inferred, ten an hour per source, 500 a day, 5,000 at most, never owned by the caller's session).
  • Tokens: five-minute access tokens, a refresh grant (30 days, sliding, rotated, 10-second replay grace); an authorization request that names no resource is bound to the endpoint; a failed token request is charged to its source.
  • An organization's own application keeps its behaviour: it holds no agent scope, so the resource's scope allowlist refuses it (invalid_scope), and registering it links no resource. The dead validAudiences option is gone; the provider's consent endpoints are closed (Tale's own routes will own a connection's lifecycle).
  • TALE_MCP_CLIENT_METADATA_DOCUMENTS and TALE_MCP_DYNAMIC_CLIENT_REGISTRATION default to false and TALE_MCP_CLIENT_METADATA_HOSTS / TALE_MCP_DCR_WEB_REDIRECT_HOSTS narrow them; in .env.example and the environment reference in English, German and French. While both are off the resource metadata answers 404.

Proof

  • Unit: configuration, the registration, authorization and token steps, the provider end to end through the library itself (memory adapter), the app routes, the environment schema, the scope rules. Mutation rounds on the default-off gating (5 + 2 + 2) and on nine security statements of the server module (foreign web redirect, keys of its own, session cookie on a registration, resource binding, charging a success, the deployment's own host, the cap, native inference, body size): every mutation killed.
  • Real Postgres and HTTP, new lane checkAgentOAuth beside the unchanged identity lane checkNativeIdentity (150/150): discovery, the endpoint seeded as a resource, a CLI agent registered as a native app owned by nobody, a known agent host accepted and a foreign redirect / extra scope / own keys / other grant refused, an authorization request bound to the endpoint, a client created from its metadata document and none fetched from the deployment itself, an organization's application kept off the endpoint with nothing linked, and a source that keeps registering turned away with Retry-After.
  • Whole platform server + PII suite 88,588, UI 7,680, docs 713, tsc, oxlint, format, links, manual lint and knip green; after the rebase onto the newest main, tsc, oxlint, format, manual lint, knip and the auth, environment, shared and erasure suites again.

The two earlier agent commits (the scopes, then the server) are kept as they were written; the last commit is the default-off change and the lane.

The scopes an agent connection can hold (tale:mcp and the five beyond it,
plus offline_access), the three cumulative access levels the consent page
offers, the access that needs a fresh sign-in, and the most a role may
grant — derived from the abilities the app already checks, so the consent
page, the authorization server and the MCP door read one rule.
The MCP endpoint becomes an OAuth resource on every address the
deployment answers on, and the Better Auth provider learns to sign in
coding agents beside the organizations' own applications:

- RFC 9728 resource metadata at /.well-known/oauth-protected-resource (at
  the endpoint's own path and at the root), and the issuer's RFC 8414
  metadata at the issuer's path, base path included; the edge and the dev
  proxy route both from the host root;
- the agent scopes and offline_access, the refresh grant (30 days,
  sliding, rotated, a 10-second replay grace), and the endpoint's resource
  rows written after the boot migrations: the provider's own start-up
  seeding would read the database before the boot waits out an
  unavailable one, and stay failed for the life of the process;
- clients identified by a client metadata document (@better-auth/cimd
  1.7.5 on its pinned-address transport, never from the deployment's own
  host), and open self-registration restricted to the agent scopes,
  loopback or app redirects and known agents' web hosts, native apps
  inferred, ten an hour per source, 500 a day, 5,000 at most, never owned
  by the caller's session;
- an agent's authorization request bound to the MCP endpoint when it
  names no resource, and a failed token request charged to its source.

An organization's own application keeps its behaviour: it holds no agent
scope, so the MCP resource's scope allowlist refuses it, and registering
it links no resource. The dead validAudiences option is gone. The four
TALE_MCP_* sign-in variables are in .env.example and the environment
reference (EN/DE/FR).
A coding agent can register itself or name a client metadata document, but
no token it earns can be used yet: the organization a grant is for, the
door that accepts the token and the page that asks the person all follow.
Both ways in therefore default to off, and the MCP endpoint's resource
metadata answers 404 until the operator opens one, so nothing advertises
a sign-in that cannot finish. The environment reference and .env.example
say so in English, German and French.

The sign-in server is proved against real Postgres and HTTP: discovery,
the endpoint seeded as a resource, self-registration accepted, refused and
slowed down, an authorization request bound to the endpoint, a client
created from its metadata document, and an organization's own application
kept off the endpoint. The identity lane runs beside it unchanged.
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