Skip to content

fix(postgrest): report HTTP error responses as tool errors - #541

Merged
Rodriguespn merged 2 commits into
supabase:mainfrom
irisfield:fix/postgrest-http-errors
Nov 17, 2026
Merged

Rodriguespn merged 2 commits into
supabase:mainfrom
irisfield:fix/postgrest-http-errors

Conversation

@irisfield

@irisfield irisfield commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

Fixes #540

postgrestRequest and the /spec resource parse every response as JSON without checking the status. A PostgREST error body is returned as a normal result with isError unset, and an empty or non-JSON body throws a SyntaxError that hides the status.

What is the new behavior?

Both go through a readJsonBody helper. It throws PostgREST <status>: <body> when response.ok is false, with statusText in place of an empty body and no suffix when both are empty. A successful body that is not JSON throws PostgREST <status>: expected JSON, got <content-type>: <first 200 characters>. postgrestRequest returns { result: null } for an empty successful body (204).

call before after
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 --apiKey isError: false, {"result":{"message":"Invalid API key",…}} isError: true, PostgREST 401: {"message":"Invalid API key",…}
200 JSON {"result":…} same

No change to tool names, descriptions, or input and output schemas.

How to Review

  1. Status check

    • packages/mcp-server-postgrest/src/server.ts
    • The /spec resource read and postgrestRequest both call readJsonBody, which holds the status check and the JSON parse.
  2. Tests

    • packages/mcp-server-postgrest/src/server.http-errors.test.ts
    • Calls postgrestRequest and reads the /spec resource against a local http stub: 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 that server.test.ts uses.

Verification

  • With the fix removed, the 400 JSON, 500 HTML and 204 tests fail, and the 200 JSON test passes.
  • npx vitest run src/server.http-errors.test.ts: 8 passed. npx tsc --noEmit and pnpm format:check: clean.
  • On a hosted project, running the built package over stdio: before, the three calls in the table return isError: false. After, they return isError: true with 404, 400 and 401.

@irisfield
irisfield requested a review from a team as a code owner November 10, 2026 05:29

@mangeshraut712 mangeshraut712 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@irisfield

Copy link
Copy Markdown
Contributor Author

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 /spec, and an error with an empty body reads PostgREST 404 (with statusText when there is one). The /spec error path now has tests; they check the raw server response, because the client rejects the resource error as an invalid result.

@mangeshraut712 mangeshraut712 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @irisfield! The follow-up in 8b13e06 addresses both points cleanly:

  • Non-JSON 200 responses: Properly catches JSON.parse failures 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 statusText when present (PostgREST 404: Not Found) and cleanly terminating (PostgREST 404) when both are empty.
  • Coverage: Both the /spec resource read and postgrestRequest tool paths are thoroughly covered across the HTTP status spectrum in server.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.

@Rodriguespn Rodriguespn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@Rodriguespn
Rodriguespn merged commit ffa50d2 into supabase:main Nov 17, 2026
4 of 5 checks passed
@supabase-releaser supabase-releaser Bot mentioned this pull request Nov 17, 2026
Rodriguespn added a commit that referenced this pull request Nov 17, 2026
…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]>
Rodriguespn pushed a commit that referenced this pull request Nov 17, 2026
🤖 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>
Rodriguespn added a commit that referenced this pull request Nov 17, 2026
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]>
@irisfield
irisfield deleted the fix/postgrest-http-errors branch November 19, 2026 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

postgrestRequest returns PostgREST error responses as successful results

3 participants