返回市场
MCP-Reddit服务器

MCP-Reddit服务器

作者:KrishnaRandad20237 星标更新:2025-11-04

项目介绍

Reddit MCP Server

一个全面的模型上下文协议(MCP)服务器,用于与Reddit集成。此服务器使AI代理能够通过标准化接口以编程方式与Reddit进行交互。

🎯 功能

此MCP服务器提供了6个强大的工具来与Reddit进行交互:

  • fetchPosts - 从任何子版块获取热门帖子
  • getComments - 获取特定帖子的评论
  • searchPosts - 在子版块中搜索帖子
  • postComment - 在Reddit帖子上发布评论
  • getSubredditInfo - 获取详细的子版块信息
  • postToSubreddit - 创建新的文本或链接帖子

🚀 快速开始

先决条件

  1. Reddit API凭证 - 在 https://www.reddit.com/prefs/apps 创建一个Reddit应用
  2. Docker - 用于容器化部署
  3. 环境变量
    • REDDIT_CLIENT_ID - 您的Reddit应用客户端ID
    • REDDIT_CLIENT_SECRET - 您的Reddit应用客户端密钥
    • REDDIT_USERNAME - 您的Reddit用户名
    • REDDIT_PASSWORD - 您的Reddit密码
    • REDDIT_USER_AGENT - 用户代理字符串(可选,默认为 "mcp-reddit-agent/0.1")

安装与设置

方法1:使用Docker(推荐)

Linux/macOS:

# 克隆仓库
git clone https://github.com/KrishnaRandad2023/mcp-reddit
cd mcp-reddit

# 构建Docker镜像
make build

# 设置环境变量
export REDDIT_CLIENT_ID="your_client_id"
export REDDIT_CLIENT_SECRET="your_client_secret"
export REDDIT_USERNAME="your_username"
export REDDIT_PASSWORD="your_password"

# 测试服务器
make test

Windows (PowerShell/Batch):

# 克隆仓库
git clone https://github.com/<my-org>/reddit-mcp
cd reddit-mcp

# 构建Docker镜像
.\build.ps1 build
# 或使用简单的批处理文件: .\build-win.bat build

# 设置环境变量
$env:REDDIT_CLIENT_ID = "your_client_id"
$env:REDDIT_CLIENT_SECRET = "your_client_secret"
$env:REDDIT_USERNAME = "your_username"
$env:REDDIT_PASSWORD = "your_password"

# 测试服务器
.\build.ps1 test
# 或: .\build-win.bat test

方法2:使用任务命令(Docker MCP)

# 创建服务器实例
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

# 构建工具
task build -- --tools reddit-mcp

# 导入目录
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

🛠️ 工具参考

fetchPosts

从子版块获取热门帖子。

参数:

  • subreddit (字符串,必需) - 子版块名称
  • limit (整数,可选) - 要获取的帖子数量(1-100,默认值:10)

示例:

{
  "subreddit": "technology",
  "limit": 5
}

getComments

获取特定Reddit帖子的评论。

参数:

  • post_id (字符串,必需) - Reddit帖子ID(不带't3_'前缀)

示例:

{
  "post_id": "abc123"
}

searchPosts

在子版块中搜索帖子。

参数:

  • subreddit (字符串,必需) - 子版块名称
  • query (字符串,必需) - 搜索查询
  • limit (整数,可选) - 结果数量(1-100,默认值:110)

示例:

{
  "subreddit": "programming",
  "query": "python tutorial",
  "limit": 10
}

postComment

在Reddit帖子上发布评论。

参数:

  • post_id (字符串,必需) - Reddit帖子ID(不带't3_'前缀)
  • comment_text (字符串,必需) - 要发布的评论文本

示例:

{
  "post_id": "abc123",
  "comment_text": "Great post! Thanks for sharing."
}

getSubredditInfo

获取关于子版块的详细信息。

参数:

  • subreddit (字符串,必需) - 子版块名称

示例:

{
  "subreddit": "MachineLearning"
}

postToSubreddit

在子版块中创建新帖子。

参数:

  • subreddit (字符串,必需) - 子版块名称
  • title (字符串,必需) - 帖子标题
  • content (字符串,可选) - 文本帖子的内容
  • url (字符串,可选) - 链接帖子的URL

