Reddit Content API

by tymcftw

Integrations

  • Uses environment variables for configuration management, specifically for storing Reddit API credentials in a .env file.

  • References GitHub for repository management, including starring, forking, and contributing to the project through issues and pull requests.

  • Provides tools for interacting with Reddit, including reading trending posts from subreddits, analyzing discussions with comments, creating posts, adding comments or replies, and voting on posts and comments.

Reddit 内容 API - 设置和使用指南

该项目提供了通过 Claude 和 Cursor 与 Reddit 交互的 MCP(模型上下文协议)工具。

特征

  • 阅读子版块的热门帖子
  • 分析 Reddit 讨论和评论
  • 在 Reddit 上创建帖子
  • 向帖子添加评论或回复现有评论
  • 对帖子和评论进行投票

要求

  • Python 3.10+
  • Reddit 帐户
  • 已注册的 Reddit 应用程序(用于获取 client_id 和 client_secret)
  • 虚拟环境(venv 或类似)
  • Claude Desktop 和/或 Cursor(可选但推荐)

从头开始安装

请仔细按照以下步骤操作以避免导入和配置问题:

# 1. Clone the repository git clone https://github.com/your-username/mcp-reddit.git cd mcp-reddit # 2. Create and activate virtual environment python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate # 3. Install dependencies (WITHOUT installing the package in editable mode) pip install -r requirements.txt # 4. Configure environment variables (see below) # Create and edit the .env file

⚠️重要提示:请勿在可编辑模式下安装包( pip install -e . ),因为它可能导致模块导入问题。

环境配置

  1. 在项目根目录中创建一个.env文件,其中包含以下变量:
REDDIT_CLIENT_ID=your_client_id REDDIT_CLIENT_SECRET=your_client_secret REDDIT_REFRESH_TOKEN=your_refresh_token
  1. 要获取刷新令牌,请运行:
python -m mcp_reddit.auth_helper

按照说明授权应用程序。令牌将自动保存到.env文件中。

项目结构

mcp-reddit/ │ ├── src/ │ └── mcp_reddit/ │ ├── __init__.py │ ├── main.py # Entry point for the MCP server │ ├── reddit_fetcher.py # Implementation of Reddit tools │ └── auth_helper.py # Helper for generating authentication tokens │ ├── .env # Environment variables (create manually) ├── requirements.txt ├── setup.py └── README.md

直接运行服务器

手动运行(对于开发和测试有用):

cd /path/to/mcp-reddit .venv/bin/python src/mcp_reddit/main.py

您应该会看到以下日志:

  • 服务器初始化
  • Reddit 身份验证
  • 注册 10 个工具(5 个原版 + 5 个带前缀)
  • “正在运行 MCP 服务器...”

Claude桌面配置

  1. 找到配置文件:
    • 在 macOS 上: /Users/your-username/Library/Application Support/Claude/claude_desktop_config.json
    • 在 Windows 上: %APPDATA%\Claude\claude_desktop_config.json
  2. 添加reddit-content-api的配置:
"reddit-content-api": { "command": "/full/path/to/mcp-reddit/.venv/bin/python", "args": [ "-m", "mcp_reddit.main", "--stdio" ], "cwd": "/full/path/to/mcp-reddit", "env": { "PYTHONPATH": "/full/path/to/mcp-reddit/src:/full/path/to/mcp-reddit", "DEBUG": "true" } }

⚠️极其重要PYTHONPATH必须同时包含src目录和项目根目录,按此顺序,以:在 Unix/macOS 上)或; (在 Windows 上)分隔

游标配置

  1. 找到配置文件:
    • 在 macOS 上: /Users/your-username/.cursor/mcp.json
    • 在 Windows 上: %USERPROFILE%\.cursor\mcp.json
  2. 添加与 Claude 相同的配置,根据需要调整路径。

常见问题故障排除

问题:仅显示 2 个工具,而不是预期的 10 个

症状:运行服务器时,仅出现 2 个工具,而不是预期的 10 个。

