Repository navigation
feat(web): add read-only Rate Shopping MCP server and /llms.txt - #1870
Conversation
Add stateless Streamable HTTP JSON-RPC 2.0 MCP endpoint (/api/mcp) with 5 Zod-4 validated read-only tools across 22 Vietnamese retail platforms, self-hosted discovery routes (/llms.txt and /.well-known/mcp.json), proxy/robots bypass rules, trilingual /developers docs (vi, en, cs), and comprehensive security and data-truth regression tests. Closes #1866
There was a problem hiding this comment.
If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.
Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 30 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
PO acceptance: merge at 6ccc307 |
Closes #1866
Claimant: antigravity:8ad3645f-874c-4469-b6c5-68df6e156303
Summary
Implements Package 8A Feature F4: a stateless, read-only Streamable HTTP Model Context Protocol (MCP) server (
POST /api/mcp), self-hosted AI discovery endpoints (GET /llms.txt,GET /.well-known/mcp.json), non-locale routing/crawler rules, and trilingual developer documentation acrossvi,en, andcswith zero database migrations and zero external LLM/infrastructure costs.Key Changes
apps/web/src/server/rate/mcp.ts,apps/web/src/app/api/mcp/route.ts):POST /api/mcp(initialize,notifications/initialized,ping,tools/list,tools/call) with backward-compatible protocol negotiation (2025-06-18,2025-03-26,2024-11-05),GET/DELETE405 Method Not Allowed(Allow: POST, OPTIONS), andOPTIONS204CORS preflight.Content-Type: application/json(415), RFC 9110Acceptquality-weight validation (406), bounded stream reader<= 16384bytes (413/-32600with early stream cancellation), batch array rejection, prototype-pollution key rejection (__proto__,constructor,prototype), safe-integer JSON-RPCidchecks (including pre-parse> 53-bitinteger rejection),.toWellFormed()UTF-16 sanitization, per-IPBoundedSlidingWindowRateLimiter(60req/min general +30req/min URL audits,429+Retry-After), and sanitized error messages that never leak internal PostgREST/Supabase details.tools/list), backed exclusively by existingwithRateDataCacheBFF readers (limit <= 10):search_verified_catalog: Cross-category search withminPriceVnd/maxPriceVndandprice_asc/price_descevaluated against verified in-stock plausible offer floors (excluding bait-price and sold-out traps).get_22_store_offers_and_price_truth: In-stock offers across 22 Vietnamese stores, historical floor/median truth, Deal Radar signal, Bayesian rating, 6-axis Review Trust Model v2 summary, non-synthetic crawl timestamps, and#1376/#1465risk-score masking (nullwhen unanalysed ordosafe_risk_known: false).compare_devices_by_use_case: Side-by-side comparison of 2 to 4 same-category slugs (including Item/variant resolution and deduplication), 10-group hardware specs, and 5-criterion JReviews scores normalized over shared rankable criteria.audit_listing_url: Canonicalizes tracking/affiliate query parameters before cache lookup, validates public URLs across the 22 supported Vietnamese platforms orrate.vn, and returns catalog match, 5-level fake-discount verdict, accessory gatekeeper check, and seller risk scores.get_genuine_deals: Verified below-median and multi-store floor deals (limit <= 10) with category, platform, official-mall, and budget filters.canonical_citation_url(https://rate.vn/...) and ISO-8601 freshness timestamps (observed_at/price_observed_at) on every returned tool payload and item.apps/web/src/app/llms.txt/route.ts,apps/web/src/app/.well-known/mcp.json/route.ts,apps/web/src/proxy.ts,apps/web/src/app/robots.ts):GET /llms.txt(text/plain; charset=utf-8) andGET /.well-known/mcp.json(application/json) as static assets withCache-Control: public, s-maxage=3600, stale-while-revalidate=86400and MCP discovery CORS headers.src/proxy.tswithout breaking thenext.config.mjsCSP header complement (csp.test.ts), and explicitly allows/llms.txt,/.well-known/mcp.json, and/api/mcpin productionrobots.ts.apps/web/src/app/[locale]/developers/page.tsx,apps/web/locales/{vi,en,cs}.json):/api/mcp,/.well-known/mcp.json,/llms.txt, all 5 MCP tools, and copy-ready.mcp.json/.cursor/mcp.json/DOSClaw+claude_desktop_config.json(mcp-remote) and JSON-RPCcurlsnippets with 100%vi,en,csparity and WCAG 2.2 AA dark-mode contrast (btn-outline-dark).Fresh-Context Review
researchsubagents with disjoint review scopes:audit_listing_url, stream reader abort handling,MCP-Protocol-Versionnegotiation oninitialize,Accept: application/json;q=0handling, safe-integer /> 53-bitJSON-RPCidchecks, andprice_asc/minPriceVnd/maxPriceVndpost-plausibility filtering). All fixed and covered by regression tests.live_listing/ sold-out points inprice_observed_at, Item-level compare deduplication and shared-criteria weight normalization,rate.vndotted-slug validation,btn-outline-darkdark-mode AA contrast on/developers, exact 10ProductSpecificationsgroup keys in/llms.txt, and natural Vietnamese"AI agent"phrasing). All fixed and covered by regression tests.Verification
pnpm --filter @repo/web test(all 56 test suites passed, including newmcp.test.ts,developers-copy.test.ts,proxy.test.ts,csp.test.ts, andcore-rate-architecture.test.ts)pnpm typecheck(6/6 packages passed)pnpm lint(4/4 packages passed, 0 warnings)pnpm build(5/5 packages passed;/.well-known/mcp.jsonand/llms.txtstatically prerendered,/api/mcpdynamic)📌 TL;DR
This PR introduces a stateless, read-only Model Context Protocol (MCP) server and
/llms.txtendpoint to expose verified price data from 22 Vietnamese retail platforms to AI agents. It includes the core API routes, middleware updates to bypass locale routing for these discovery paths, comprehensive localization, and a dedicated documentation section on the developer page.🎯 Type of Change
🔍 Changes Walkthrough
apps/web/src/server/rate/mcp.tsapps/web/src/app/api/mcp/route.tsPOST(JSON-RPC),OPTIONS(CORS), and rejectingGET/DELETEfor the MCP endpoint.apps/web/src/app/.well-known/mcp.json/route.tsapps/web/src/app/llms.txt/route.tsapps/web/src/proxy.tsisDirectNonLocalePathhelper to bypass locale rewriting and session refresh for/api/mcp,/llms.txt, and/.well-knownpaths.apps/web/src/app/robots.tsapps/web/src/app/[locale]/developers/page.tsxapps/web/locales/{en,vi,cs}.jsonapps/web/src/server/rate/__tests__/mcp.test.tsapps/web/src/lib/__tests__/proxy.test.tsapps/web/src/lib/__tests__/developers-copy.test.tsapps/web/package.jsonmcp.test.tsto the test execution pipeline.📊 Architectural Flow
sequenceDiagram participant AI as AI Agent / LLM participant Proxy as Next.js Proxy (Middleware) participant MCP as /api/mcp (POST) participant LLM as /llms.txt (GET) participant WK as /.well-known/mcp.json (GET) participant DB as Data Layer (Supabase/Cache) Note over AI, WK: Discovery Phase AI->>WK: GET /.well-known/mcp.json Proxy->>WK: Pass-through (No locale rewrite) WK-->>AI: MCP Descriptor (JSON) AI->>LLM: GET /llms.txt Proxy->>LLM: Pass-through (No locale rewrite) LLM-->>AI: Markdown Context Guide Note over AI, DB: Interaction Phase AI->>MCP: POST JSON-RPC (tools/call) Proxy->>MCP: Pass-through (No session refresh) MCP->>MCP: Validate Rate Limit & Body Size MCP->>DB: Query Verified Offers/Prices DB-->>MCP: Raw Data MCP->>MCP: Filter (Exclude bait/sold-out) & Format MCP-->>AI: JSON-RPC Response (with citations)