⚡ Bolt: Batch MCP OAuth Token resolution - #161
Conversation
Batch resolves MCP OAuth tokens using an in-memory Map initialized via a single `getTokensForServers` database query to eliminate N+1 latency in `mcp-servers` and `session-mcp-servers` API endpoints.
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What: Refactored
injectPerUserOAuthTokensinapps/agor-daemon/src/register-hooks.tsto pre-fetch both shared and per-user MCP OAuth tokens using a single batch database query via a newgetTokensForServersmethod onUserMCPOAuthTokenRepository. The results are indexed in an in-memory Map with compound keys (${serverId}:${userId | 'shared'}) for instant lookup.🎯 Why: Previously, listing MCP servers resulted in N+1 database queries due to individual
await userTokenRepo.getToken(...)calls inside aPromise.allloop. This caused significant latency on endpoints fetching large sets of tools/servers.📊 Impact: Reduces database latency and connections by eliminating N+1 DB roundtrips. N queries are replaced with exactly 1 query, improving endpoint performance linearly relative to the number of returned servers.
🔬 Measurement: Verify by monitoring database query logs or tracing endpoint latency when querying
findon themcp-serversorsession-mcp-serversendpoints.PR created automatically by Jules for task 10492137682816094658 started by @Donach