[fix]: refresh stale per-user OAuth MCP tool catalogs - #5752
Conversation
…iew maintenance (maximhq#5693) * feat: support matview_refresh_interval "off" to disable logstore matview maintenance The materialized views back only the dashboard UI. Deployments that run Bifrost headless behind their own observability stack pay the REFRESH MATERIALIZED VIEW CONCURRENTLY cost for views nothing reads, and the 5s floor means the interval alone cannot turn maintenance off. With "off" (or a non-positive duration) the logs store skips view creation, the initial refresh, and the periodic refresher entirely. matViewsReady stays false, so dashboard queries fall back to the raw tables, and the runtime self-heal path cannot re-arm maintenance since it only triggers from matview-path queries. * fix: guard matview self-heal when maintenance is disabled Review follow-up: carry the resolved disabled state onto the store so triggerMatViewSelfHeal cannot recreate views the configuration says must not exist, and make the schema/docs explicit that a zero duration also disables (positive sub-5s values still clamp up).
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved token parameter compatibility handling to preserve alternative formats when the primary option is unsupported. * **Chores** * Version updated to 2.0.0. * Enhanced load testing configuration for more reliable builds. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
## Summary Briefly explain the purpose of this PR and the problem it solves. ## Changes - What was changed and why - Any notable design decisions or trade-offs ## 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 Describe the steps to validate this change. Include commands and expected outcomes. ```sh # Core/Transports go version go test ./... # UI cd ui pnpm i || npm i pnpm test || npm test pnpm build || npm run build ``` If adding new configs or environment variables, document them here. ## Screenshots/Recordings If UI changes, add before/after screenshots or short clips. ## Breaking changes - [ ] Yes - [ ] No If yes, describe impact and migration instructions. ## Related issues Link related issues and discussions. Example: Closes maximhq#123 ## Security considerations Note any security implications (auth, secrets, PII, sandboxing, etc.). ## 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
## Summary Adds a `THIRD_PARTY_NOTICES.md` file to formally document third-party components used in Bifrost that carry license terms requiring explicit attribution — specifically MPL-2.0 licensed dependencies and embedded source code derived from external projects. ## Changes - Introduces `THIRD_PARTY_NOTICES.md` to attribute: - Embedded source code in `framework/migrator/migrator.go` derived from `go-gormigrate/gormigrate` (MIT) - Go binary dependencies carrying MPL-2.0 terms: `github.com/cyphar/filepath-securejoin` and `github.com/hashicorp/go-version` - npm build-time devDependencies carrying MPL-2.0 terms: `lightningcss` (never shipped to end users) and `dompurify` (Apache-2.0 option elected) - All MPL-2.0 components are used unmodified and combined as a "Larger Work" per MPL-2.0 Section 3.3; no Bifrost source files are themselves MPL-licensed. ## Type of change - [ ] Bug fix - [ ] Feature - [ ] Refactor - [x] Documentation - [ ] Chore/CI ## Affected areas - [ ] Core (Go) - [ ] Transports (HTTP) - [ ] Providers/Integrations - [ ] Plugins - [ ] UI (React) - [x] Docs ## How to test No functional changes — review the file contents to confirm accuracy of license attributions against the listed upstream repositories. ## Breaking changes - [ ] Yes - [x] No ## Related issues N/A ## Security considerations This change has no security implications. It is a legal/compliance attribution document only. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [ ] I added/updated tests where appropriate - [x] I updated documentation where needed - [x] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable
## Summary Briefly explain the purpose of this PR and the problem it solves. ## Changes - What was changed and why - Any notable design decisions or trade-offs ## 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 Describe the steps to validate this change. Include commands and expected outcomes. ```sh # Core/Transports go version go test ./... # UI cd ui pnpm i || npm i pnpm test || npm test pnpm build || npm run build ``` If adding new configs or environment variables, document them here. ## Screenshots/Recordings If UI changes, add before/after screenshots or short clips. ## Breaking changes - [ ] Yes - [ ] No If yes, describe impact and migration instructions. ## Related issues Link related issues and discussions. Example: Closes maximhq#123 ## Security considerations Note any security implications (auth, secrets, PII, sandboxing, etc.). ## 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
## Summary Briefly explain the purpose of this PR and the problem it solves. ## Changes - What was changed and why - Any notable design decisions or trade-offs ## 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 Describe the steps to validate this change. Include commands and expected outcomes. ```sh # Core/Transports go version go test ./... # UI cd ui pnpm i || npm i pnpm test || npm test pnpm build || npm run build ``` If adding new configs or environment variables, document them here. ## Screenshots/Recordings If UI changes, add before/after screenshots or short clips. ## Breaking changes - [ ] Yes - [ ] No If yes, describe impact and migration instructions. ## Related issues Link related issues and discussions. Example: Closes maximhq#123 ## Security considerations Note any security implications (auth, secrets, PII, sandboxing, etc.). ## 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
## Summary Briefly explain the purpose of this PR and the problem it solves. ## Changes - What was changed and why - Any notable design decisions or trade-offs ## 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 Describe the steps to validate this change. Include commands and expected outcomes. ```sh # Core/Transports go version go test ./... # UI cd ui pnpm i || npm i pnpm test || npm test pnpm build || npm run build ``` If adding new configs or environment variables, document them here. ## Screenshots/Recordings If UI changes, add before/after screenshots or short clips. ## Breaking changes - [ ] Yes - [ ] No If yes, describe impact and migration instructions. ## Related issues Link related issues and discussions. Example: Closes maximhq#123 ## Security considerations Note any security implications (auth, secrets, PII, sandboxing, etc.). ## 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
Rewarm each per-user OAuth MCP client global tool catalog asynchronously after a user token is resolved. Coalesce concurrent refreshes, throttle failed attempts by the configured sync interval, reject results produced from stale client configurations, and cancel work with the manager lifecycle. Persist only the refreshed tools, name mapping, and last-sync timestamp through a narrow conditional config-store update so background refreshes cannot overwrite concurrent client edits. Restore the catalog across restarts and document its global semantics. Affected packages: - core/mcp and core/schemas - framework/configstore - transports/bifrost-http - docs/mcp/auth
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe PR adds coordinated per-user OAuth MCP tool-catalog refreshes, stale-result protection, immutable client configuration updates, persistence of discovered tools and sync timestamps, database migration support, bootstrap wiring, tests, and documentation. ChangesPer-user OAuth MCP tool catalog synchronization
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant Caller
participant MCPManager
participant MCPServer
participant ConfigStore
Caller->>MCPManager: Authorized MCP tool call
MCPManager->>MCPManager: Coalesce and throttle refresh
MCPManager->>MCPServer: Request tools/list with OAuth token
MCPServer-->>MCPManager: Return discovered tools
MCPManager->>ConfigStore: Persist tools, mappings, and sync time
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
core/mcp/clientmanager_test.go (1)
40-82: 🚀 Performance & Scalability | 🔵 TrivialConsider adding coverage for the empty-tools refresh scenario.
maybeRefreshDiscoveredToolsAsync(the orchestration function that callsVerifyPerUserOAuthConnectionthenapplyDiscoveredToolsRefresh) is not directly unit-tested here — only its constituent pieces (toolSyncFlight,applyDiscoveredToolsRefresh) are. Once the empty-tools guard proposed incore/mcp/clientmanager.gois added, add a test that exercises a successful-but-emptytoolsresult and asserts the previous non-empty catalog is retained.🤖 Prompt for 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. In `@core/mcp/clientmanager_test.go` around lines 40 - 82, Add a unit test for maybeRefreshDiscoveredToolsAsync covering a successful refresh that returns an empty tools map, with VerifyPerUserOAuthConnection succeeding; assert applyDiscoveredToolsRefresh is not allowed to replace the existing non-empty catalog and the prior tools remain intact, while preserving the existing stale-result and immutable-config coverage.
🤖 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/mcp/clientmanager.go`:
- Around line 287-306: Update the async refresh flow around
VerifyPerUserOAuthConnection and applyDiscoveredToolsRefresh to reject empty or
nil tools results when the client already has a non-empty shared catalog.
Preserve the existing catalog, set retryOnNextRequest so the next request
retries, and return without applying the empty tools or mapping; continue
applying empty results only when no prior catalog exists.
- Around line 259-275: Protect all reads of state.ExecutionConfig in
maybeRefreshDiscoveredToolsAsync, including the reads used by the dispatched
refresh and existing AcquireClientConn logic, with the same atomic pointer
snapshot mechanism used when DisableClient, EnableClient, UpdateClient, and
applyDiscoveredToolsRefresh replace it. Ensure the goroutine operates on the
captured configuration snapshot rather than an unsynchronized pointer.
---
Nitpick comments:
In `@core/mcp/clientmanager_test.go`:
- Around line 40-82: Add a unit test for maybeRefreshDiscoveredToolsAsync
covering a successful refresh that returns an empty tools map, with
VerifyPerUserOAuthConnection succeeding; assert applyDiscoveredToolsRefresh is
not allowed to replace the existing non-empty catalog and the prior tools remain
intact, while preserving the existing stale-result and immutable-config
coverage.
🪄 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: 594893e1-bf64-4717-a775-5cf81768c554
📒 Files selected for processing (16)
core/changelog.mdcore/mcp/clientmanager.gocore/mcp/clientmanager_test.gocore/mcp/mcp.gocore/schemas/mcp.godocs/mcp/auth/per-user-oauth.mdxframework/changelog.mdframework/configstore/migrations.goframework/configstore/rdb.goframework/configstore/rdb_test.goframework/configstore/store.goframework/configstore/tables/mcp.gotransports/bifrost-http/lib/config.gotransports/bifrost-http/lib/config_test.gotransports/bifrost-http/server/server.gotransports/changelog.md
The merge-base changed after approval.
244a01d to
ce1b2a6
Compare
Summary
Refresh the global cached tool catalog for per-user OAuth MCP clients after their setup-time discovery becomes stale. Previously these clients had no persistent connection, so the periodic tool syncer skipped them and their catalogs remained unchanged until the client was recreated.
Changes
tools/listrefresh after resolving a valid per-user OAuth token.discovered_tools_last_syncmigration and restore the timestamp across restarts.Type of change
Affected areas
Also affects
framework/configstorepersistence and migrations.How to test
Expected: all commands pass. The UI is not changed by this PR.
Screenshots/Recordings
Not applicable; there are no UI changes.
Breaking changes
Related issues
None.
Security considerations
The resolved bearer token is used only by the temporary upstream MCP connection and is not persisted or exposed to plugins. Refreshed tool definitions are global by design, while every tool execution continues to use the calling user OAuth token.
Checklist