MCP Reddit摘要服务器
基于FastAPI的MCP(模型上下文协议)服务器,可自动获取、汇总Reddit内容并将其直接传递给Slack。该系统使用Azure OpenAI创建选定子版块中热门帖子的简明摘要,将其格式化为有组织的PDF报告,并与您的团队共享。
✨ 特性
- 🔍 智能Reddit监控:按主题(人工智能、网络安全、编程)获取热门帖子或指定自定义子版块
- 🧠 AI驱动的摘要:使用Azure OpenAI压缩冗长的Reddit讨论
- 📝 干净的Markdown格式:使用subreddit组织的帖子生成结构良好的摘要
- 📄 专业PDF报告:使用自定义CSS将markdown转换为带样式的PDF
- 🔔 Slack集成:自动将摘要传递到团队的Slack频道
- ⏱️ 预定交货:按每日或自定义时间表配置自动摘要
- 🧩 模块化架构:通过新功能或集成轻松扩展
MCPHub认证: Reddit摘要-omendra02 MCP服务器
先决条件
- Python 3.8+
- Reddit API证书
- Azure OpenAI API访问
- Slack工作空间与机器人集成
环境设置
创建一个 .env 项目根目录中的文件,包含以下变量:
# Reddit API
REDDIT_CLIENT_ID=your_client_id
REDDIT_CLIENT_SECRET=your_client_secret
REDDIT_USERNAME=your_username
REDDIT_PASSWORD=your_password
USER_AGENT=your_user_agent
# Azure OpenAI
AZURE_OPENAI_KEY=your_openai_key
AZURE_OPENAI_API_VERSION=your_api_version
AZURE_OPENAI_ENDPOINT=your_endpoint
AZURE_OPENAI_DEPLOYMENT=your_deployment_name
# Slack
SLACK_BOT_TOKEN=your_slack_bot_token
SLACK_CHANNEL_ID=your_channel_id安装
# Clone the repository
git clone https://github.com/yourusername/mcp-reddit-digest.git
cd mcp-reddit-digest
# Install dependencies
pip install -r requirements.txt
# Start the server
uvicorn mcp_server.main:app --reload🔧 用法
API终点
GET /-健康检查端点POST /mcp/hello-用于验证连接的测试端点POST /mcp/reddit-按主题(人工智能、网络安全、技术更新等)生成摘要POST /mcp/reddit/subreddit-从自定义子版块生成摘要
请求示例
按主题生成摘要:
curl -X POST "http://localhost:8000/mcp/reddit" \
-H "Content-Type: application/json" \
-d '{"input": "ai"}'为特定的子版块生成摘要:
curl -X POST "http://localhost:8000/mcp/reddit/subreddit" \
-H "Content-Type: application/json" \
-d '{"input": "MachineLearning, artificial, IndiaTech"}'⚙️ 配置
预定摘要
系统配置为运行计划摘要。编辑 scheduler.py 调整时间:
# For production (runs daily at 9 AM)
scheduler.add_job(scheduled_reddit_digest, 'cron', hour=9, minute=0)
# For testing (runs every minute)
scheduler.add_job(scheduled_reddit_digest, 'interval', minutes=1)主题映射
默认主题到subreddit的映射在中定义 reddit_fetcher.py.根据需要添加或修改映射:
TOPIC_SUBREDDITS = {
"tech update": ["technology", "technews", "IndiaTech", "developersIndia"],
"ai": ["MachineLearning", "ArtificialIntelligence", "Singularity", "artificial"],
# Add new mappings here
}🔄 项目结构
mcp_server/
├── core/
│ ├── slack_notifiers.py # Slack integration
│ ├── summarizer.py # Azure OpenAI integration
│ └── utils.py # Helper functions
├── tools/
│ ├── hello_tool.py # Simple test tool
│ └── reddit_digest/ # Reddit digest functionality
│ ├── markdown_generator.py
│ ├── pdf_generator.py
│ ├── reddit_fetcher.py
│ ├── style.css # PDF styling
│ └── tool.py # Main digest logic
├── main.py # FastAPI application
├── mcp.json # Tool definitions
└── scheduler.py # Automated tasks
