Skip to content

⚡ Bolt: Fix N+1 query in MCP OAuth token injection - #159

Open
Donach wants to merge 1 commit into
cfx/android-hermes-clientfrom
bolt/fix-mcp-oauth-token-n-plus-1-17972844638617198844
Open

⚡ Bolt: Fix N+1 query in MCP OAuth token injection#159
Donach wants to merge 1 commit into
cfx/android-hermes-clientfrom
bolt/fix-mcp-oauth-token-n-plus-1-17972844638617198844

Conversation

@Donach

@Donach Donach commented Jul 28, 2026

Copy link
Copy Markdown

💡 What
Extracted the MCP OAuth token fetch operation from the Promise.all loop when enriching MCP server records. It now pre-fetches all required tokens using a batched inArray Drizzle query and maps them in memory using a compound key (${server_id}:${user_id ?? 'shared'}).

🎯 Why
Previously, when the /mcp-servers endpoint returned multiple configured servers, the FeathersJS after hook would iterate through each server and query the database sequentially for OAuth tokens, resulting in a severe N+1 query performance bottleneck as the server count increased.

📊 Impact
Reduces database roundtrips for /mcp-servers reads from O(N) (where N is the number of returned MCP servers) down to O(1). This speeds up dashboard loading and token checks dramatically when many integrations are configured.

🔬 Measurement
Verify by loading the MCP servers tab in the UI or performing a large find against the mcp-servers service. Monitor the SQLite query logs to observe only one SELECT * FROM user_mcp_oauth_tokens WHERE mcp_server_id IN (...) instead of numerous single-record lookups.


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

Extracted token fetching from the `Promise.all` loop when resolving MCP
servers in `register-hooks.ts`. Leverages Drizzle's `inArray` to fetch
all relevant tokens for a batch of servers at once. Uses a compound key
to correctly map both shared and per-user tokens in memory.
@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