Skip to content

feat: add pending_verification state and initiate-verification endpoint for config.json shared-OAuth MCP clients - #3871

Merged
Pratham-Mishra04 merged 1 commit into
devfrom
05-29-feat_support_for_shared_oauth_mcp_servers_from_config.json
Aug 8, 2026
Merged

feat: add pending_verification state and initiate-verification endpoint for config.json shared-OAuth MCP clients#3871
Pratham-Mishra04 merged 1 commit into
devfrom
05-29-feat_support_for_shared_oauth_mcp_servers_from_config.json

Conversation

@Pratham-Mishra04

Copy link
Copy Markdown
Collaborator

Summary

Shared-OAuth MCP clients declared in config.json (i.e. auth_type: oauth with an inline oauth_config block but no pre-existing oauth_configs row or token) previously had no path to complete authorization — attempting to connect would fail immediately in ConnectionHeaders → GetAccessToken. This PR introduces a pending_verification state and a new POST /api/mcp/client/{id}/initiate-verification endpoint so an admin can trigger the browser OAuth flow for these config-file-originated clients after the server starts.

Changes

  • New MCPConnectionStatePendingVerification state: clients with PendingOAuthConfig set are parked in this state on startup instead of attempting a connection that would fail. Once the OAuth callback marks the linked oauth_configs row authorized, the stash is cleared and the next reconnect takes the normal connect path.

  • PendingOAuthConfig field on MCPClientConfig and TableMCPClient: holds the inline oauth_config block from config.json. Serialized to/from a new pending_oauth_config_json column via BeforeSave/AfterFind hooks. Cleared by ClearMCPClientPendingOAuthConfig once authorization succeeds.

  • DB migration (migrationAddMCPClientPendingOAuthConfigJSONColumn): adds the nullable pending_oauth_config_json text column to config_mcp_clients.

  • POST /api/mcp/client/{id}/initiate-verification endpoint: reads the persisted PendingOAuthConfig stash, runs the same OAuth bootstrap dance as the UI Create flow (via the new shared runOAuthBootstrap helper), links the freshly created oauth_configs row to the MCP client via UpdateMCPClientOAuthConfigID, and returns the authorize URL.

  • runOAuthBootstrap helper: extracts the shared OAuth initiation logic (redirect URI construction, InitiateOAuthFlow call) from addMCPClient so both the UI Create flow and the config-bootstrap flow use identical code paths and cannot drift.

  • completeMCPClientOAuth config-bootstrap fallback: when mcp_client_config_json on the oauth_configs row is nil (config.json-originated clients don't populate it), the handler now resolves the MCP client by oauth_config_id instead of returning 404. After authorization, ClearMCPClientPendingOAuthConfig drops the stash so the client reconnects normally.

  • New ConfigStore methods: GetMCPClientByOauthConfigID, UpdateMCPClientOAuthConfigID, ClearMCPClientPendingOAuthConfig.

  • Hash coverage: GenerateMCPClientHash now includes PendingOAuthConfigJSON so edits to the inline oauth_config block in config.json trigger reconciliation.

  • pendingOAuthConfigToRequest converter: maps the plain-string OAuth2Config fields to the *EnvVar-typed OAuthConfigRequest shape expected by InitiateOAuthFlow.

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

  1. Declare a shared-OAuth MCP client in config.json with auth_type: oauth and an inline oauth_config block (no oauth_config_id).
  2. Start the server — the client should appear in pending_verification state rather than erroring.
  3. Call POST /api/mcp/client/{id}/initiate-verification as an admin. Expect a 200 response containing authorize_url, oauth_config_id, and expires_at.
  4. Complete the browser OAuth flow via the returned authorize_url.
  5. Confirm the OAuth callback transitions the client out of pending_verification and into connected.
  6. Restart the server and confirm the client connects normally (no longer parks in pending_verification).
go test ./...

Breaking changes

  • Yes
  • No

Security considerations

  • PendingOAuthConfig stores OAuth client credentials as plaintext in the pending_oauth_config_json column. This mirrors the existing behavior for other credential columns in the same table (which are encrypted at rest via the existing EncryptionStatus mechanism). Env-var reference resolution is intentionally not applied to fields inside this block, consistent with the documented behavior.
  • The completeMCPClientOAuth fallback path gates on auth_type='oauth' and a non-null PendingOAuthConfigJSON to prevent replay attacks and cross-type misuse, returning 409 Conflict if the bootstrap has already been completed.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9ca06857-8397-4d13-9c39-b5c266f6f5e8

📥 Commits

Reviewing files that changed from the base of the PR and between 78aaeec and 30b6653.

📒 Files selected for processing (3)
  • framework/configstore/rdb.go
  • transports/bifrost-http/lib/config.go
  • transports/bifrost-http/lib/config_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • transports/bifrost-http/lib/config.go
  • transports/bifrost-http/lib/config_test.go
  • framework/configstore/rdb.go

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added support for shared MCP clients to remain pending until OAuth authorization is completed.
    • Added an OAuth verification flow to initiate authorization and complete setup.
    • Completed authorization now reconnects clients and finalizes configuration.
  • Bug Fixes

    • Preserved pending OAuth settings during configuration synchronization.
    • Prevented reconnect attempts while authorization is pending.
    • Prevented completed OAuth settings from being overwritten during updates.
  • Security

    • Redacted pending OAuth credentials in externally exposed configuration.

Walkthrough

Adds pending OAuth configuration and encrypted persistence for MCP clients. Adds a pending-verification lifecycle, preserves server-side OAuth state during reconciliation, and adds shared-OAuth verification initiation and completion flows.

Changes

MCP Shared-OAuth Pending Verification

Layer / File(s) Summary
Schema contract
core/schemas/mcp.go
Adds PendingOAuthConfig and the pending_verification connection state.
Persistence and hashing
framework/configstore/clientconfig.go, framework/configstore/migrations.go, framework/configstore/rdb.go, framework/configstore/store.go, framework/configstore/tables/mcp.go
Adds the database migration, encrypted JSON persistence, hash inputs, and OAuth config-store methods.
Client manager lifecycle
core/mcp/clientmanager.go
Skips reconnects for pending clients and supports pending-verification transitions and clearing.
Configuration reconciliation and redaction
transports/bifrost-http/lib/config.go, transports/bifrost-http/lib/config_test.go
Preserves server-side MCP and OAuth state and masks pending OAuth credentials.
OAuth verification flow
transports/bifrost-http/handlers/mcp.go
Adds bootstrap initiation, OAuth linking, completion fallback, replay checks, and pending-state cleanup.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant MCPHandler
  participant OAuthFlow
  participant ConfigStore
  Client->>MCPHandler: Initiate MCP client verification
  MCPHandler->>ConfigStore: Load pending shared-OAuth client
  MCPHandler->>OAuthFlow: Start OAuth bootstrap
  OAuthFlow-->>MCPHandler: Return authorization metadata
  MCPHandler->>ConfigStore: Link OAuth configuration ID
  Client->>MCPHandler: Complete OAuth authorization
  MCPHandler->>ConfigStore: Resolve client and clear pending configuration
Loading

Possibly related PRs

Suggested reviewers: akshaydeo, danpiths, roroghost17

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the pending verification state and endpoint added for config.json shared-OAuth MCP clients.
Description check ✅ Passed The description covers the purpose, changes, testing steps, affected areas, security considerations, breaking changes, and checklist.
Docstring Coverage ✅ Passed Docstring coverage is 92.31% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 05-29-feat_support_for_shared_oauth_mcp_servers_from_config.json

Comment @coderabbitai help to get the list of available commands.

@CLAassistant

CLAassistant commented May 29, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Pratham-Mishra04 commented May 29, 2026

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@greptile-apps

greptile-apps Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

This looks safe to merge.

  • The updated connection path clears the pending OAuth state before reconnecting.
  • Config reconciliation preserves the cleared state across restarts.
  • No blocking issues remain in the changed code.

Important Files Changed

Filename Overview
core/mcp/clientmanager.go Adds pending-verification lifecycle handling and propagates cleared OAuth bootstrap state during connection updates.
transports/bifrost-http/handlers/mcp.go Adds OAuth initiation and completion handling for config-file MCP clients.
transports/bifrost-http/lib/config.go Preserves server-managed OAuth state during config-file reconciliation.
framework/configstore/rdb.go Persists, links, loads, and clears pending OAuth configuration.
framework/configstore/tables/mcp.go Adds encrypted serialization and rehydration for pending OAuth configuration.

Reviews (6): Last reviewed commit: "feat: support for shared oauth mcp serve..." | Re-trigger Greptile

Comment thread core/mcp/clientmanager.go
@Pratham-Mishra04
Pratham-Mishra04 changed the base branch from 05-29-docs_mcp_docs_update to graphite-base/3871 May 29, 2026 12:04
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 05-29-feat_support_for_shared_oauth_mcp_servers_from_config.json branch from 90587d2 to f63648d Compare July 1, 2026 10:15
@Pratham-Mishra04
Pratham-Mishra04 changed the base branch from graphite-base/3871 to dev July 1, 2026 10:15
@akshaydeo
akshaydeo requested a review from a team as a code owner July 1, 2026 12:24
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 05-29-feat_support_for_shared_oauth_mcp_servers_from_config.json branch from f63648d to 73722bd Compare July 2, 2026 05:29
@coderabbitai
coderabbitai Bot requested a review from roroghost17 July 2, 2026 05:30

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/schemas/mcp.go`:
- Around line 326-342: Config.RedactMCPClientConfig currently leaves
PendingOAuthConfig untouched, so the inline oauth_config block can leak
plaintext secrets. Update the redaction path for MCP client configs to handle
PendingOAuthConfig the same way as the sibling OAuth secret fields, using the
existing OAuth2Config redaction/encryption logic so OAuth2Config.ClientSecret is
not returned verbatim.

In `@framework/configstore/clientconfig.go`:
- Around line 1449-1455: GenerateMCPClientHash should not rely only on
PendingOAuthConfigJSON for the oauth_config contribution, because it can be nil
on freshly built rows before BeforeSave runs. Update the hash logic in
GenerateMCPClientHash to fall back to hashing the runtime PendingOAuthConfig
when PendingOAuthConfigJSON is empty, while preserving the existing
deterministic JSON path when the persisted mirror is present.

In `@framework/configstore/tables/mcp.go`:
- Around line 205-218: PendingOAuthConfigJSON is being serialized in plain text
while the same hook encrypts other sensitive fields. Update the save logic in
the MCP table hook around c.PendingOAuthConfig / c.PendingOAuthConfigJSON to
route this field through the existing encrypt.IsEnabled() handling alongside
ConnectionString and HeadersJSON, and add the corresponding decrypt/rehydration
path in AfterFind so PendingOAuthConfig is restored correctly. If OAuth2Config
includes a secret, ensure the encrypted persistence path covers it consistently
with the other protected fields.
- Around line 50-59: `PendingOAuthConfigJSON` is missing an explicit GORM column
mapping, so it may not resolve to the intended database field. Update the
`PendingOAuthConfigJSON` field in `mcp.go` to pin it to
`pending_oauth_config_json` with a column tag, keeping it aligned with the
migration and any raw `Updates()` usage. Use the `PendingOAuthConfigJSON` struct
field as the anchor for the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: a1230292-6009-4af4-a826-bcac11f81c28

📥 Commits

Reviewing files that changed from the base of the PR and between 8493d18 and 73722bd.

📒 Files selected for processing (10)
  • core/mcp/clientmanager.go
  • core/schemas/mcp.go
  • framework/configstore/clientconfig.go
  • framework/configstore/migrations.go
  • framework/configstore/rdb.go
  • framework/configstore/store.go
  • framework/configstore/tables/mcp.go
  • transports/bifrost-http/handlers/mcp.go
  • transports/bifrost-http/lib/config.go
  • transports/bifrost-http/lib/config_test.go

Comment thread core/schemas/mcp.go
Comment thread framework/configstore/clientconfig.go
Comment thread framework/configstore/tables/mcp.go
Comment thread framework/configstore/tables/mcp.go
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 2, 2026
Comment thread core/mcp/clientmanager.go
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 05-29-feat_support_for_shared_oauth_mcp_servers_from_config.json branch from 77274df to 78aaeec Compare August 6, 2026 21:53
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

…ootstrap cleanup failure

- initiateMCPClientVerification now checks h.store.ConfigStore for nil
  before dereferencing, matching every other handler in this file.
- pendingOAuthConfigToRequest now carries the config.json oauth_config's
  Resource (RFC 8707) into the OAuth initiation request instead of
  silently dropping it.
- completeMCPClientOAuth now reports failure (mirroring the existing
  [PARTIAL SUCCESS] pattern used for the VK-assignment case) when
  clearing a config.json client's pending-bootstrap stash fails, instead
  of returning success while DB state can regress the client to
  pending_verification after a restart.
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 05-29-feat_support_for_shared_oauth_mcp_servers_from_config.json branch from 78aaeec to 30b6653 Compare August 8, 2026 08:43

Pratham-Mishra04 commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author

Merge activity

  • Aug 8, 8:47 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Aug 8, 8:48 AM UTC: @Pratham-Mishra04 merged this pull request with Graphite.

@Pratham-Mishra04
Pratham-Mishra04 merged commit 55c5e60 into dev Aug 8, 2026
13 of 14 checks passed
@Pratham-Mishra04
Pratham-Mishra04 deleted the 05-29-feat_support_for_shared_oauth_mcp_servers_from_config.json branch August 8, 2026 08:48
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.

2 participants