get_deals
Retrieve current discounted PC component deals from meupc.net, including current price and lowest price in 90 days. Filter by category or page to find offers.
Instructions
Ofertas atuais com desconto no meupc.net, com preço atual e menor preço em 90 dias
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page | No | Número da página | |
| category | No | Filtrar por categoria (ex: 'processadores', 'placas-video', 'memorias') |
Implementation Reference
- src/tools/get-deals.ts:12-68 (handler)The main handler function that executes the 'get_deals' tool logic. It fetches deals from the meupc.net website, scrapes deal cards (name, price, discount, store), and returns results as JSON.
export async function getDeals(params: GetDealsParams): Promise<string> { const { page, category } = params; let url = `/ofertas?page=${page}`; if (category) { url += `&peca=${encodeURIComponent(category)}`; } const root = await fetchPage(url); const results: DealResult[] = []; root.querySelectorAll("div.card.is-fullheight").forEach(card => { const name = card.querySelector(".card-content h3.title a")?.text.trim() ?? ""; if (!name) return; const productUrl = card.querySelector(".card-content h3.title a")?.getAttribute("href") ?? ""; const image = card.querySelector("header.card-image figure img")?.getAttribute("src") ?? null; // Loja const store = card.querySelector(".card-content p.uppertitle")?.text.trim() || card.querySelector("header.card-image div.loja-img img")?.getAttribute("alt")?.trim() || null; // Desconto (tag vermelha, ex: "-50%") const discount = card.querySelector(".card-content span.tag.is-danger")?.text.trim() || null; // Preço atual const currentPriceText = card.querySelector(".card-content a.preco")?.text.trim() ?? ""; const currentPrice = parsePrice(currentPriceText) ?? 0; // Menor preço em 90 dias (no div.level.is-fullwidth) let oldPrice: number | null = null; card.querySelectorAll(".card-content div.level.is-fullwidth").forEach(lvl => { const text = lvl.text; if (text.includes("Menor") || text.includes("90 dias")) { const priceMatch = text.match(/R\$\s*([\d.,]+)/); if (priceMatch) { oldPrice = parsePrice(priceMatch[1]); } } }); results.push({ name, currentPrice, oldPrice, discount, store, url: absoluteUrl(productUrl), image: image ? absoluteUrl(image) : null, }); }); return JSON.stringify(results, null, 2); } - src/tools/get-deals.ts:5-8 (schema)Zod schema defining the input parameters for 'get_deals': page (positive int, default 1) and optional category string.
export const getDealsSchema = z.object({ page: z.number().int().positive().default(1).describe("Número da página"), category: z.string().optional().describe("Filtrar por categoria (ex: 'processadores', 'placas-video', 'memorias')"), }); - src/index.ts:43-50 (registration)Registration of the 'get_deals' tool on the MCP server, binding the schema and handler.
server.tool( "get_deals", "Ofertas atuais com desconto no meupc.net, com preço atual e menor preço em 90 dias", getDealsSchema.shape, async (params) => ({ content: [{ type: "text", text: await getDeals(params) }], }) ); - src/tools/get-deals.ts:1-3 (helper)Imports for zod schema validation, scraper utilities (fetchPage, absoluteUrl, parsePrice), and the DealResult type.
import { z } from "zod"; import { fetchPage, absoluteUrl, parsePrice } from "../scraper.js"; import type { DealResult } from "../types.js"; - src/types.ts:27-35 (helper)The DealResult type definition used as the return structure for deal data.
export interface DealResult { name: string; currentPrice: number; oldPrice: number | null; discount: string | null; store: string | null; url: string; image: string | null; }