使用说明
Reddit MCP服务器
用于Reddit集成的综合模型上下文协议(MCP)服务器。该服务器使AI代理能够通过标准化的界面以编程方式与Reddit交互。
🎯 特性
此MCP服务器为Reddit交互提供了6个强大的工具:
- fetch帖子 -从任何子版块获取热门帖子
- 获取评论 -从特定帖子中检索评论
- 搜索帖子 -在subreddit中搜索帖子
- post评论 -在Reddit帖子上发表评论
- 获取子目录信息 -获取详细的subreddit信息
- postToSubreddit -创建新的文本或链接帖子
🚀 快速开始
先决条件
- Reddit API凭据 -创建一个Reddit应用程序https://www.reddit.com/prefs/apps
- 码头工人 -用于集装箱化部署
- 环境变量:
REDDIT_CLIENT_ID-您的Reddit应用客户端IDREDDIT_CLIENT_SECRET-你的Reddit应用客户端密码REDDIT_USERNAME-您的Reddit用户名REDDIT_PASSWORD-您的Reddit密码REDDIT_USER_AGENT-用户代理字符串(可选,默认为“mcp-reddit-agent/0.1”)
安装和设置
方法一:使用Docker(推荐)
Linux/macOS:
# Clone the repository
git clone https://github.com/KrishnaRandad2023/mcp-reddit
cd mcp-reddit
# Build the Docker image
make build
# Set environment variables
export REDDIT_CLIENT_ID="your_client_id"
export REDDIT_CLIENT_SECRET="your_client_secret"
export REDDIT_USERNAME="your_username"
export REDDIT_PASSWORD="your_password"
# Test the server
make test
Windows(PowerShell/批处理):
# Clone the repository
git clone https://github.com/<my-org>/reddit-mcp
cd reddit-mcp
# Build the Docker image
.\build.ps1 build
# Or use simple batch file: .\build-win.bat build
# Set environment variables
$env:REDDIT_CLIENT_ID = "your_client_id"
$env:REDDIT_CLIENT_SECRET = "your_client_secret"
$env:REDDIT_USERNAME = "your_username"
$env:REDDIT_PASSWORD = "your_password"
# Test the server
.\build.ps1 test
# Or: .\build-win.bat test
方法2:使用任务命令(Docker MCP)
# Create server instance
task create -- --category social https://github.com/<my-org>/reddit-mcp \
-e REDDIT_CLIENT_ID=your_client_id \
-e REDDIT_USERNAME=your_username \
-e REDDIT_USER_AGENT="mcp-reddit-agent/0.1" \
-e REDDIT_CLIENT_SECRET=your_client_secret \
-e REDDIT_PASSWORD=your_password
# Build the tools
task build -- --tools reddit-mcp
# Import catalog
task catalog -- reddit-mcp
docker mcp catalog import $PWD/catalogs/reddit-mcp/catalog.yaml
方法3:直接运行Docker
docker run --rm -i \
-e REDDIT_CLIENT_ID="your_client_id" \
-e REDDIT_CLIENT_SECRET="your_client_secret" \
-e REDDIT_USERNAME="your_username" \
-e REDDIT_PASSWORD="your_password" \
-e REDDIT_USER_AGENT="mcp-reddit-agent/0.1" \
mcp/reddit-mcp:latest
🛠️ 工具参考
fetch帖子
从subreddit获取热门帖子。
论据:
subreddit(string,必填)-子版块的名称limit(整数,可选)-要获取的帖子数量(1-100,默认值:10)
例子:
{
"subreddit": "technology",
"limit": 5
}
获取评论
获取特定Reddit帖子的评论。
论据:
post_id(字符串,必填)-Reddit帖子ID(不带't3_'前缀)
例子:
{
"post_id": "abc123"
}
搜索帖子
在subreddit中搜索帖子。
论据:
subreddit(string,必填)-子版块的名称query(字符串,必填)-搜索查询limit(整数,可选)-结果数(1-100,默认值:10)
例子:
{
"subreddit": "programming",
"query": "python tutorial",
"limit": 10
}
post评论
在Reddit上发表评论。
论据:
post_id(字符串,必填)-Reddit帖子ID(不带't3_'前缀)comment_text(字符串,必填)-要发布的评论文本
例子:
{
"post_id": "abc123",
"comment_text": "Great post! Thanks for sharing."
}
获取子目录信息
获取有关subreddit的详细信息。
论据:
subreddit(string,必填)-子版块的名称
例子:
{
"subreddit": "MachineLearning"
}
postToSubreddit
在subreddit中创建新帖子。
论据:
subreddit(string,必填)-子版块的名称title(字符串,必填)-帖子标题content(字符串,可选)-文本帖子的帖子内容url(字符串,可选)-链接帖子的URL
注: 要么 content 或 url 必须提供。
示例(文本帖子):
{
"subreddit": "test",
"title": "My Test Post",
"content": "This is a test post created via MCP."
}
示例(链接帖子):
{
"subreddit": "technology",
"title": "Interesting Article",
"url": "https://example.com/article"
}
🔧 发展
从源头构建
# Clone repository
git clone https://github.com/<my-org>/reddit-mcp
cd reddit-mcp
# Install dependencies
pip install -r requirements.txt
# Run locally (requires environment variables)
python src/server.py
可用的构建命令
Linux/macOS(Makefile):
make help # Show help
make build # Build Docker image
make test # Run tests
make catalog # Generate MCP catalog
make publish # Prepare for registry submission
make clean # Clean up Docker images
Windows(PowerShell/批处理):
.\build.ps1 help # Show help
.\build.ps1 build # Build Docker image
.\build.ps1 test # Run tests
.\build.ps1 catalog # Generate MCP catalog
.\build.ps1 publish # Prepare for registry submission
.\build.ps1 clean # Clean up Docker images
# Or use simple batch files:
.\build-win.bat build # Build Docker image
.\build-win.bat test # Run tests
.\build-win.bat catalog # Generate MCP catalog
.\build-win.bat clean # Clean up Docker images
项目结构
reddit-mcp/
├── src/
│ └── server.py # Main MCP server implementation
├── catalogs/
│ └── reddit-mcp/
│ └── catalog.yaml # MCP catalog definition
├── Dockerfile # Docker container definition
├── requirements.txt # Python dependencies
├── server.json # MCP server metadata
├── tools.json # Tool definitions
├── Makefile # Build automation
├── *.sh # Shell scripts for automation
└── README.md # This file
🔐 安全和身份验证
Reddit API设置
- 首选https://www.reddit.com/prefs/apps
- 点击“创建应用程序”或“创建另一个应用程序”
- 选择“脚本”作为应用程序类型
- 记下您的客户端ID(在应用程序名称下)和客户端密码
- 使用您的凭据设置环境变量
环境变量
| 变量 | 必填 | 机密 | 描述 |
|---|---|---|---|
REDDIT_CLIENT_ID |
✅ | ❌ | Reddit应用程序客户端ID |
REDDIT_CLIENT_SECRET |
✅ | ✅ | Reddit应用程序客户端机密 |
REDDIT_USERNAME |
✅ | ❌ | 您的Reddit用户名 |
REDDIT_PASSWORD |
✅ | ✅ | 您的Reddit密码 |
REDDIT_USER_AGENT |
❌ | ❌ | 用户代理字符串(默认值:“mcp-reddit-agent/0.1”) |
安全最佳实践
- 安全地存储机密(使用环境变量,而不是硬编码值)
- 使用专用的Reddit帐户进行自动化
- 遵循Reddit的API利率限制指南
- 尊重subreddit规则和Reddit服务条款
📋 使用示例
Claude桌面配置示例
{
"mcpServers": {
"reddit": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"-e",
"REDDIT_CLIENT_ID=your_client_id",
"-e",
"REDDIT_CLIENT_SECRET=your_client_secret",
"-e",
"REDDIT_USERNAME=your_username",
"-e",
"REDDIT_PASSWORD=your_password",
"-e",
"REDDIT_USER_AGENT=mcp-reddit-agent/0.1",
"mcp/reddit-mcp:latest"
]
}
}
}
对话示例
获取最新帖子:
“获取来自r/technology的前5个帖子”
搜索和评论:
“搜索r/programming中的Python教程,并对顶部结果发表评论”
亚涡分析:
“获取有关r/MachineLearning的信息,并向我展示有关变压器的最新帖子”
🚀 部署和提交
Docker注册表提交
此服务器已准备好提交到官方的Docker MCP注册表:
-
在本地构建和测试:
Linux/macOS:
make build make test窗户:
.\build.ps1 build .\build.ps1 test -
推送到Docker Hub:
docker tag mcp/reddit-mcp:latest your-dockerhub-username/reddit-mcp:latest docker push your-dockerhub-username/reddit-mcp:latest -
使用您的存储库详细信息更新server.json
-
提交给MCP注册表:
# Using mcp-publisher CLI mcp-publisher init mcp-publisher login github mcp-publisher publish
MCP注册表要求✅
此服务器满足所有Docker MCP注册表要求:
- ✅ Docker标签:
io.modelcontextprotocol.server.name="reddit-mcp" - ✅ STDIO传输:使用stdio进行MCP通信
- ✅ 环境变量:正确配置的secrets和env变量
- ✅ 服务器元数据:使用工具定义完成server.json
- ✅ 文档:全面的README和使用示例
- ✅ 类别:社会(按规定)
注册表元数据
- 名字:
io.github.my-org/reddit-mcp - 类别:社会
- Docker镜像:
mcp/reddit-mcp - 描述:用于API交互的Reddit MCP服务器:获取帖子、搜索、评论和提交
- 图标: https://www.redditinc.com/assets/images/site/reddit-logo.png
- 仓库: https://github.com//reddit mcp
🤝 贡献
- 复刻仓库
- 创建要素分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'Add amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
📄 许可证
此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。
🆘 支持
- 问题: GitHub问题
- 讨论: GitHub讨论
- 文档: MCP文件
- Reddit API: Reddit API文档
⚠️ 利率限制和最佳实践
- Reddit API有费率限制-尊重它们
- 在批量操作请求之间使用适当的延迟
- 关注Reddit API服务条款
- 尊重社区并遵守subreddit规则
- 尽可能考虑使用只读操作
已准备好提交MCP注册表 🚀
此服务器已完全配置,并准备按照所有贡献指南提交给官方的Docker MCP注册表。