Skip to content

fix(BUY-66091): alias domain/original_price in MCP get_deals SELECT [SEV-1] - #332

Open
BuyWhere wants to merge 1 commit into
mainfrom
fix/buy-66091-mcp-deals-domain-column
Open

fix(BUY-66091): alias domain/original_price in MCP get_deals SELECT [SEV-1]#332
BuyWhere wants to merge 1 commit into
mainfrom
fix/buy-66091-mcp-deals-domain-column

Conversation

@BuyWhere

@BuyWhere BuyWhere commented Aug 4, 2026

Copy link
Copy Markdown
Owner

SEV-1 fix — BUY-66091

Symptom: get_deals MCP tool returns column "domain" does not exist for every call (US first reported probe #338, 2026-08-04 06:28Z). Previously returned statement_timeout.

Root cause: handleGetDeals in api/src/routes/mcp.ts selected bare domain and original_price columns from products, but neither exists on that table:

  • domain is on merchants (not products)
  • original_price is a JSONB metadata key (not a column)

The regression was introduced in 1f84498 (BUY-64112, 2026-08-04), which flattened the deals query and dropped the aliasing that the REST /v1/products/deals handler (products.ts) and buildProduct (response.ts reads row.domain / row.original_price) both rely on.

Fix: alias the columns the same way the REST handler does:

- SELECT id, source, domain, url, title, price, original_price, ...
+ SELECT id, source AS domain, url, title, price,
+        (metadata->>'original_price')::numeric AS original_price, ...

Verification:

  • tsc --noEmit — 0 errors
  • Ran the corrected query against prod DB (US): returns real deals (Article.com, 84% discount) with domain + original_price populated
SELECT id, source AS domain, ..., (metadata->>'original_price')::numeric AS original_price,
       ..., discount_pct
FROM products
WHERE currency='USD' AND price > 0 AND is_active=true AND discount_pct >= 10 AND country_code='US'
ORDER BY discount_pct DESC NULLS LAST, updated_at DESC LIMIT 3;
 → 3 rows ✓

Deploy blocker: Railway deploy tokens are Unauthorized (BUY-56879) — agent cannot deploy. Needs merge + pipeline unblock, or human Railway redeploy of buywhere-api.

🤖 Generated with Claude Code

The MCP get_deals handler (handleGetDeals) selected bare `domain` and
`original_price` columns from `products`, but neither exists on that table:
`domain` lives on `merchants` and `original_price` is a JSONB metadata key.
This threw `column "domain" does not exist` for every get_deals call (SEV-1,
US first reported in probe #338 2026-08-04 06:28Z).

The regression was introduced in 1f84498 (BUY-64112), which flattened the
deals query and dropped the aliasing present in the REST /v1/products/deals
handler (products.ts) and buildProduct's expected keys (response.ts reads
row.domain / row.original_price).

Fix aliases them the same way the REST handler does:
  source AS domain
  (metadata->>'original_price')::numeric AS original_price

Verified the corrected query returns real US deals against prod DB.

Co-Authored-By: Claude <noreply@anthropic.com>
@BuyWhere
BuyWhere force-pushed the fix/buy-66091-mcp-deals-domain-column branch from 7fe9c1c to cdb65bb Compare August 4, 2026 18:36
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.

1 participant