Files
coder/docs/reference
Ethan ba068876cd feat: register MCP OAuth2 clients when MCP server configs are updated (#31559)
Relates to CODAGT-779

We only ran Dynamic Client Registration when an MCP server config was
created. If an admin later switched an existing server to OAuth2, or
changed the URL of a server whose client Coder had registered, the
server was left without a working client, and users couldn't connect to
it.

To fix, create and update now go through the same planner, which
registers a client whenever a save needs one. That's when a config
becomes `dynamic` (on create, when the auth type changes to OAuth2, or
when `oauth2_client_registration` changes from `manual` to `dynamic`),
or when the URL of a `dynamic` config changes. The update request gets
an optional `oauth2_client_registration` field. When it's omitted, we
use `dynamic` if the resulting config has no client ID, auth URL or
token URL, and keep the stored value otherwise.

Coder owns the client ID, secret, auth URL and token URL of a `dynamic`
config, so we ignore them when a request leaves them empty or repeats
them, and any other value fails with a 400 unless the request also sets
`manual`. Updates that touch auth fields are also validated now, so a
`manual` config without a client ID, auth URL or token URL is rejected.
A new client replaces the client ID, so it deletes every user's stored
token. If discovery or registration fails, nothing changes, and if the
config changes whilst we're registering, the request fails with a `409
Conflict`.

There are a few gaps I've left for now, and documented. A change to the
deployment's access URL doesn't register a new client. Configs broken by
the old behaviour stay `manual` until an admin switches them to
`dynamic`. We also don't re-register when the provider rejects the
client with `invalid_client`.
2026-11-03 12:39:30 +11:00
..