GNews API MCP Server
Provides access to the GNews API for searching news articles and getting top headlines, with OAuth2 authentication and support for advanced query syntax.
README
GNews API MCP Server
A Model Context Protocol (MCP) server built on FastAPI that provides access to the GNews API for fetching news articles and headlines. The server now runs as a remote MCP server on top of a FastAPI app, supporting HTTP transport and modern authentication middleware. This enables AI applications to search for news, get trending headlines, and access comprehensive news data through a standardized interface with robust security.
Features
🔧 Tools
search_news- Search for news articles using keywords with advanced filteringget_top_headlines- Get trending news articles by category
Installation & Setup
- Clone or download this repository
git clone <repository-url>
cd gnews-server
- Install dependencies
pip install -r requirements.txt
# or using uv
uv sync
- Get a GNews API key
- Visit gnews.io
- Sign up for a free account
- Get your API key from the dashboard
- Set up environment variables
export GNEWS_API_KEY="your_api_key_here"
- Configure authentication
- The server uses OAuth2 Bearer token authentication via ScaleKit. See
auth.pyfor details. - Set required ScaleKit environment variables in your config (see
config.py).
Usage
Running the Server
The server now runs as a FastAPI application with MCP protocol support and authentication middleware.
Development mode:
python main.py
Using uv:
uv run main.py
The server exposes MCP endpoints over HTTP, including a well-known OAuth-protected resource metadata endpoint at:
/.well-known/oauth-protected-resource/mcp
Integration with Claude Desktop & Other MCP Clients
Add to your Claude Desktop configuration file (claude_desktop_config.json):
{
"mcpServers": {
"gnews": {
"command": "python",
"args": ["/absolute/path/to/gnews-server/main.py"],
"env": {
"GNEWS_API_KEY": "your_api_key_here"
}
}
}
}
The server supports the standard MCP protocol and can be used with any MCP-compatible client. Use HTTP transport for remote connections, or stdio for local development.
Integration with Other MCP Clients
The server supports the standard MCP protocol and can be used with any MCP-compatible client. Use the stdio transport for local connections.
Authentication
The server uses OAuth2 Bearer token authentication via ScaleKit. All requests (except for well-known endpoints) require a valid token in the Authorization header:
Authorization: Bearer <access_token>
Token validation and required scopes are handled by the AuthMiddleware (see auth.py). Unauthorized requests will receive a structured error response.
API Reference
Tools
search_news
Search for news articles using specific keywords.
Parameters:
q(required): Search keywords with support for logical operatorslang(optional): Language code (2 letters, e.g., "en", "es")country(optional): Country code (2 letters, e.g., "us", "gb")max(optional): Number of articles to return (1-100, default: 10)in(optional): Search in specific fields: "title", "description", "content"nullable(optional): Allow null values for: "description", "content", "image"from(optional): Filter from date (ISO 8601 format)to(optional): Filter until date (ISO 8601 format)sortby(optional): Sort by "publishedAt" or "relevance"page(optional): Page number for pagination
Example queries:
- "Apple iPhone"
- "Apple AND iPhone"
- "Apple OR Microsoft"
- "(Apple AND iPhone) OR Microsoft"
- "Apple NOT iPhone"
- "Apple iPhone 15" AND NOT "Apple iPhone 14"
Returns:
{
"success": true,
"query": "search terms",
"totalArticles": 150,
"articles": [
{
"title": "Article Title",
"description": "Article description...",
"content": "Full article content...",
"url": "https://example.com/article",
"image": "https://example.com/image.jpg",
"publishedAt": "2024-01-01T12:00:00Z",
"source": {
"name": "Source Name",
"url": "https://source.com"
}
}
],
"parameters_used": {...}
}
get_top_headlines
Get current trending news articles by category.
Parameters:
category(optional): News category (default: "general")- Available: "general", "world", "nation", "business", "technology", "entertainment", "sports", "science", "health"
lang(optional): Language codecountry(optional): Country codemax(optional): Number of articles (1-100, default: 10)nullable(optional): Allow null valuesfrom(optional): Filter from dateto(optional): Filter until dateq(optional): Additional search keywordspage(optional): Page number
Returns: Similar structure to search_news with category-specific trending articles.
Resources
gnews://supported-languages
Returns a formatted list of all supported language codes and names.
gnews://supported-countries
Returns a formatted list of all supported country codes and names.
gnews://query-syntax
Returns comprehensive documentation on search query syntax including logical operators, phrase search, and examples.
Prompts
create_news_search_prompt
Creates a structured prompt for comprehensive news research on a specific topic.
Parameters:
topic(required): The topic to researchdays_back(optional): Number of days to look back (default: 7)
Advanced Query Syntax
The GNews API supports sophisticated search queries:
Logical Operators
- AND:
Apple AND iPhone(both terms must appear) - OR:
Apple OR Microsoft(either term can appear) - NOT:
Apple NOT iPhone(exclude articles with "iPhone")
Phrase Search
- Exact phrases:
"Apple iPhone 15"(exact sequence)
Operator Precedence
- OR has higher precedence than AND
- Use parentheses for grouping:
(Apple AND iPhone) OR Microsoft
Complex Examples
- Intel AND (i7 OR i9)
- (Windows 7) AND (Windows 10)
- "breaking news" AND NOT "rumor"
- (Tesla OR "electric vehicle") AND NOT "stock price"
Supported Languages
Arabic (ar), Chinese (zh), Dutch (nl), English (en), French (fr), German (de), Greek (el), Hindi (hi), Italian (it), Japanese (ja), Malayalam (ml), Marathi (mr), Norwegian (no), Portuguese (pt), Romanian (ro), Russian (ru), Spanish (es), Swedish (sv), Tamil (ta), Telugu (te), Ukrainian (uk)
Supported Countries
Australia (au), Brazil (br), Canada (ca), China (cn), Egypt (eg), France (fr), Germany (de), Greece (gr), Hong Kong (hk), India (in), Ireland (ie), Italy (it), Japan (jp), Netherlands (nl), Norway (no), Pakistan (pk), Peru (pe), Philippines (ph), Portugal (pt), Romania (ro), Russian Federation (ru), Singapore (sg), Spain (es), Sweden (se), Switzerland (ch), Taiwan (tw), Ukraine (ua), United Kingdom (gb), United States (us)
Error Handling & Security
- Authentication: All endpoints (except well-known) require a valid OAuth2 Bearer token. Invalid or missing tokens result in a 401 Unauthorized response.
- API Key Validation: Checks for required environment variable
- Parameter Validation: Validates language codes, country codes, and numeric ranges
- Network Error Handling: Graceful handling of connection issues
- API Error Responses: Clear error messages from GNews API
Error responses include:
{
"success": false,
"error": "Error description",
"query": "original query",
"parameters_used": {...}
}
Rate Limits
GNews API has rate limits based on your subscription plan:
- Free Plan: 100 requests per day
- Paid Plans: Higher limits available
The server will return appropriate error messages if rate limits are exceeded.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- GNews API Documentation: https://docs.gnews.io/
- MCP Specification: https://modelcontextprotocol.io/
- Issues: Please report bugs and feature requests through the repository's issue tracker
Example Usage in Claude
After setting up the server, you can use it in Claude Desktop or any MCP client:
"Search for recent news about artificial intelligence developments in the last 3 days"
"Get the top technology headlines from the United States"
"Find news articles about climate change, but exclude articles about politics"
"Show me breaking news about electric vehicles from European sources"
The server will automatically use the appropriate tools and provide structured, comprehensive news results, with authentication and security enforced.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。