Skip to content

⚡ Bolt: batch MCP OAuth token database lookups to fix N+1 query - #170

Open
Donach wants to merge 1 commit into
cfx/android-hermes-clientfrom
bolt-mcp-oauth-token-batching-6178228255922363110
Open

⚡ Bolt: batch MCP OAuth token database lookups to fix N+1 query#170
Donach wants to merge 1 commit into
cfx/android-hermes-clientfrom
bolt-mcp-oauth-token-batching-6178228255922363110

Conversation

@Donach

@Donach Donach commented Aug 4, 2026

Copy link
Copy Markdown

💡 What:
Replaces the Promise.all(context.result.map(injectToken)) approach for fetching MCP OAuth tokens in register-hooks.ts with a batched query. Introduces getTokensForServers to the UserMCPOAuthTokenRepository using Drizzle's inArray to fetch all tokens simultaneously, placing them in an in-memory Map for O(1) synchronous lookup.

🎯 Why:
Previously, rendering a list of MCP servers (like in the UI or during orchestration) triggered an individual database getToken() call per server for OAuth tokens. This resulted in an N+1 query problem, creating unnecessary database latency.

📊 Impact:
Reduces database round-trips from O(N) to O(1) when fetching lists of OAuth-enabled MCP servers. Substantially improves response latency for large server lists, and minimizes load on the SQLite / libSQL database.

🔬 Measurement:
Run pnpm -w agor session list or load the workspace UI with multiple OAuth-authenticated MCP servers configured. Verify that the tokens resolve properly (either per_user or shared) and that database logs show a single query fetching all required tokens via $in instead of iterative individual queries.


PR created automatically by Jules for task 6178228255922363110 started by @Donach

Replaces the N+1 database queries for MCP server OAuth tokens
with a single batched query using Drizzle's `inArray` inside
`apps/agor-daemon/src/register-hooks.ts`.

Tokens are now pre-fetched and stored in an O(1) in-memory Map
using a compound key of `<server_id>:<user_id|shared>`, preserving
both shared-mode and per-user token isolation.
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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.

1 participant