fix(client): Handle empty JSON responses#1159
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d9aff4a. Configure here.
| const text = await response.text(); | ||
| if (text.trim() === "") { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Null return breaks caller contracts
Medium Severity
parseJsonResponse now returns null for empty bodies, but every requestJSON caller still treats the result as required response data. Untyped call sites cast and read fields immediately, so empty responses become TypeErrors instead of the previous parse failure. Zod-backed call sites fail later with schema errors. Endpoints that intentionally return no body already go through request, not requestJSON.
Reviewed by Cursor Bugbot for commit d9aff4a. Configure here.


This PR addresses the issue "Error: Failed to parse JSON response: Unexpected end of JSON input" occurring in
SentryApiService.parseJsonResponse.Root Cause:
The
parseJsonResponsemethod inpackages/mcp-core/src/api-client/client.tsdirectly callsresponse.json()without checking if the response body is empty. This leads to anUnexpected end of JSON inputerror when Sentry API endpoints return a 200 or 204 status with no content, or when Cloudflare's fetch layer delivers an empty body.Solution:
Modified
parseJsonResponseto first read the response body as text. If the trimmed text content is empty, it now returnsnull, effectively bypassing the JSON parsing attempt for empty responses. For non-empty responses, it proceeds to parse the text as JSON within the existing error handling block. This prevents the parsing error while maintaining correct behavior for valid JSON and appropriate error reporting for malformed non-empty responses.Fixes MCP-SERVER-FY2
Comment
@sentry <feedback>on this PR to have Autofix iterate on the changes.