Skip to main content
Glama

Search Stock News MCP Server

search-stock-news.test.ts2.08 kB
import searchStockNews from "../search-stock-news"; jest.mock("../../config/env", () => ({ getConfig: jest.fn().mockReturnValue({ apiKey: "test-api-key", maxResults: 20, searchDepth: "basic", minScore: 0.4, queryTemplates: [ '{symbol} ({company_name}) latest stock price movements' ], includeDomains: ['https://test.com'], excludeDomains: ['https://exclude.com'] }), })); jest.mock('@tavily/core', () => ({ tavily: jest.fn().mockReturnValue({ search: jest.fn().mockResolvedValue({ results: [ { title: "Test News", url: "https://test.com/news", content: "Test content", publishedDate: "2024-01-01", score: 0.8 } ] }) }) })); describe("searchStockNews", () => { beforeEach(() => { jest.clearAllMocks(); }); it("should search for stock news with default configuration", async () => { const result = await searchStockNews("AAPL", "Apple Inc."); expect(result).toHaveLength(1); expect(result[0].template).toBe('{symbol} ({company_name}) latest stock price movements'); expect(result[0].results).toHaveLength(1); expect(result[0].results[0].title).toBe("Test News"); }); it("should handle custom configuration", async () => { const customConfig = { maxResults: 10, searchDepth: "advanced" as const, minScore: 0.5, queryTemplates: ["Custom template"], includeDomains: ["https://custom.com"], excludeDomains: ["https://exclude-custom.com"] }; const result = await searchStockNews("AAPL", "Apple Inc.", customConfig); expect(result).toHaveLength(1); expect(result[0].template).toBe("Custom template"); }); it("should handle search errors gracefully", async () => { const mockTavily = require('@tavily/core').tavily; mockTavily.mockReturnValueOnce({ search: jest.fn().mockRejectedValue(new Error("Search failed")) }); const result = await searchStockNews("AAPL", "Apple Inc."); expect(result).toHaveLength(0); }); });

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