注意: 必须提供contenturl中的一个。

示例(文本帖子):

{
  "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"
}

🔧 开发

从源码构建

# 克隆仓库
git clone https://github.com/<my-org>/reddit-mcp
cd reddit-mcp

# 安装依赖
pip install -r requirements.txt

# 本地运行(需要环境变量)
python src/server.py

可用的构建命令

Linux/macOS (Makefile):

make help       # 显示帮助
make build      # 构建Docker镜像
make test       # 运行测试
make catalog    # 生成MCP目录
make publish    # 准备提交到注册表
make clean      # 清理Docker镜像

Windows (PowerShell/Batch):

.\build.ps1 help       # 显示帮助
.\build.ps1 build      # 构建Docker镜像
.\build.ps1 test       # 运行测试
.\build.ps1 catalog    # 生成MCP目录
.\build.ps1 publish    # 准备提交到注册表
.\build.ps1 clean      # 清理Docker镜像

# 或使用简单的批处理文件:
.\build-win.bat build       # 构建Docker镜像
.\build-win.bat test        # 运行测试
.\build-win.bat catalog     # 生成MCP目录
.\build-win.bat clean       # 清理Docker镜像

项目结构

reddit-mcp/
├── src/
│   └── server.py          # 主MCP服务器实现
├── catalogs/
│   └── reddit-mcp/
│       └── catalog.yaml   # MCP目录定义
├── Dockerfile             # Docker容器定义
├── requirements.txt       # Python依赖
├── server.json           # MCP服务器元数据
├── tools.json            # 工具定义
├── Makefile              # 构建自动化
├── *.sh                  # 自动化脚本
└── README.md             # 此文件

🔐 安全与认证

Reddit API设置

  1. 访问 https://www.reddit.com/prefs/apps
  2. 点击“创建应用”或“创建另一个应用”
  3. 选择“脚本”作为应用类型
  4. 记下您的客户端ID(在应用名称下)和客户端密钥
  5. 使用您的凭据设置环境变量

环境变量

变量必需秘密描述
REDDIT_CLIENT_IDReddit应用客户端ID
REDDIT_CLIENT_SECRETReddit应用客户端密钥
REDDIT_USERNAME您的Reddit用户名
REDDIT_PASSWORD您的Reddit密码
REDDIT_USER_AGENT用户代理字符串(默认值:"mcp-reddit-agent/0.1")

安全最佳实践

  • 安全存储秘密(使用环境变量,而不是硬编码值)
  • 使用专用的Reddit账户进行自动化操作
  • 遵循Reddit的API速率限制指南
  • 尊重子版块规则和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的信息,并显示最近关于transformers的帖子"

🚀 部署与提交

Docker注册表提交

此服务器已准备好提交到官方Docker MCP注册表:

  1. 本地构建和测试:

    Linux/macOS:

    make build
    make test
    

    Windows:

    .\build.ps1 build
    .\build.ps1 test
    
  2. 推送到Docker Hub:

    docker tag mcp/reddit-mcp:latest your-dockerhub-username/reddit-mcp:latest
    docker push your-dockerhub-username/reddit-mcp:latest
    
  3. 更新server.json中的仓库详情

  4. 提交到MCP注册表:

    # 使用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通信
  • 环境变量:正确配置的秘密和环境变量
  • 服务器元数据:完整的server.json带有工具定义
  • 文档:全面的README和使用示例
  • 类别:社交(如指定)

注册表元数据

🤝 贡献

  1. 分叉仓库
  2. 创建特性分支(git checkout -b feature/amazing-feature
  3. 提交更改(git commit -m '添加惊人的特性'
  4. 推送到分支(git push origin feature/amazing-feature
  5. 打开Pull Request

📄 许可证

此项目根据MIT许可证发布 - 查看LICENSE文件了解详情。

🆘 支持

⚠️ 速率限制及最佳实践

  • Reddit API有速率限制 - 尊重它们
  • 批量操作时,在请求之间使用适当的延迟
  • 遵循Reddit的API服务条款
  • 尊重社区并遵循子版块规则
  • 考虑在可能的情况下使用只读操作

准备提交到MCP注册表 🚀

此服务器完全配置好,可以按照所有贡献指南提交到官方Docker MCP注册表。