reddit-mcp

aniketwattamwar/reddit-mcp

3.1

If you are the rightful owner of reddit-mcp 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.

This project provides a FastMCP-based server for interacting with Reddit's API, offering tools and resources for fetching subreddit information, user details, and performing searches.

Reddit MCP Server

This project provides a FastMCP-based server for interacting with Reddit's API. It includes tools and resources for fetching subreddit information, user details, and performing searches.


Features

  • Fetch subreddit details dynamically.
  • Retrieve user information.
  • Search Reddit posts based on queries.
  • Access popular subreddits and Reddit API status.

Prerequisites

  1. Python: Ensure Python 3.11 is installed.
  2. Dependencies: Install required Python packages using pip.
  3. Reddit API Access: Obtain a Reddit API access token.

Installation

  1. Clone the repository:

    git clone https://github.com/your-username/reddit-mcp.git
    cd reddit-mcp
    
  2. Create a virtual environment:

    python -m venv .venv
    
  3. Activate the virtual environment:

    • Windows:
      .venv\Scripts\activate
      
    • Linux/Mac:
      source .venv/bin/activate
      
  4. Install dependencies:

    pip install -r requirements.txt
    

Running the MCP Server

  1. Start the MCP server:

    python mcp_server.py
    
    mcp run mcp_server.py
    
    mcp dev mcp_server.py
    

opens inspector and you can check how your mcp server is working

  1. The server will initialize and expose tools and resources for Reddit API interaction.

Obtaining Reddit Access Token

To interact with Reddit's API, you need an access token:

  1. Create a Reddit App:

    • Go to Reddit Apps.
    • Click "Create App" or "Create Another App".
    • Fill in the required details:
      • App type: Script.
      • Name: Your app name.
      • Redirect URI: http://localhost.
      • Permissions: Select appropriate scopes.
  2. Generate Access Token:

    • Use the following Python script to generate a token:
      import requests
      from requests.auth import HTTPBasicAuth
      
      client_id = "your_client_id"
      client_secret = "your_client_secret"
      username = "your_reddit_username"
      password = "your_reddit_password"
      
      auth = HTTPBasicAuth(client_id, client_secret)
      data = {
          "grant_type": "password",
          "username": username,
          "password": password
      }
      headers = {"User-Agent": "YourAppName/0.1"}
      
      response = requests.post("https://www.reddit.com/api/v1/access_token", auth=auth, data=data, headers=headers)
      print(response.json())
      
    • Replace your_client_id, your_client_secret, your_reddit_username, and your_reddit_password with your credentials.
    • The script will return an access token.
      OR
    • Use Postman
  3. Set the Access Token:

    • Update the Authorization header in mcp_server.py:
      client.headers["Authorization"] = f"Bearer {your_access_token}"
      

Contributing

We welcome contributions to improve the Reddit MCP Server. Follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix:
    git checkout -b feature-name
    
  3. Commit your changes:
    git commit -m "Add feature description"
    
  4. Push your branch:
    git push origin feature-name
    
  5. Create a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.


Contact

For questions or support, open an issue in the repository.