fix(api): reject a malformed plugin connection id with a 400

Merged
SU
1mo ago
+14-1

Problem

POST /mcp/plugins/<marketplace>/<plugin>?connection=<value> returned a 500 when <value> was not a UUID. In the reported events an MCP client put a JSON object into connection. The client got an opaque server error, and Sentry recorded a high-priority error for a bad request.

Root cause

The route passes the raw connection query parameter to resolveTarget, which passes it to connectionById. connections.id is a uuid column, so Postgres rejects the value with invalid input syntax for type uuid. Nothing classified this as caller input, so it surfaced as an unhandled server error.

Fix

Validate connection with z.uuid() at the route, where the untrusted input enters, and answer 400 INVALID_CONNECTION with a message the agent can act on. A well-formed but unknown id keeps its current behaviour (needs-auth). resolveTarget stays unchanged; its other callers pass ids that come from the database.

Verification

$ bunx biome check "apps/api/src/app/mcp/plugins/[marketplace]/[plugin]/route.ts"
Checked 1 file in 48ms. No fixes applied.
$ cd apps/api && bun run typecheck
$ tsc --noEmit
(no errors)
$ bun test src/app/mcp
379 files were searched — no test files exist for this route

Refs API-3S

Summary by CodeRabbit

  • Bug Fixes
    • Invalid connection IDs now receive a clear error response instead of being used to resolve a target.