DarkStar616/NewsAPI.AI_MCP_Server_v1.0
If you are the rightful owner of NewsAPI.AI_MCP_Server_v1.0 and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
MCP NewsAPI.ai Server is a production-ready Model Context Protocol server that integrates NewsAPI.ai and Event Registry for news article and event searches, as well as text analytics.
MCP NewsAPI.ai Server
A production-ready Model Context Protocol (MCP) server that exposes NewsAPI.ai / Event Registry as tools for searching news articles, events, and performing text analytics.
API Base: https://eventregistry.org/api/v1/
Features
- Article Search: Search news articles with filtering by date, language, source, sentiment, and more
- Event Search: Search news events with category, location, and date filtering
- Concept Suggestions: Get concept URIs for use in searches
- Text Analytics: Sentiment analysis, categorization, annotation, and similarity calculation
- Resilient: Automatic retry with exponential backoff and jitter for rate limits (429) and server errors (5xx)
- Type-Safe: Full TypeScript implementation with Zod validation
- Normalized Responses: Consistent pagination format across all search endpoints
Requirements
- Node.js 18 or higher
- NewsAPI.ai API key (get one here)
Setup
-
Clone or download this repository
-
Install dependencies:
npm install -
Configure your API key:
cp .env.example .envEdit
.envand add your NewsAPI.ai API key:NEWSAPI_AI_KEY=your_api_key_here
Usage
Development Mode
Run the server in development mode with hot reload:
npm run dev
Production Mode
Build and run the server:
npm run build
npm start
MCP Configuration
Add this server to your MCP client configuration (e.g., Claude Desktop):
{
"mcpServers": {
"newsapi": {
"command": "node",
"args": ["/path/to/mcp-newsapi-ai/dist/index.js"],
"env": {
"NEWSAPI_AI_KEY": "your_api_key_here"
}
}
}
}
For development, you can use tsx directly:
{
"mcpServers": {
"newsapi": {
"command": "npx",
"args": ["-y", "tsx", "/path/to/mcp-newsapi-ai/src/index.ts"],
"env": {
"NEWSAPI_AI_KEY": "your_api_key_here"
}
}
}
}
Available Tools
news.search_articles
Search for news articles with rich filtering options.
Example:
{
"query": "artificial intelligence",
"lang": "eng",
"from": "2024-01-01",
"to": "2024-12-31",
"sortBy": "date",
"page": 1,
"pageSize": 10
}
Parameters:
query(required): Search keywordlang: Language code (e.g., eng, spa, fra)from: Start date (YYYY-MM-DD)to: End date (YYYY-MM-DD)sourceUri: Array of source URIsconceptUri: Array of concept URIscategory: Array of category URIssentimentMin: Minimum sentiment (-1 to 1)sentimentMax: Maximum sentiment (-1 to 1)sortBy: Sort order (date, rel, sourceImportance)page: Page number (default: 1)pageSize: Results per page (1-100, default: 50)
Response:
{
"page": 1,
"pageSize": 10,
"total": 1234,
"results": [...]
}
news.search_events
Search for news events.
Example:
{
"query": "climate summit",
"lang": "eng",
"page": 1,
"pageSize": 20
}
Parameters:
query: Search keyword (optional)lang: Language codefrom: Start date (YYYY-MM-DD)to: End date (YYYY-MM-DD)conceptUri: Array of concept URIscategory: Array of category URIspage: Page number (default: 1)pageSize: Results per page (1-100, default: 50)
news.suggest_concepts
Get concept suggestions based on a text prefix.
Example:
{
"text": "climate",
"limit": 10
}
Parameters:
text(required): Text prefix to searchlimit: Max suggestions (1-20, default: 10)
news.text.sentiment
Analyze sentiment of text.
Example:
{
"text": "This is a great day!"
}
Response: Returns a sentiment score between -1 (negative) and 1 (positive).
news.text.categorize
Categorize text using a taxonomy.
Example:
{
"text": "Apple announces new iPhone with advanced AI features",
"taxonomy": "dmoz"
}
Parameters:
text(required): Text to categorizetaxonomy: Taxonomy to use (dmoz or iptc, default: dmoz)
news.text.annotate
Annotate text with semantic concepts.
Example:
{
"text": "Elon Musk's SpaceX launches new satellite"
}
Response: Returns detected entities and concepts with URIs.
news.text.similarity
Calculate semantic similarity between two texts.
Example:
{
"text1": "AI is transforming the world",
"text2": "Artificial intelligence changes everything"
}
Response: Returns a similarity score between 0 and 1.
Error Handling
The server provides structured error responses:
{
"error": "NewsApiError",
"status": 429,
"message": "API request failed with status 429: Rate limit exceeded"
}
Common errors:
- Missing API key: Check your
.envfile - 429 (Rate Limit): The server will automatically retry with backoff
- 5xx (Server Error): The server will automatically retry up to 3 times
- Validation Error: Check your input parameters against the schema
Rate Limits & Costs
NewsAPI.ai has different pricing tiers with varying rate limits. Please check your plan limits at newsapi.ai/pricing.
The server automatically handles rate limits with exponential backoff and jitter, retrying up to 3 times for 429 and 5xx errors.
Troubleshooting
Server won't start
Error: NEWSAPI_AI_KEY environment variable is not set
Solution: Make sure you have created a .env file with your API key, or set the environment variable when running the server.
Validation errors
Error: page=0 or other invalid parameters
Solution: Check the parameter constraints in the tool descriptions. For example, page must be >= 1, pageSize must be between 1-100.
429 Rate Limit Errors
The server automatically retries with exponential backoff. If you continue to see 429 errors after retries:
- Check your API plan limits
- Reduce the frequency of requests
- Consider upgrading your NewsAPI.ai plan
Network or timeout errors
The server retries network errors up to 3 times. If issues persist:
- Check your internet connection
- Verify NewsAPI.ai service status
- Check for firewall or proxy issues
Development
Project Structure
mcp-newsapi-ai/
├── src/
│ ├── index.ts # MCP server implementation
│ ├── client.ts # HTTP client with retry logic
│ ├── schema.ts # Zod validation schemas
│ ├── util.ts # Utility functions
│ └── tools/
│ ├── articles.ts # Article search
│ ├── events.ts # Event search
│ ├── concepts.ts # Concept suggestions
│ └── text.ts # Text analytics
├── package.json
├── tsconfig.json
└── README.md
Testing
To test the server manually:
- Start the server:
npm run dev - The server communicates via stdio (standard input/output)
- Use an MCP client like Claude Desktop to interact with the tools
Security
- API keys are read from environment variables only
- No secrets are logged or printed to console
- No personally identifiable information (PII) is logged
License
MIT