search-stock-news
Retrieve filtered stock-related news by specifying a stock symbol, company name, and criteria like max results, search depth, and relevance score. Access tailored financial updates quickly.
Instructions
Search for stock-related news using Tavily API
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| companyName | Yes | Company name (e.g., Apple Inc.) | |
| maxResults | No | Maximum number of results to return | |
| minScore | No | Minimum relevance score threshold | |
| searchDepth | No | Search depth level | |
| symbol | Yes | Stock symbol (e.g., AAPL) |
Implementation Reference
- src/tools/search-stock-news.ts:7-73 (handler)Core handler function that performs multi-template Tavily searches for stock news, filters and sorts results by score, and returns grouped results.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; };
- src/services/tools.ts:10-29 (registration)Registers the tool in the tools array with name, description, Zod input parameters schema, and execute wrapper that calls the imported handler.{ name: "search-stock-news", description: "Search for stock-related news using Tavily API", parameters: z.object({ symbol: z.string().describe("Stock symbol (e.g., AAPL)"), companyName: z.string().describe("Company name (e.g., Apple Inc.)"), maxResults: z.number().optional().describe("Maximum number of results to return"), searchDepth: z.enum(["basic", "advanced"]).optional().describe("Search depth level"), minScore: z.number().optional().describe("Minimum relevance score threshold") }), execute: async (args) => { const results = await searchStockNews( args.symbol, args.companyName, args.maxResults || 10, args.minScore || 0.4 ); return JSON.stringify(results, null, 2); } },
- src/types/tools.ts:25-31 (schema)TypeScript interface defining the structure of individual stock news search results used in the handler's output.export interface StockNewsResult { title: string; url: string; content: string; publishedDate: string; score: number; }