Repository navigation
fix: The MCP server's upstream call has no deadline and no error handling - #525
Conversation
|
@Wittig18 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
Merged. The title understates it — this fixes two distinct failure modes, and the worse one is the hang.
The second one: Distinguishing timeouts from other failures matters more than it looks. Without it, an upstream that times out reports whatever generic message happens to surface, and the operator chases a JSON problem that doesn't exist. And naming the upstream host in every message is the difference between a debuggable failure and a bare Two merge resolutionsBoth against work that landed earlier today, neither your fault:
expect(mockFetch).toHaveBeenCalledWith('http://example.com/paid', { method: 'POST' })Your new Verified on the merge result rather than your branch: |
Summary
bazaar_searchin src/mcp/server.ts now has a 10s deadline, checks the response status and content type before parsing, and returns structured errors that name the upstream. The deadline isAbortSignal.timeout(10_000)passed to the fetch, as in src/alerts/delivery.ts. A non-2xx response, a response whose content-type isn't JSON, or a body that fails to parse each return anERR_SERVICE_UNREACHABLEtool error with isError set. A timeout returns the same code with a message saying the upstream did not respond within 10000ms. Every message includes the upstream host. I also gavepaid_callthe same deadline and a timeout branch inhandlePaidCallError.paid_callstill returns non-JSON bodies as text, so it doesn't reject them. I haven't run any tests, since I can't run commands here.Changed files
src/mcp/server.tstests/mcp.test.tsTest plan
Run
npx vitest run tests/mcp.test.ts. The new describe block 'bazaar_search upstream failures (#349)' covers the deadline signal being passed, a timeout, a 502 HTML response, a text/html 200, and a JSON content-type with an unparseable body. I changed the existingokFetchImplfixture to sendcontent-type: application/json, because without it the new content-type check would reject the existing success test. Then run the fullnpm test;Load test (prices)already fails on main.This PR was created as a draft by the issue solver bot. It will remain a
draft until repository CI passes.
Closes #349