news
Search news articles across multiple engines (Google, Bing, DuckDuckGo, Yahoo, HackerNews) with customizable filters for sites, time range, and optional full-page crawling.
Instructions
News search tool
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query, be simple and concise | |
| max_results | No | Maximum number of results to return | |
| search_service | No | Specify the news engine to use. Choose based on your specific needs | bing |
| crawl_results | No | Number of results to crawl for full webpage content, useful when search result summaries are insufficient for complex queries | |
| include_sites | No | List of sites to include in search. Only use when you need special results from sites not available in search_service | |
| exclude_sites | No | List of sites to exclude from search. Only use when you need to explicitly filter out specific domains from results | |
| time_range | No | Time range for search results, only use when specific time constraints are required |
Implementation Reference
- src/tools/news.ts:10-45 (handler)The main handler function for the 'news' tool. Validates args via isValidNewsArgs, calls the /news API endpoint via makeRequest, and returns the results as JSON content or an error message.
export async function handleNews(args: unknown, apiKey?: string) { if (!isValidNewsArgs(args)) { throw new McpError( ErrorCode.InvalidParams, "Invalid news search arguments" ); } log("Processing news search with query:", (args as NewsArgs).query); try { const response = await makeRequest<NewsResponse>( API_CONFIG.ENDPOINTS.NEWS, args, apiKey ); return { content: [{ type: "text", mimeType: "application/json", text: JSON.stringify(response.results, null, 2) }] }; } catch (error) { log("News search error:", error); return { content: [{ type: "text", mimeType: "text/plain", text: `News API error: ${formatError(error)}` }], isError: true }; } } - src/tools/index.ts:57-107 (schema)Tool registration/definition for the 'news' tool. Defines name ('news'), description, and inputSchema with properties: query (required string), max_results, search_service (enum of search engines), crawl_results, include_sites, exclude_sites, and time_range.
export const NEWS_TOOL: Tool = { name: "news", description: "News search tool", inputSchema: { type: "object", properties: { query: { type: "string", description: "Search query, be simple and concise" }, max_results: { type: "number", description: "Maximum number of results to return", default: 10 }, search_service: { type: "string", description: "Specify the news engine to use. Choose based on your specific needs", default: "bing", enum: ["google", "bing", "duckduckgo", "yahoo", "hackernews"] }, crawl_results: { type: "number", description: "Number of results to crawl for full webpage content, useful when search result summaries are insufficient for complex queries", default: 0 }, include_sites: { type: "array", items: { type: "string" }, description: "List of sites to include in search. Only use when you need special results from sites not available in search_service", default: [] }, exclude_sites: { type: "array", items: { type: "string" }, description: "List of sites to exclude from search. Only use when you need to explicitly filter out specific domains from results", default: [] }, time_range: { type: "string", description: "Time range for search results, only use when specific time constraints are required", enum: ["day", "month", "year"] } }, required: ["query"] } }; - src/tools/handlers.ts:31-32 (registration)Registration of the 'news' tool in the dispatch switch statement. When toolName matches NEWS_TOOL.name ('news'), it calls handleNews(args, apiKey).
case NEWS_TOOL.name: return await handleNews(args, apiKey); - src/types.ts:180-239 (schema)Type definitions for the news tool: NewsArgs interface (query, max_results, search_service, crawl_results, include_sites, exclude_sites, time_range), NewsResult interface, NewsResponse interface, and the isValidNewsArgs type guard function that validates all fields.
export interface NewsArgs { query: string; max_results?: number; search_service?: NewsService; crawl_results?: number; include_sites?: string[]; exclude_sites?: string[]; time_range?: TimeRange; } export function isValidNewsArgs(args: unknown): args is NewsArgs { if (typeof args !== 'object' || args === null) { return false; } const { query, max_results, search_service, crawl_results, include_sites, exclude_sites, time_range } = args as NewsArgs; if (typeof query !== 'string' || query.trim().length === 0) { return false; } if (max_results !== undefined && (typeof max_results !== 'number' || max_results < 1 || max_results > 50)) { return false; } if (search_service !== undefined) { const validServices = Object.values(NewsService); if (!validServices.includes(search_service)) { return false; } } if (crawl_results !== undefined && (typeof crawl_results !== 'number' || crawl_results < 0)) { return false; } if (include_sites !== undefined && (!Array.isArray(include_sites) || !include_sites.every(site => typeof site === 'string'))) { return false; } if (exclude_sites !== undefined && (!Array.isArray(exclude_sites) || !exclude_sites.every(site => typeof site === 'string'))) { return false; } if (time_range !== undefined) { const validTimeRanges = Object.values(TimeRange); if (!validTimeRanges.includes(time_range)) { return false; } } return true; - src/config.ts:40-49 (helper)API configuration including the BASE_URL, DEFAULT_QUERY ('latest news in the world'), and the NEWS endpoint path ('/news') used by the news handler to make API requests.
BASE_URL: 'https://api.search1api.com', DEFAULT_QUERY: 'latest news in the world', ENDPOINTS: { SEARCH: '/search', CRAWL: '/crawl', SITEMAP: '/sitemap', NEWS: '/news', REASONING: '/v1/chat/completions', TRENDING: '/trending' }