Skip to main content
Glama

Search Stock News MCP Server

search-stock-news.ts1.69 kB
"use strict"; import { tavily } from '@tavily/core'; import { getConfig } from '../config/env'; import { StockNewsResult } from '../types/tools'; export default async ( symbol: string, companyName: string, days: number, minScore: number ): Promise<Array<{ searchQuery: string; results: StockNewsResult[]; }>> => { const config = getConfig(); const { apiKey, maxResults, searchDepth, queryTemplates, includeDomains, excludeDomains } = config; // Initialize Tavily client const tvly = tavily({ apiKey }); const allResults = []; // Process each template for (const template of queryTemplates) { const searchQuery = template .replace('{symbol}', symbol) .replace('{company_name}', companyName); try { const response = await tvly.search(searchQuery, { searchDepth, topics: ['news'], timeRange: "d", days, maxResults, includeDomains, excludeDomains }); // Transform and filter the results const filteredResults = response.results .map((result) => ({ title: result.title, url: result.url, content: result.content, publishedDate: result.publishedDate, score: result.score, })) .filter(result => result.score >= minScore) .sort((a, b) => b.score - a.score); allResults.push({ searchQuery, results: filteredResults }); } catch (error) { console.error(`Error searching with template: ${template}`, error); // Continue with other templates even if one fails continue; } } return allResults; };

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Cognitive-Stack/search-stock-news-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server