Explore the MCP News API Server for programmatic news search and top headlines access using MCP protocol
The MCP News API Server is an MCP (Model Context Protocol) infrastructure that provides programmatic access to news data via the News API. By leveraging this server, developers can seamlessly integrate real-world news articles into their AI applications, enhancing their capabilities and providing users with up-to-date, relevant information. This README outlines the setup process, available tools, error handling mechanisms, and integration strategies for various MCP clients.
The core capability of this MCP News API Server lies in its ability to expose endpoints from the News API to any compatible AI application or runner through the Model Context Protocol. Developers can utilize these endpoints to fetch news articles based on specific criteria like keywords, sources, and more. The server supports two primary tools: search_articles
for detailed searches and get_top_headlines
for fetching trending headlines.
Search Articles (search_articles):
q
: Keywords or phrases to search within article titles and bodies.sources
, domains
, excludeDomains
: Constraints on specific sources, domains, and exclusions.from
& to
: Date filters for the articles' publish date ranges.language
: The language filter (default: all).sortBy
: Sorting order of results (relevancy
, popularity
, or publishedAt
).pageSize
& page
: Pagination control.Get Top Headlines (get_top_headlines):
q
, sources
, category
, language
, country
: Filters for the data source and language.pageSize
& page
: Controls pagination.The server implements the Model Context Protocol to enable seamless integration with various MCP clients. Key components include environment variable configuration, command-line execution of the build, and running through an MCP runner or directly.
This section details the architecture and protocol implementation of the MCP News API Server:
The server reads its NEWSAPI_KEY
from an environment variable. This is essential for authenticating requests to the News API. Developers can set this key via the following command in Bash/Zsh:
export NEWSAPI_KEY="YOUR_API_KEY"
For direct execution, set up the server using these commands:
Clone the repository or ensure you are in the project directory.
Install dependencies:
npm install
Build the server:
npm run build
Run the server:
node build/index.js
npm run start
stdio
transport:"mcp-newsapi": {
"transportType": "stdio",
"command": "node",
"args": [
"/path/to/mcp-newsapi/build/index.js"
],
"environment": {
"NEWSAPI_KEY": "YOUR_API_KEY"
}
}
The server exposes two main tools through MCP:
Search Articles:
export const search_articles = z.object({
q: z.string().optional(),
sources: z.string().optional(),
domains: z.string().optional(),
excludeDomains: z.string().optional(),
from: z.date().optional(),
to: z.date().optional(),
language: z.string().optional(),
sortBy: z.enum(['relevancy', 'popularity', 'publishedAt']).optional().default('relevancy'),
pageSize: z.number().min(1).max(100).default(20),
page: z.number().min(1)
})
Get Top Headlines:
export const get_top_headlines = z.object({
q: z.string().optional(),
sources: z.string().optional(),
category: z.enum(
['business', 'entertainment', 'general', 'health', 'science', 'sports', 'technology']
).optional(),
language: z.string().optional(),
country: z.string().optional(),
pageSize: z.number().min(1).max(100).default(20),
page: z.number().min(1)
})
To get started, follow these steps:
git clone https://github.com/your-repo/mcp-newsapi-server.git
npm install
npm run build && npm start
This MCP News API Server can be seamlessly integrated into various developer workflows to enhance AI applications with real-world data:
A news app can use the get_top_headlines
tool to fetch and display top headlines based on user preferences like categories (business, technology) and languages.
AI agents powered by MCP can query articles using keywords (q
) or sources (sources
) parameters. This capability allows contextual responses in chatbots and voice assistants.
This server is compatible with various MCP clients, including:
The following compatibility matrix showcases the status of integration for each client:
MCP Client | Claude Desktop | Continue | Cursor |
---|---|---|---|
Resources | ✅ | ✅ | ❌ |
Tools | ✅ | ✅ | ✅ |
Prompts | ✅ | ✅ | ❌ |
The server is designed to provide consistent performance across different environments. Here’s a compatibility matrix:
Environment | Node.js v18+ | npm v7+ |
---|---|---|
Supported? | 😎 | 😎 |
For advanced configuration, developers can customize the environment variables or modify the package.json
scripts to suit their needs. Additionally, security best practices such as rate limiting and token validation should be considered.
{
"mcpServers": {
"MCP-NewsAPI-server-v2": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-newsapi"],
"env": {
"NEWSAPI_KEY": "your-api-key"
}
}
}
}
search_articles
tool?A: Use the following input parameters:
{
q: "technology",
sources: ["techcrunch"],
from: new Date("2023-10-01"),
to: new Date(),
sortBy: "relevancy",
pageSize: 50,
page: 1
}
A: Yes, by setting the language
parameter in both tools.
The MCP News API Server provides a robust platform for integrating real-world news data into various AI applications using the Model Context Protocol. By leveraging this infrastructure, developers can enhance their applications with up-to-date, relevant content. For detailed integration steps and advanced configurations, refer to the README and documentation provided with the server.
Learn to connect to MCP servers over HTTP with Python SDK using SSE for efficient protocol communication
Next-generation MCP server enhances documentation analysis with AI-powered neural processing and multi-language support
Build a local personal knowledge base with Markdown files for seamless AI conversations and organized information.
Integrate AI with GitHub using MCP Server for profiles repos and issue creation
Python MCP client for testing servers avoid message limits and customize with API key
Explore MCP servers for weather data and DigitalOcean management with easy setup and API tools