可能的原因和解决方案

  1. 导入问题:Python 正在从site-packages导入已安装的版本,而不是src/中的本地代码。解决方案
    • 确保不要以可编辑模式安装包( pip install -e .
    • 在配置中明确将src添加到PYTHONPATH的开头
    • 如果您已经安装了它,请使用pip uninstall reddit-content-api将其删除
  2. Python 缓存:旧的.pyc文件可能会导致问题。解决方案
    • 从项目中删除所有__pycache__目录
  3. 版本冲突:同一个库的不同版本。解决方案
    • 使用pip install -r requirements.txt重新安装依赖项

问题:“无法创建帖子:Reddit 身份验证未正确配置”

原因:刷新令牌无效或已过期。

解决方案:通过运行python -m mcp_reddit.auth_helper重新生成令牌,并确保其保存在.env中。

问题:Claude/Cursor 中不显示工具

原因:配置文件中的配置不正确。

解决方案

  • 检查配置文件中的路径,特别是PYTHONPATH
  • 修改配置后彻底重启Claude/Cursor

使用 Claude/Cursor 中的工具

配置完成后,您可以使用以下工具:

  1. mcp_reddit_content_api_fetch_reddit_hot_threads - 获取热门帖子
  2. mcp_reddit_content_api_fetch_reddit_post_content - 分析帖子及其评论
  3. mcp_reddit_content_api_create_reddit_post - 创建新帖子
  4. mcp_reddit_content_api_add_reddit_comment - 添加评论
  5. mcp_reddit_content_api_vote_on_reddit_content - 对内容进行投票

示例

获取热门帖子

Subreddit: python Number of posts: 5

创建帖子

Subreddit: test Title: Test from MCP Content type: text Content: This is a test from the Reddit Content API using MCP.

贡献

如果您发现问题或有改进,请创建问题或提交拉取请求。

执照

麻省理工学院

支持这个项目

如果您发现该项目对您的工作或研究有用,请考虑:

  • ⭐ 为存储库加星标以表示您的支持
  • 🔄 关注代码库以获取新功能和改进的更新
  • 🐛 提交 Bug 或功能请求的问题
  • 🛠️ 如果您有改进想要分享,请通过 Pull 请求进行贡献

您的支持有助于让这个项目更好地服务于每个人!

-
security - not tested
A
license - permissive license
-
quality - not tested

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

MCP 服务器可以与 Reddit 进行交互,允许用户通过 Claude 和 Cursor 阅读热门帖子、分析讨论、创建帖子、添加评论以及对内容进行投票。

  1. 特征
    1. 要求
      1. 从头开始安装
        1. 环境配置
          1. 项目结构
            1. 直接运行服务器
              1. Claude桌面配置
                1. 游标配置
                  1. 常见问题故障排除
                    1. 问题:仅显示 2 个工具,而不是预期的 10 个
                    2. 问题:“无法创建帖子:Reddit 身份验证未正确配置”
                    3. 问题:Claude/Cursor 中不显示工具
                  2. 使用 Claude/Cursor 中的工具
                    1. 示例
                  3. 贡献
                    1. 执照
                      1. 支持这个项目

                        Related MCP Servers

                        • A
                          security
                          A
                          license
                          A
                          quality
                          An MCP server that enables saving and sharing Claude Desktop conversations, allowing users to store chats privately or make them public through a web interface.
                          Last updated -
                          2
                          6
                          TypeScript
                          MIT License
                          • Apple
                        • A
                          security
                          A
                          license
                          A
                          quality
                          An MCP server that enables Claude to interact with Twitter, allowing for posting tweets and searching Twitter content.
                          Last updated -
                          2
                          65
                          202
                          TypeScript
                          MIT License
                          • Apple
                        • A
                          security
                          A
                          license
                          A
                          quality
                          An MCP server that enables posting messages to Discord webhooks, allowing customization of content, username, and avatar URL.
                          Last updated -
                          1
                          0
                          JavaScript
                          MIT License
                        • -
                          security
                          A
                          license
                          -
                          quality
                          A MCP server that provides browser automation tools, allowing users to navigate websites, take screenshots, click elements, fill forms, and execute JavaScript through Playwright.
                          Last updated -
                          Python
                          Apache 2.0
                          • Apple

                        View all related MCP servers

                        ID: argh97ecbf