使用说明
新闻API MCP服务器
A. 模型上下文协议 (MCP)服务器,提供新闻搜索和标题检索,使用 新闻API。按国家和类别获取头条新闻,或在数千个来源中搜索文章。
安装
安装时使用 篮子:
mpak install @nimblebraininc/newsapi
配置
从获取API密钥 新闻API,然后配置:
mpak config set @nimblebraininc/newsapi api_key YOUR_API_KEY
克劳德代码
claude mcp add newsapi -- mpak run @nimblebraininc/newsapi
克劳德桌面
添加到您的 claude_desktop_config.json:
{
"mcpServers": {
"newsapi": {
"command": "mpak",
"args": ["run", "@nimblebraininc/newsapi"]
}
}
}
看 mpak注册表页 获取完整安装选项。
工具
get_top_headlines
按国家和类别获取头条新闻。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
query |
string |
没有 | 要在文章标题中搜索的关键字 |
country |
string |
无 | 2个字母的国家代码(默认值: "us") |
category |
string |
否 | 以下之一: "business", "entertainment", "general", "health", "science", "sports", "technology" |
page_size |
integer |
否 | 结果数,最大100(默认值: 10) |
示例调用:
{
"name": "get_top_headlines",
"arguments": {
"country": "us",
"category": "technology",
"page_size": 5
}
}
示例响应:
{
"articles": [
{
"title": "New AI breakthrough announced",
"description": "Researchers have developed a new approach...",
"url": "https://example.com/article",
"source": "TechCrunch",
"author": "Jane Smith",
"published_at": "2026-02-13T10:00:00Z"
}
],
"total_results": 5
}
搜索_新闻
搜索所有来源的新闻文章。 注: 仅返回过去30天内的文章(NewsAPI免费层限制)。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
query |
string |
是 | 搜索关键字或短语 |
sources |
string |
否 | 逗号分隔的源ID(例如。 "bbc-news,cnn") |
domains |
string |
否 | 逗号分隔的域(例如。 "bbc.co.uk,techcrunch.com") |
from_date |
string |
否 | 最旧的文章日期,ISO 8601(例如。 "2026-01-01") |
to_date |
string |
否 | 最新文章日期,ISO 8601(例如。 "2026-01-31") |
language |
string |
无 | 2个字母的语言代码(默认值: "en") |
sort_by |
string |
没有 | "relevancy", "popularity",或 "publishedAt" (默认值: "publishedAt") |
page_size |
integer |
否 | 结果数,最大100(默认值: 10) |
示例调用:
{
"name": "search_news",
"arguments": {
"query": "artificial intelligence",
"sort_by": "relevancy",
"page_size": 5
}
}
示例响应:
{
"query": "artificial intelligence",
"articles": [
{
"title": "The State of AI in 2026",
"description": "A comprehensive look at how AI has evolved...",
"url": "https://example.com/ai-2026",
"source": "Wired",
"author": "John Doe",
"published_at": "2026-02-10T14:30:00Z",
"content": "First 200 characters of the article content..."
}
],
"total_results": 127
}
快速开始
本地开发
git clone https://github.com/NimbleBrainInc/mcp-newsapi.git
cd mcp-newsapi
# Install dependencies
uv sync
# Set API key
cp .env.example .env
# Edit .env with your API key
# Run the server (stdio mode)
uv run python -m mcp_newsapi.server
服务器支持HTTP传输:
- 健康检查:
GET /health - MCP端点:
POST /mcp
发展
# Install with dev dependencies
uv sync --group dev
# Run all checks (format, lint, typecheck, unit tests)
make check
# Run unit tests
make test
# Run with coverage
make test-cov
关于
NewsAPI MCP服务器发布于 mpak注册表 并由 敏捷大脑.mpak是一个开放的注册表 模型上下文协议 服务器。
许可证
麻省理工学院