fix: MCP server hanging, stale context, and pagination issues#49
Conversation
* Remove stateless fallback mode in server.ts to prevent tools/call messages from hanging uninitialized servers. Replaced with explicit HTTP 400 error. * Update session ID extraction to check req.query.sessionId as a fallback for the transport connection. * Fix stale session context on stateful transport reuse by injecting the latest sessionId into the cached McpContext before transport.handleRequest(). * Replace nullish coalescing `??` with `||` logic in MCP tools list parameter extraction to correctly handle agents passing a 0 limit, preventing empty list results. Co-authored-by: Donach <39565367+Donach@users.noreply.github.com>
|
👋 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
Resolves several critical reliability issues with the Agor MCP server implementation, specifically around request hanging, stale session contexts, and empty data lists returned to external agents.
Why
POST /mcpstateless fallback block created an uninitializedMcpServerand directly forwarded requests. The official SDK dropstools/callmessages if the server isn't initialized, leaving the HTTP response hanging indefinitely.x-agor-session-id, but the SDK caches the originalMcpContextat initialization.args.limit ?? 50. If an agent requested unlimited items by sendinglimit: 0, the value 0 bypassed the nullish check, pushinglimit: 0directly to Drizzle, yielding 0 results.Fix
HTTP 400 (-32000)JSON-RPC error.transport.handleRequestto intercept and dynamically updateMcpContext.sessionIdon every request.mcpSessionIdfrom both headers and query strings (req.query.sessionId).??with||for limit parsing to correctly default explicit0s.Impact
Agents properly receive errors rather than hanging timeouts. Transport connections safely handle rapid context-swapping. Tools gracefully ignore 0-limits and return actual list datasets.
Verification
POST /mcperrors.PR created automatically by Jules for task 17280555621895635601 started by @Donach