fetch_list_of_goodnews
Retrieve positive news headlines filtered by category, using sentiment analysis to identify uplifting stories from NewsAPI.
Instructions
Fetch a list of headlines and return only top-ranked news based on positivity.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | No | all |
Implementation Reference
- src/mcp_goodnews/server.py:14-34 (handler)The `fetch_list_of_goodnews` tool handler which fetches headlines based on categories and then uses `GoodnewsRanker` to filter for positive news.
@mcp.tool() async def fetch_list_of_goodnews( category: Literal["all", "science", "health", "technology"] = "all", ) -> str: """Fetch a list of headlines and return only top-ranked news based on positivity.""" # make request to top-headlines newsapi articles = [] if category == "all": categories = ["science", "health", "technology"] else: categories = [category] for cat in categories: top_articles = await get_top_headlines(cat) articles.extend(top_articles) # rank the retrieved handlines and get only most positive articles ranker = GoodnewsRanker(model_name="command-a-03-2025") goodnews = await ranker.rank_articles(articles) return goodnews # type: ignore[no-any-return] - src/mcp_goodnews/server.py:14-14 (registration)Tool registration using the `@mcp.tool()` decorator in the `FastMCP` server instance.
@mcp.tool()