Repository navigation
fix(postgrest): report HTTP error responses as tool errors - #541
Conversation
mangeshraut712
left a comment
There was a problem hiding this comment.
Reading the body as text, checking response.ok first and parsing afterwards is the right shape, and the 204 → { result: null } case is a nice catch now that prefer: return=representation isn't always honoured. Two small follow-ups below.
|
Thanks for the review. Both are in 8b13e06: a successful body that is not JSON now reports its status and content type, for the tool and for |
mangeshraut712
left a comment
There was a problem hiding this comment.
Thanks @irisfield! The follow-up in 8b13e06 addresses both points cleanly:
- Non-JSON 200 responses: Properly catches
JSON.parsefailures and names the HTTP status, response content-type header and body prefix (PostgREST <status>: expected JSON, got <content-type>: <body-slice>). - Empty error body formatting: Omits the dangling colon when the body is empty, using
statusTextwhen present (PostgREST 404: Not Found) and cleanly terminating (PostgREST 404) when both are empty. - Coverage: Both the
/specresource read andpostgrestRequesttool paths are thoroughly covered across the HTTP status spectrum inserver.http-errors.test.ts.
postgrestRequest and the /spec resource parsed every response as JSON without checking the status, so a PostgREST error body such as an invalid API key was returned as a successful result and an empty or non-JSON error body threw a SyntaxError. Throw an error with the status and body when the response is not ok. Fixes supabase#540
… error bodies Wrap JSON.parse so a 200 response that is not JSON reports its status and content type, name the status when an error response has an empty body, and cover the /spec resource error path.
8b13e06 to
63edcbf
Compare
Rodriguespn
left a comment
There was a problem hiding this comment.
Thanks a lot for the fix and the thorough tests, @irisfield! This is exactly what the issue needed.
A heads-up: we're about to deprecate @supabase/mcp-server-postgrest, so this will be the last contribution we accept for it. We'll merge this and publish a final release with your fix, then deprecate the package on npm and stop accepting issues and PRs for it. The final release will point to BYO-MCP for anyone who wants an MCP server for their app. Existing installs keep working, so you can keep using it as before.
Thanks again for taking the time to contribute!
…570) Adds a deprecation notice to `@supabase/mcp-server-postgrest` pointing users to [Deploy MCP servers](https://supabase.com/docs/guides/ai-tools/byo-mcp) (BYO-MCP), and a note in `CONTRIBUTING.md` that we no longer accept issues or PRs for it. Decision: team thread on option 2 (deprecate now, remove later). This has to be in the **final release** so the notice shows on the npm page. It uses a `fix:` type so release-please includes it in 0.2.1. **Merge order:** #541, then this PR, then the release PR (0.2.1). Then #569 (stop releasing the package) and `npm deprecate`. Refs AI-1511 Co-authored-by: Claude Sonnet 5.5 <[email protected]>
🤖 I have created a release *beep* *boop* --- <details><summary>mcp-utils: 0.11.0</summary> ## [0.11.0](mcp-utils-v0.10.0...mcp-utils-v0.11.0) (2026-11-17) ### Features * **mcp-apps:** MCP Apps foundation ([#551](#551)) ([0dbacba](0dbacba)) </details> <details><summary>mcp-server-supabase: 0.18.0</summary> ## [0.18.0](mcp-server-supabase-v0.17.0...mcp-server-supabase-v0.18.0) (2026-11-17) ### Features * **mcp-apps:** MCP Apps foundation ([#551](#551)) ([0dbacba](0dbacba)) </details> <details><summary>mcp-server-postgrest: 0.2.1</summary> ## [0.2.1](mcp-server-postgrest-v0.2.0...mcp-server-postgrest-v0.2.1) (2026-11-17) ### Bug Fixes * **postgrest:** add deprecation notice and BYO-MCP migration pointer ([#570](#570)) ([029e2a5](029e2a5)) * **postgrest:** report HTTP error responses as tool errors ([#541](#541)) ([ffa50d2](ffa50d2)) </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: supabase-releaser[bot] <223506987+supabase-releaser[bot]@users.noreply.github.com>
Stops releasing `@supabase/mcp-server-postgrest` now that its final release (0.2.1, with the error-handling fix from #541 and the deprecation notice from #570) is out. Removal of the package from the repo is deferred until BYO-MCP is ready. - Removes the package from release-please (config and manifest) and from the npm publish step in `release.yml` - Drops it from the `pkg-pr-new` preview publish The package stays in `build` and `test`. Existing installs keep working. Closes AI-1511 Co-authored-by: Claude Sonnet 5.5 <[email protected]>
What kind of change does this PR introduce?
Bug fix
What is the current behavior?
Fixes #540
postgrestRequestand the/specresource parse every response as JSON without checking the status. A PostgREST error body is returned as a normal result withisErrorunset, and an empty or non-JSON body throws aSyntaxErrorthat hides the status.What is the new behavior?
Both go through a
readJsonBodyhelper. It throwsPostgREST <status>: <body>whenresponse.okis false, withstatusTextin place of an empty body and no suffix when both are empty. A successful body that is not JSON throwsPostgREST <status>: expected JSON, got <content-type>: <first 200 characters>.postgrestRequestreturns{ result: null }for an empty successful body (204).GET /no_such_table?select=*isError: false,{"result":{"code":"PGRST205",…}}isError: true,PostgREST 404: {"code":"PGRST205",…}GET /no_such_table?select=*&bad=isError: false,{"result":{"code":"PGRST100",…}}isError: true,PostgREST 400: {"code":"PGRST100",…}GET /with an invalid--apiKeyisError: false,{"result":{"message":"Invalid API key",…}}isError: true,PostgREST 401: {"message":"Invalid API key",…}{"result":…}No change to tool names, descriptions, or input and output schemas.
How to Review
Status check
packages/mcp-server-postgrest/src/server.ts/specresource read andpostgrestRequestboth callreadJsonBody, which holds the status check and the JSON parse.Tests
packages/mcp-server-postgrest/src/server.http-errors.test.tspostgrestRequestand reads the/specresource against a localhttpstub: a 400 PostgREST error, a 500 HTML body, a 200 JSON body, a 204, a 200 HTML body and an empty 404. It does not need the local Supabase stack thatserver.test.tsuses.Verification
npx vitest run src/server.http-errors.test.ts: 8 passed.npx tsc --noEmitandpnpm format:check: clean.isError: false. After, they returnisError: truewith 404, 400 and 401.