Files
PaperClipAI/server
Pradeep PeddineniandPradeep Peddineni 378278b21e fix: stop tool gateway routes from returning raw internal error text (#17321)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The tool gateway routes in server/src/routes/tool-gateway.ts serve
the board API and the public MCP protocol at POST
/mcp/gateways/:gatewayPublicId
> - Those routes use their own sendGatewayError helper instead of the
global error handler
> - for any error that isn't an HttpError it sent err.message back to
the caller, so a database failure leaks drizzle's Failed query text with
the SQL and its params
> - The public MCP route only needs a bearer header to reach that path,
so even a caller with a bad token can get that text
> - This pull request makes the helper answer with a fixed Internal
server error and log the real error on the server, same as the global
handler does
> - The benefit is no more SQL or param values in 500 responses from
these routes

## Linked Issues or Issue Description

Fixes #16783

## What Changed

- sendGatewayError in server/src/routes/tool-gateway.ts now logs unknown
errors with logger.error and returns { error: "Internal server error" }
with status 500.
- HttpError and ToolGatewayHttpError responses are not changed, they
still send their own message and details.
- Added server/src/__tests__/tool-gateway-error-response.test.ts. It
mounts mcpGatewayProtocolRoutes with a gateway that throws a drizzle
style error and checks the 500 body has no SQL or params. Same for a
thrown string.

## Verification

- Ran the new test on master first and both cases fail, the response
body has the full Failed query text and the param value. With the fix
both pass.
- tool-gateway.test.ts, tool-gateway-discovery-http.test.ts,
tool-grant-scope.test.ts and prompt-injection-gateway.test.ts still
pass.
- Typecheck on the changed files is clean and check:node-version,
check:module-boundaries, check:tokens and the no git push check pass.

```
cd server && npx vitest run src/__tests__/tool-gateway-error-response.test.ts src/__tests__/tool-gateway.test.ts
```

## Risks

- Low risk. Only the fallback branch for unexpected errors changes.
- If some client was reading the raw message from a 500 it will now just
see Internal server error. The full error is still in the server log so
nothing gets lost for whoever runs the instance.
- btw tool-gateway.ts was already over 1000 lines before this, the
change adds one import line.

## Model Used

Grok Bot (an AI assistant) helped trace the root cause and draft the fix
and the test. I reviewed the change and ran the tests locally.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [ ] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [ ] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [ ] I will address all Greptile and reviewer comments before
requesting merge

Co-authored-by: Pradeep Peddineni <23334879+pradeeppeddineni@users.noreply.github.com>
2026-12-05 00:20:57 -08:00
..