🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

feat: revoke MCP server OAuth grants at the provider on disconnect - #27300

Merged
ibetitsmike merged 23 commits into
mainfrom
mike/codagt-805-revoke-oauth-grants-mcp
Jul 19, 2026
Merged

feat: revoke MCP server OAuth grants at the provider on disconnect#27300
ibetitsmike merged 23 commits into
mainfrom
mike/codagt-805-revoke-oauth-grants-mcp

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Closes CODAGT-805.

The experimental MCP server OAuth2 disconnect endpoint previously deleted only the stored token row, leaving the grant active at the OAuth provider. This PR adds provider-side token revocation while keeping local disconnect independent of provider availability.

Changes

  • Add mcp_server_configs.oauth2_revocation_url in migration 000547. The value can be configured manually, discovered from RFC 8414 metadata, and managed through the MCP server settings UI. Non-admin responses redact it with the other OAuth2 fields.
  • Revoke the refresh token first through the RFC 7009 endpoint, then fall back to the access token only for unsupported_token_type. Public clients send client_id; confidential clients use client_secret_basic.
  • Delete the local token transactionally before best-effort provider revocation. Callers without a token receive the same response for hidden and nonexistent config IDs, and provider failures return a generic warning without exposing provider response bodies.
  • Require HTTPS revocation endpoints except for HTTP loopback URLs. Redirects must preserve the POST and remain on the configured origin. Redirect errors omit provider-controlled paths and query strings so reflected token material cannot enter logs.
  • Treat 200 OK and 204 No Content as completed revocations. 202 Accepted remains a failure because it does not confirm completion.
  • Prevent an in-flight refresh from recreating a token deleted by disconnect. Refresh persistence now uses an optimistic update keyed by token ID and updated_at; only the OAuth callback can create a token row. Refresh conflicts reload the current row or clear in-memory auth when disconnect deleted it.
  • Return {token_revoked, token_revocation_error} from disconnect, while retaining SDK compatibility with the legacy 204 response. The UI surfaces provider revocation failures as warning toasts.
  • Document revocation endpoint discovery, HTTPS requirements, and best-effort disconnect behavior.

No token or no configured revocation URL returns token_revoked: false without an error, so disconnect remains idempotent.

Updated by Mux, an AI coding agent, on Mike's behalf.

@linear-code

linear-code Bot commented Jul 16, 2026

Copy link
Copy Markdown

CODAGT-805

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 923247e6e9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/mcp.go Outdated
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0e5a4d3727

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/mcp.go Outdated
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 67f2ae7033

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/x/chatd/mcpclient/mcpclient.go Outdated
Comment thread coderd/mcp.go Outdated
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3975b9ef06

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/x/chatd/mcpclient/mcpclient.go Outdated
Comment thread coderd/x/chatd/mcpclient/mcpclient.go Outdated
Comment thread codersdk/mcp.go
Comment thread coderd/x/chatd/mcpclient/revoke_test.go Outdated
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f3c5232460

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codersdk/mcp.go
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fce59f001b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 483d583a58

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike ibetitsmike reopened this Jul 16, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 16, 2026
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

2 similar comments
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Retrigger: no response to previous review requests. Current head 5af2e159 adds only a main-merge conflict resolution and an empty retrigger commit on top of the previously reviewed 483d583a. Posted by Mux on Mike's behalf.

@ibetitsmike
ibetitsmike marked this pull request as ready for review July 17, 2026 10:59
@coder coder unlocked this conversation Jul 17, 2026
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Retrigger: the PR was locked during the earlier review requests, which is why they went unanswered. Now unlocked. Head is 5af2e159. Posted by Mux on Mike's behalf.

@coder-tasks

coder-tasks Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Documentation Check

The mcp-server-http experiment is unsafe, so this feature normally sits below the docs bar. However, a detailed page already ships for it (docs/ai-coder/agents/platform-controls/mcp-servers.md), and this PR changes documented surfaces (a new admin-configurable OAuth2 field and changed disconnect behavior). Keeping that existing page accurate is the ask here.

All flagged items are now addressed in the docs page.

Updates Needed

  • docs/ai-coder/agents/platform-controls/mcp-servers.md - Add the new oauth2_revocation_url optional field to the OAuth2 Manual configuration optional-fields table. Added; auth-type-change clearing is already covered by the general note at the top of the Authentication section.
  • docs/ai-coder/agents/platform-controls/mcp-servers.md - The disconnect description now documents best-effort provider revocation (RFC 7009), that the stored token is always deleted, and the token_revoked / token_revocation_error response fields.
  • docs/ai-coder/agents/platform-controls/mcp-servers.md - The Auto-discovery section now notes that RFC 8414 metadata discovery captures the provider's revocation_endpoint, with an explicit request value taking precedence.
  • docs/ai-coder/agents/platform-controls/mcp-servers.md - The HTTPS-only validation for oauth2_revocation_url is now documented ("The revocation endpoint must use HTTPS. Loopback URLs may use HTTP for local development and tests.").

Automated review via Coder Agents

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5af2e15953

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/mcp.go Outdated
@github-actions

Copy link
Copy Markdown

Docs preview

📖 View docs preview for docs/ai-coder/agents/platform-controls/mcp-servers.md

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

New head d422c058 fixes your P3 (config existence probe on disconnect) and adds the token revocation docs. Posted by Mux on Mike's behalf.

The experimental MCP server OAuth2 disconnect endpoint only deleted the
stored token row, leaving the grant live at the OAuth provider. Capture
the RFC 8414 revocation_endpoint during auto-discovery, store it in a
new mcp_server_configs.oauth2_revocation_url column (also settable via
the manual create/update API), and best-effort revoke the token per
RFC 7009 after the local delete. The endpoint now returns 200 with
{token_revoked, token_revocation_error} instead of 204.
Provider error bodies can echo the revocation form, including the
admin-configured OAuth client secret, so the disconnect response now
carries a fixed message while full details stay in server logs.
Drop provider response bodies from revocation errors so echoed request
parameters (including the OAuth client secret) cannot reach server
logs, and detach the provider call from request cancellation so a
client abort after the local delete cannot skip the revocation.
Authenticate confidential clients with client_secret_basic (the only
scheme RFC 6749 requires servers to support), skip the provider call
when the token row holds no token material, accept legacy 204
disconnect responses in the SDK, and capture revocation requests race
free in tests.
Update payloads omit empty optional fields, which the backend treats
as keep-existing, so a cleared revocation URL never persisted.
… drop body client_id for confidential clients
@ibetitsmike
ibetitsmike force-pushed the mike/codagt-805-revoke-oauth-grants-mcp branch from b318d3b to d6ebd6b Compare July 18, 2026 21:57
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: d6ebd6be14

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike
ibetitsmike merged commit 9f4ddea into main Jul 19, 2026
32 of 33 checks passed
@ibetitsmike
ibetitsmike deleted the mike/codagt-805-revoke-oauth-grants-mcp branch July 19, 2026 22:14
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants