Sponsored by Deepsite.site

MCP News API Server

Created By
matteoantoci9 months ago
An MCP server exposing News API endpoints for searching and retrieving news articles. Provides reliable, easy-to-use tools for integrating news data into applications and workflows, with robust error handling and secure API key management.
Content

MCP News API Server

A Model Context Protocol (MCP) server that exposes endpoints from the News API (https://newsapi.org) to search for and retrieve news articles. This server allows programmatic access to news data via the MCP protocol.

Prerequisites

  • Node.js (v18 or later recommended)
  • npm (comes with Node.js)
  • A News API key (get one from https://newsapi.org)
  • (Optional) MCP-compatible client or runner (e.g., VSCode extension, CLI)

Setup

  1. Clone the repository or ensure you are in the project directory.

  2. Install dependencies:

    npm install
    
  3. Build the server:

    npm run build
    

    This will create a build directory with the compiled JavaScript code.

  4. Set your News API Key: The server reads the API key from the NEWSAPI_KEY environment variable. Set this variable in your environment before running the server. Example (Bash/Zsh):

    export NEWSAPI_KEY="YOUR_API_KEY"
    

    Replace "YOUR_API_KEY" with your actual News API key.

Running the Server

  • Directly: Ensure the NEWSAPI_KEY environment variable is set, then run:

    node build/index.js
    

    or, if you have a start script:

    npm run start
    
  • Via MCP runner: Configure your MCP client to run the server using stdio transport. You will also need to configure the environment variable for the API key within your MCP runner's settings. Example MCP settings entry:

    "mcp-newsapi": {
      "transportType": "stdio",
      "command": "node",
      "args": [
        "/path/to/mcp-newsapi/build/index.js"
      ],
      "environment": {
        "NEWSAPI_KEY": "YOUR_API_KEY"
      }
      // ... other optional settings ...
    }
    

    Replace "YOUR_API_KEY" with your actual News API key.

Available Tools

The server exposes the following tools via MCP, corresponding to News API endpoints:

search_articles

  • Description: Searches for news articles using the News API "Everything" endpoint.
  • Input:
    • q (string, required): Keywords or phrases to search for in the article title and body.
    • sources (string, optional): A comma-separated string of identifiers for the news sources or blogs you want headlines from.
    • domains (string, optional): A comma-separated string of domains (e.g. bbc.co.uk, techcrunch.com) to search within.
    • excludeDomains (string, optional): A comma-separated string of domains (e.g. bbc.co.uk, techcrunch.com) to exclude from the search.
    • from (string, optional): A date and optional time for the oldest article allowed. Format: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS (e.g. 2024-01-01 or 2024-01-01T10:00:00).
    • to (string, optional): A date and optional time for the newest article allowed. Format: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS.
    • language (string, optional): The 2-letter ISO 639-1 code of the language you want to get headlines for. Possible options: ar, de, en, es, fr, he, it, nl, no, pt, ru, sv, ud, zh. Default: all languages returned.
    • sortBy (enum: 'relevancy', 'popularity', 'publishedAt', optional): The order to sort the articles in. Possible options: relevancy, popularity, publishedAt. Default: relevancy.
    • pageSize (integer, optional, default 100): The number of results to return per page (request). 20 is the default, 100 is the maximum.
    • page (integer, optional, default 1): Use this to page through the results if the total results found is greater than the pageSize.
  • Output:
    • An object containing status, totalResults, and an array of articles with details like source, author, title, description, URL, image URL, published date, and content.

get_top_headlines

  • Description: Fetches top news headlines using the News API "Top Headlines" endpoint.
  • Input:
    • q (string, optional): Keywords or phrases to search for in the article title and body.
    • sources (string, optional): A comma-separated string of identifiers for the news sources or blogs you want headlines from.
    • category (enum: 'business', 'entertainment', 'general', 'health', 'science', 'sports', 'technology', optional): The category you want to get headlines for. Possible options: business, entertainment, general, health, science, sports, technology.
    • language (string, optional): The 2-letter ISO 639-1 code of the language you want to get headlines for. Possible options: ar, de, en, es, fr, he, it, nl, no, pt, ru, sv, ud, zh. Default: all languages returned.
    • country (string, optional): The 2-letter ISO 3166-1 country code of the country you want to get headlines for. Possible options: ae, ar, at, au, be, bg, br, ca, ch, cn, co, cu, cz, de, eg, fr, gb, gr, hk, hu, id, ie, il, in, it, jp, kr, lt, lv, ma, mx, my, ng, nl, no, nz, ph, pl, pt, ro, rs, ru, sa, se, sg, si, sk, th, tr, tw, ua, us, ve, za. Default: all countries returned.
    • pageSize (integer, optional, default 100): The number of results to return per page (request). 20 is the default, 100 is the maximum.
    • page (integer, optional, default 1): Use this to page through the results if the total results found is greater than the pageSize.
  • Output:
    • An object containing status, totalResults, and an array of articles with details like source, author, title, description, URL, image URL, published date, and content.

Error Handling

The server attempts to provide meaningful error messages based on the News API response. If an API call fails, the tool will throw an error with details about the failure, including the News API error message and code if available.

Extending

To add more News API endpoints as tools, create a new TypeScript file in src/tools/, define its input schema using Zod, implement the handler function to call the News API SDK, and export the tool definition. Then, import and register the new tool in src/tools/index.ts.

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Y GuiA web-based graphical interface for AI chat interactions with support for multiple AI models and MCP (Model Context Protocol) servers.
Playwright McpPlaywright MCP server
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Serper MCP ServerA Serper MCP Server
Amap Maps高德地图官方 MCP Server
ChatWiseThe second fastest AI chatbot™
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
WindsurfThe new purpose-built IDE to harness magic
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Tavily Mcp
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
DeepChatYour AI Partner on Desktop
CursorThe AI Code Editor
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.