feat: reuse OAuth 2.1 clients per assistant for MCP server auth - #5085
Draft
danielkov wants to merge 1 commit into
Draft
feat: reuse OAuth 2.1 clients per assistant for MCP server auth#5085danielkov wants to merge 1 commit into
danielkov wants to merge 1 commit into
Conversation
Implements stable 1:1 mapping between assistants and OAuth clients for MCP server authentication to prevent accumulation of abandoned per-use clients. Changes: - Add assistant_mcp_oauth_clients table to store reusable OAuth client credentials per (assistant_id, mcp_url) combination - Modify handleCreateMCPAuthFlow to check for and reuse existing clients before registering new ones - Store encrypted client_secret as BYTEA in database - Add SQL queries for getting and upserting OAuth client records Resolves DNO-799 Co-authored-by: Daniel Emod Kovacs <danielkov@users.noreply.github.com>
Contributor
|
Contributor
|
|
||||||||||||||||
Contributor
|
|
||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements stable 1:1 mapping between assistants and their OAuth 2.1 clients for MCP server authentication, preventing the accumulation of abandoned per-use client registrations.
Problem
Assistants were creating a new OAuth 2.1 client registration for each authentication session with MCP servers, leaving behind multiple clients and making it harder for administrators to understand which apps retain authentication access.
Solution
This PR introduces:
New database table:
assistant_mcp_oauth_clientsto store reusable OAuth client credentials indexed by(assistant_id, mcp_url)Modified auth flow: The
handleCreateMCPAuthFlowfunction now:Encrypted storage: Client secrets are encrypted using the existing encryption client before storage as BYTEA
Acceptance Criteria
✅ One stable OAuth 2.1 client per assistant per relevant MCP server/auth context
✅ Subsequent authentication sessions reuse the existing client
✅ No accumulation of abandoned per-use clients
✅ Client metadata clearly identifies and links back to the assistant
✅ Existing duplicate clients have a defined cleanup path (manual cleanup or future migration)
Migration Notes
assistant_mcp_oauth_clientsstores OAuth client credentialsTesting
Resolves DNO-799
Linear Issue: DNO-799
Summary by cubic
Reuses a single OAuth 2.1 client per assistant per MCP server to stop piling up one-off registrations and make admin access clearer. Implements a 1:1 mapping keyed by (assistant, MCP URL) and updates the auth flow to look up and reuse clients (meets Linear DNO-799).
New Features
assistant_mcp_oauth_clientstable with a unique(assistant_id, mcp_url)key; stores encryptedclient_secretas BYTEA.handleCreateMCPAuthFlowto fetch and reuse existing clients; registers and upserts a client only if none exists.GetAssistantMCPOAuthClientandUpsertAssistantMCPOAuthClient.Migration
Written for commit 3d47574. Summary will update on new commits.