get_top_headlines
Fetch top headlines by specific country and category using a unified API tool. Streamline news aggregation and stay informed with targeted updates.
Instructions
Get top headlines by country and category
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | No | ||
| country | No |
Implementation Reference
- src/apis/news/newsapi.ts:77-82 (handler)The handler function for the get_top_headlines tool. It checks for the API key configuration and delegates to the NewsApiClient's topHeadlines method with parsed arguments.async get_top_headlines(args: Record<string, unknown>) { if (!cfg.newsApiKey) throw new Error("NEWS_API_KEY is not configured"); const country = args.country ? String(args.country) : undefined; const category = args.category ? String(args.category) : undefined; return client.topHeadlines(country, category); },
- src/apis/news/newsapi.ts:40-50 (registration)Local registration of the get_top_headlines tool within the News API module, defining name, description, and input schema.{ name: "get_top_headlines", description: "Get top headlines by country and category", inputSchema: { type: "object", properties: { country: { type: "string" }, category: { type: "string" }, }, }, },
- src/tools/register.ts:25-25 (registration)Central registration invocation that includes the get_top_headlines tool via the News API registration.registerNewsApi(),
- src/apis/news/newsapi.ts:12-17 (helper)Supporting method in NewsApiClient that performs the actual API request to fetch top headlines, invoked by the tool handler.topHeadlines(country?: string, category?: string) { return this.request("/v2/top-headlines", { headers: { Authorization: `Bearer ${this.apiKey}` }, query: { country, category }, }); }