Skip to content

fix: client-cancelled GET /v0/servers returns 499 without error log#1335

Merged
rdimitrov merged 3 commits into
modelcontextprotocol:mainfrom
advancedresearcharray:fix/list-servers-client-cancel-1323
Jun 5, 2026
Merged

fix: client-cancelled GET /v0/servers returns 499 without error log#1335
rdimitrov merged 3 commits into
modelcontextprotocol:mainfrom
advancedresearcharray:fix/list-servers-client-cancel-1323

Conversation

@advancedresearcharray
Copy link
Copy Markdown
Contributor

Summary

  • Map context.Canceled from ListServers to HTTP 499 instead of 500
  • Skip list servers failed error-level logging when the client disconnects mid-stream
  • Prevents huma superfluous response.WriteHeader warnings on closed sockets

Closes #1323

Test plan

  • go test ./internal/api/handlers/v0/... -run ListServersError

Made with Cursor

root and others added 3 commits June 4, 2026 10:04
Avoid error-level logs and double WriteHeader when GET /v0/servers
clients disconnect mid-stream. Closes modelcontextprotocol#1323.

Co-authored-by: Cursor <cursoragent@cursor.com>
Export ListServersError, use errors.As and v0_test package.

Co-authored-by: Cursor <cursoragent@cursor.com>
@rdimitrov rdimitrov merged commit ef29673 into modelcontextprotocol:main Jun 5, 2026
2 checks passed
rdimitrov added a commit that referenced this pull request Jun 5, 2026
…#1338)

## Summary
Fixes the information-disclosure regression introduced by #1335 (item 1
of #1337).

`ListServersError` passed the raw `err` into
`huma.Error500InternalServerError(...)`. huma serializes extra error
args into the response body's `errors` array (`ErrorModel.Errors`,
`json:"errors,omitempty"`), so on the **public, unauthenticated** `GET
/v0/servers` endpoint a genuine DB failure echoed the internal wrapped
error from `internal/database/postgres.go` (`error iterating rows: <pgx
error>`) back to the client. pgx/pgconn errors can carry SQLSTATE codes,
constraint/table/column names, and internal messages (CWE-209).

## Change
- Drop `err` from the 500 call so only the generic message is returned;
keep `log.Printf` for the server-side detail — matching the sibling
handlers (`servers.go:190/220`, `edit.go`, `status.go`).
- Add a regression test
(`TestListServersError_realFailureDoesNotLeakDetail`) that marshals the
500 error and asserts the internal detail is absent from the
client-visible body. Existing tests only asserted status codes, which is
why the leak slipped through.

The 499 client-cancelled path is unchanged (the client has already
disconnected, so nothing is leaked there).

## Test plan
- [x] `go test ./internal/api/handlers/v0/... -run ListServersError`
(3/3 pass)
- [x] `go build ./...`, `go vet`, `golangci-lint` (no new findings in
changed files)

## Note
This leaves the non-security items in #1337 (correcting the `superfluous
WriteHeader` claim, `statusClientClosed` const reuse, broader
cancellation-guard scope) for separate follow-up. Closing #1337 here
since the only security-impacting item is addressed; reopen/split if
you'd prefer to track the nits independently.

Closes #1337

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

/v0/servers logs benign client cancellations as "list servers failed" and triggers "superfluous response.WriteHeader" warnings

2 participants