mcp_newsnow_server

zhanggc2019/mcp_newsnow_server

3.2

If you are the rightful owner of mcp_newsnow_server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

MCP NewNow Server is a Model Context Protocol-based news server that provides multi-platform news data retrieval capabilities.

Tools
4
Resources
0
Prompts
0

MCP NewNow Server

一个基于 Model Context Protocol (MCP) 的热点新闻服务器,提供多平台新闻数据获取功能。

功能特性

  • 🔥 支持多个热门平台的新闻获取
  • 🚀 基于 FastMCP 框架,性能优异
  • 🌐 支持网络和本地部署
  • 📊 提供丰富的工具和资源接口
  • 🔧 灵活的配置选项

支持的新闻源

平台标识符中文名称
bilibili-hot-searchb站、哔哩哔哩哔哩哔哩热搜
zhihu知乎知乎热榜
weibo微博、新浪微博微博热搜
toutiao头条、今日头条今日头条
douyin抖音抖音热点
tieba贴吧、百度贴吧百度贴吧
wallstreetcn华尔街见闻华尔街见闻
thepaper澎湃、澎湃新闻澎湃新闻
cls-hot财联社、财联财联社热点
xueqiu雪球雪球
kuaishou快手快手热点
coolapk-酷安
github-trending-today-GitHub 今日趋势
linuxdo-hot-LinuxDo 热榜

安装部署

环境要求

  • Python 3.12+
  • uv 包管理器(推荐)或 pip

方法一:使用 uv(推荐)

  1. 安装 uv(如果尚未安装)

    # Windows
    powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
    
    # macOS/Linux
    curl -LsSf https://astral.sh/uv/install.sh | sh
    
  2. 克隆项目

    git clone <repository-url>
    cd mcp_newsnow_server
    
  3. 安装依赖

    uv sync
    
  4. 运行服务器

    # 开发模式(stdio 传输)
    uv run python -m mcp_newsnow_server
    
    # 或者直接运行
    uv run python cli.py
    
    # 网络服务模式(SSE 传输)
    uv run python server.py
    

方法二:使用 pip

  1. 克隆项目

    git clone <repository-url>
    cd mcp_newsnow_server
    
  2. 创建虚拟环境

    python -m venv venv
    
    # Windows
    venv\Scripts\activate
    
    # macOS/Linux
    source venv/bin/activate
    
  3. 安装依赖

    pip install -e .
    
  4. 运行服务器

    # 开发模式
    python cli.py
    
    # 网络服务模式
    python server.py
    

方法三:Docker 部署(推荐生产环境)

  1. 创建 Dockerfile

    FROM python:3.12-slim
    
    WORKDIR /app
    
    # 安装 uv
    RUN pip install uv
    
    # 复制项目文件
    COPY . .
    
    # 安装依赖
    RUN uv sync --frozen
    
    # 暴露端口
    EXPOSE 8000
    
    # 启动服务
    CMD ["uv", "run", "python", "server.py"]
    
  2. 构建和运行

    # 构建镜像
    docker build -t mcp-newsnow-server .
    
    # 运行容器
    docker run -p 8000:8000 mcp-newsnow-server
    

配置选项

环境变量

  • NEWS_API_URL: 新闻API的基础URL(默认:https://newsnow.busiyi.world

示例配置

# 设置自定义API地址
export NEWS_API_URL="https://your-custom-api.com"

# 运行服务器
uv run python server.py

使用方法

MCP 工具

服务器提供以下工具:

  1. get_newsnow(source: str) - 获取指定源的新闻
  2. get_multi_news(sources: list[str]) - 获取多个源的新闻
  3. get_all_news() - 获取所有配置源的新闻
  4. list_sources() - 列出所有可用的新闻源

MCP 资源

  • news://headlines - 获取最新头条新闻
  • news://sources - 获取可用新闻源列表

MCP 提示词

  • news_summary(source: str) - 生成特定源的新闻总结提示
  • multi_news_summary(sources: str) - 生成多源新闻总结提示

使用示例

# 获取知乎热榜
await get_newsnow("知乎")

# 获取多个平台新闻
await get_multi_news(["微博", "知乎", "b站"])

# 获取所有平台新闻
await get_all_news()

# 列出可用源
await list_sources()

开发

开发环境设置

# 克隆项目
git clone <repository-url>
cd mcp_newsnow_server

# 安装开发依赖
uv sync --group dev --group lint

# 运行测试
uv run pytest

# 代码格式化
uv run ruff format

# 代码检查
uv run ruff check

项目结构

mcp_newsnow_server/
├── __init__.py          # 包初始化
├── __main__.py          # 模块入口点
├── cli.py               # 命令行接口
├── main.py              # 主程序入口
├── server.py            # MCP 服务器实现
├── pyproject.toml       # 项目配置
├── README.md            # 项目文档
├── uv.lock              # 依赖锁定文件
└── .gitignore           # Git 忽略文件

添加新的新闻源

  1. server.py 中的 sources_list 添加新源标识符
  2. SOURCE_MAPPINGS 中添加中文名称映射
  3. 确保API端点支持该新闻源

API 接口

服务器在网络模式下运行时,默认监听 0.0.0.0:8000,支持以下传输方式:

  • stdio: 标准输入输出(用于MCP客户端集成)
  • sse: Server-Sent Events(用于Web集成)

故障排除

常见问题

  1. 连接超时

    • 检查网络连接
    • 确认API地址可访问
    • 调整超时设置(当前为300秒)
  2. 未知新闻源

    • 使用 list_sources() 查看支持的源
    • 检查源名称拼写
    • 参考源名称映射表
  3. 依赖安装失败

    • 确保Python版本 >= 3.12
    • 使用国内镜像源:uv sync --index-url https://mirrors.aliyun.com/pypi/simple/

日志调试

# 启用详细日志
export PYTHONPATH=.
python -c "
import logging
logging.basicConfig(level=logging.DEBUG)
from server import mcp
mcp.run(transport='stdio')
"

许可证

本项目采用开源许可证,具体请查看 LICENSE 文件。

贡献

欢迎提交 Issue 和 Pull Request!

  1. Fork 本项目
  2. 创建特性分支 (git checkout -b feature/AmazingFeature)
  3. 提交更改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 开启 Pull Request

更新日志

v0.1.0

  • 初始版本发布
  • 支持14个主流新闻平台
  • 提供完整的MCP工具、资源和提示词接口
  • 支持多种部署方式