get-acoes
Retrieve essential stock information by providing an array of stock symbols. Utilizes the Investidor10 MCP Server to fetch validated data via the Status Invest API.
Instructions
Buscar informações básicas de ações
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| stocks | Yes | Array of stock symbols |
Implementation Reference
- Registers the MCP tool 'get-acoes' with input schema for stocks array and a thin handler that calls the service and returns JSON as text content.this.server.tool( 'get-acoes', 'Buscar informações básicas de ações', { stocks: z.array(z.string()).describe('Array of stock symbols'), }, async ({ stocks }) => { const infos = await this.service.getStocksByHTML(stocks); return { content: [ { type: 'text', text: JSON.stringify(infos, null, 2), }, ], }; }, );
- Core handler logic for fetching stock data by HTML: loops over stocks, fetches HTML via apiService, parses info and indicators using helpers, formats JSON with code, name, price, variation, url, image, indicators.async getStocksByHTML(stocks: string[]) { const baseUrl = this.apiService.getUrlBase(); const data = []; for (const stock of stocks) { const stockData = await this.apiService.getStockByHTML(stock); if (!stockData) continue; const ticket = this.getStockInfo(stockData); const indicators = this.getAllIndicators(stockData); const jsonData = { code: ticket.code, name: ticket.name, price: ticket.price, variation: ticket.variation, url: `${baseUrl}/acoes/${ticket.code.toLowerCase()}`, image: `${baseUrl}${ticket.image}`, indicators, }; data.push(jsonData); } return data; }
- Helper to parse basic stock information (code, name, price, variation, image) from raw HTML using Cheerio selectors and parsing.private getStockInfo(html: string) { const $ = cheerio.load(html); const code = $('div[class=name-ticker] h1').text().trim(); const name = $('div[class=name-ticker] h2').text().trim(); const image = $('div[id=header_action] .logo img').attr('src'); const priceText = $('section[id=cards-ticker] .cotacao ._card-body') .text() .trim(); const price = parseFloat( priceText.replace('R$', '').replace('.', '').replace(',', '.'), ); const variationText = $('section[id=cards-ticker] .pl ._card-body') .text() .trim(); const variation = parseFloat( variationText.replace('R$', '').replace('.', '').replace(',', '.'), ); return { code, name, price, variation, image, }; }
- Helper to extract all valuation indicators from HTML table using Cheerio, mapping titles and parsed numeric values.private getAllIndicators(html: string) { const $ = cheerio.load(html); const indicatorContainer = $('div[id=table-indicators] div.cell'); if (indicatorContainer.length === 0) { return []; } if (indicatorContainer.length > 0) { const valuationIndicators = indicatorContainer.map((_, element) => { const title = $(element) .find('span:eq(0)') .text() .trim() .replace(' ', ' '); const valueText = $(element).find('div:eq(0)').text().trim(); const value = parseFloat( valueText.replace('R$', '').replace('.', '').replace(',', '.'), ); return { title, value, }; }); return valuationIndicators.toArray(); } }
- Zod schema defining input parameter 'stocks' as array of strings.{ stocks: z.array(z.string()).describe('Array of stock symbols'), },