MCP ExplorerExplorer

Fastmcp Example

@paquino11on 10 months ago
2 MIT
FreeCommunity
AI Systems
A simple MCP server that fetches and formats news articles using NewsData.io API.

Overview

What is Fastmcp Example

fastMCP-example is a simple MCP (Model Context Protocol) server built with FastMCP that fetches news articles using the NewsData.io API. It provides tools and resources to retrieve and format the latest news articles.

Use cases

Use cases include fetching news articles for specific topics, generating news summaries for newsletters, and integrating news data into applications for enhanced user engagement.

How to use

To use fastMCP-example, install the required dependencies, set up a virtual environment, and run the MCP server using the provided commands. You can also test it in development mode and attach it to the Claude Desktop app for enhanced functionality.

Key features

Key features include a Fetch News Tool for retrieving articles based on keywords, languages, and countries; a Structured Output Prompt for generating user-friendly lists of articles; and support for various metadata such as languages, countries, and categories.

Where to use

fastMCP-example can be used in various fields such as journalism, content curation, and research, where real-time news retrieval and formatting are essential.

Content

NewsData MCP Server

A simple MCP (Model Context Protocol) server built with FastMCP that fetches news articles using the NewsData.io API. This server provides tools, prompts, and resources to retrieve and format the latest news articles.
You can read the full Medium story at:

Features

  • Fetch News Tool: Retrieve news articles based on a keyword, language, and country.
  • Structured Output Prompt: Generate a user-friendly list of news articles with titles and links.
  • Supported Resources: Provide metadata such as supported languages, countries, and categories.

Getting Started

Prerequisites

  • Python 3.10 or later
  • uv (required for deploying MCP servers)
  • An API key from NewsData.io. Sign up for a free account to generate your API key.

Installation

  1. Install uv:

    brew install uv
    
  2. Set up a virtual environment:

    python3 -m venv venv
    source venv/bin/activate
    
  3. Install FastMCP and other dependencies:

    uv pip install fastmcp requests
    
  4. Clone or copy the project code into a file named newsdata_mcp.py.

Usage

  1. Run the MCP server:

    uv run fastmcp install --with uvicorn --with requests newsdata_mcp.py
    
  2. Test the MCP server in development mode:

    uv run fastmcp dev --with uvicorn --with requests newsdata_mcp.py
    
  3. Attach the MCP server to the Claude Desktop app for testing tools, prompts, and resources.

Tools, Prompts, and Resources

Tools

fetch_news

Fetch news articles based on a keyword, language, and country.

Parameters:

  • keyword (str): Search term for news articles.
  • language (str): Language code (default: en).
  • country (str): Country code (optional).

Example Usage in Claude:

“Tell me the news related to Artificial Intelligence in the United States.”


Prompts

fetch_news_prompt

Formats fetched news articles into a structured list of titles and links.

Example Usage in Claude:

  1. Attach the fetch_news_prompt tool from the MCP server.
  2. Fill in:
    • Keyword: Blockchain
    • Language: en
    • Country: us
  3. Submit and receive a .json file with the news articles.

Resources

newsapi://languages

Returns a list of supported language codes.

newsapi://countries

Returns a list of supported country codes.

newsapi://categories

Returns a list of supported news categories.

Example Usage in Claude:
Attach any resource to receive a .json file with metadata.


Code Overview

Key Functions

  1. fetch_news: The main tool for retrieving news articles from the NewsData.io API.
  2. fetch_news_prompt: Formats the fetched articles into a readable list with titles and links.
  3. Resources:
    • get_supported_languages: Supported language codes.
    • get_supported_countries: Supported country codes.
    • get_news_categories: Supported news categories.

References

Enjoy building with MCP and FastMCP!

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers