Skip to main content
Glama
dynstat

MCP Server Demo

by dynstat

fetch_news_articles

Retrieve news articles from WorldNewsAPI by specifying search terms, date ranges, and result limits to gather relevant information.

Instructions

Fetches news articles from the WorldNewsAPI based on specified parameters
and returns them as a list of dictionaries.

Args:
    query_text (str): The text to search for in news articles
    earliest_date (str): Earliest publication date in YYYY-MM-DD format
    latest_date (str): Latest publication date in YYYY-MM-DD format
    max_results (int): Maximum number of results to return

Returns:
    list: A list of dictionaries containing article details

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
query_textNopolitics
earliest_dateNo2025-04-17
latest_dateNo2025-04-23
max_resultsNo

Implementation Reference

  • server.py:22-95 (handler)
    The @mcp.tool() decorated function implementing fetch_news_articles. It fetches news articles from WorldNewsAPI based on query_text, date ranges, and max_results, paginating results and formatting them into a dictionary list.
    @mcp.tool()
    def fetch_news_articles(
        query_text="politics",
        earliest_date="2025-04-17",
        latest_date="2025-04-23",
        max_results=5,
    ) -> dict:
        """
        Fetches news articles from the WorldNewsAPI based on specified parameters
        and returns them as a list of dictionaries.
    
        Args:
            query_text (str): The text to search for in news articles
            earliest_date (str): Earliest publication date in YYYY-MM-DD format
            latest_date (str): Latest publication date in YYYY-MM-DD format
            max_results (int): Maximum number of results to return
    
        Returns:
            list: A list of dictionaries containing article details
        """
        try:
            newsapi_instance = worldnewsapi.NewsApi(
                worldnewsapi.ApiClient(newsapi_configuration)
            )
    
            offset = 0
            all_results = []
            max_results = int(max_results)  # Ensure max_results is an integer
    
            while len(all_results) < max_results:
                request_count = min(
                    100, max_results - len(all_results)
                )  # request 100 or the remaining number of articles
    
                response = newsapi_instance.search_news(
                    text=query_text,
                    earliest_publish_date=earliest_date,
                    latest_publish_date=latest_date,
                    sort="publish-time",
                    sort_direction="desc",
                    # min_sentiment=-0.8,  # Ensuring this is a float
                    # max_sentiment=0.8,   # Ensuring this is a float
                    offset=offset,
                    number=request_count,
                )
    
                # print(f"Retrieved {len(response.news)} articles. Offset: {offset}/{max_results}. "
                #   f"Total available: {response.available}.")
    
                if len(response.news) == 0:
                    break
    
                all_results.extend(response.news)
                offset += 100
    
            # Convert API response objects to dictionaries
            articles_list = []
            for article in all_results[:max_results]:  # Use max_results here
                article_dict = {
                    "title": article.title,
                    "author": article.authors,
                    "url": article.url,
                    "text_preview": article.text[:80] + "..." if article.text else "",
                    "full_text": article.text,
                    "publish_date": article.publish_date,
                }
                articles_list.append(article_dict)
    
            return {"all_data": articles_list}
    
        except worldnewsapi.ApiException as e:
            # print(f"Exception when calling NewsApi->search_news: {e}")
            return {"error": str(e)}
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool fetches and returns data, implying a read-only operation, but doesn't mention critical behaviors like rate limits, authentication requirements, error handling, or pagination. For a tool with 4 parameters and no annotation coverage, this leaves significant gaps in understanding how it behaves in practice.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and appropriately sized. It starts with a clear purpose statement, followed by a parameter list with helpful details, and ends with return information. Every sentence adds value, though it could be slightly more concise by integrating the return statement into the opening sentence.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (4 parameters, no annotations, no output schema), the description is partially complete. It excels in parameter documentation but lacks behavioral context (e.g., error cases, performance limits) and doesn't detail the structure of returned dictionaries. Without an output schema, more information on return values would be beneficial for full completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds substantial meaning beyond the input schema, which has 0% description coverage. It explicitly documents all 4 parameters with their purposes and formats (e.g., 'earliest_date (str): Earliest publication date in YYYY-MM-DD format'), and specifies the return type. This fully compensates for the schema's lack of descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Fetches news articles from the WorldNewsAPI based on specified parameters and returns them as a list of dictionaries.' This specifies the verb (fetches), resource (news articles), and source (WorldNewsAPI). However, it doesn't differentiate from sibling tools (add, get_weather), which are unrelated to news fetching, so it doesn't need explicit sibling differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention any prerequisites, limitations, or scenarios where other tools might be more appropriate. The only context is the parameter list, which doesn't constitute usage guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

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/dynstat/mcp-demo'

If you have feedback or need assistance with the MCP directory API, please join our Discord server