|
| 1 | +# Reddit Search MCP Server |
| 2 | + |
| 3 | +A Model Context Protocol (MCP) server that enables AI clients to search, retrieve, and interact with Reddit content. Provides semantic search, post creation, comment management, and community discovery capabilities. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Semantic Search**: Find relevant subreddits and posts using natural language queries |
| 8 | +- **Content Creation**: Create posts and comments programmatically |
| 9 | +- **Community Discovery**: Discover relevant subreddits based on topics |
| 10 | +- **Rate Limiting**: Built-in rate limiting and retry logic for Reddit API |
| 11 | +- **Dual Transport**: Supports both SSE and StreamableHTTP protocols |
| 12 | + |
| 13 | +## Tools Reference |
| 14 | + |
| 15 | +| Tool | Description | Input Parameters | Output | Credentials Required | |
| 16 | +|------|-------------|------------------|--------|---------------------| |
| 17 | +| `reddit_find_subreddits` | Find relevant subreddits based on a query | `query` (string) | Array of subreddit objects with name, description, subscriber_count | Basic API credentials | |
| 18 | +| `reddit_search_posts` | Search for posts in a specific subreddit | `subreddit` (string), `query` (string) | Array of post objects with title, score, url, comment_count | Basic API credentials | |
| 19 | +| `reddit_get_post_comments` | Get top comments for a specific post | `post_id` (string), `subreddit` (string) | Array of comment objects with author, body, score | Basic API credentials | |
| 20 | +| `reddit_find_similar_posts` | Find posts similar to a given post | `post_id` (string), `limit` (number, optional) | Array of similar post objects | Basic API credentials | |
| 21 | +| `reddit_create_post` | Create a new text post in a subreddit | `subreddit` (string), `title` (string), `text` (string) | Post creation confirmation with post_id | Basic API credentials + Username/Password | |
| 22 | +| `reddit_create_comment` | Create a comment on a post | `post_id` (string), `text` (string) | Comment creation confirmation with comment_id | Basic API credentials + Username/Password | |
| 23 | +| `reddit_upvote` | Upvote a post | `post_id` (string) | Upvote confirmation | Basic API credentials + Username/Password | |
| 24 | +| `reddit_get_user_posts` | Get recent posts by authenticated user | `limit` (number, optional) | Array of user's post objects | Basic API credentials + Username/Password | |
| 25 | + |
| 26 | +## Prerequisites |
| 27 | + |
| 28 | +### Reddit API Credentials |
| 29 | + |
| 30 | +1. Visit https://www.reddit.com/prefs/apps |
| 31 | +2. Click "Create App" or "Create Another App" |
| 32 | +3. Choose "script" application type |
| 33 | +4. Save the generated `client_id` and `client_secret` |
| 34 | + |
| 35 | +**For Post Creation/Interaction**: You'll also need your Reddit username and password. |
| 36 | + |
| 37 | +## Setup |
| 38 | + |
| 39 | +### 1. Environment Configuration |
| 40 | + |
| 41 | +Create `.env` file in `mcp_servers/reddit_search/`: |
| 42 | + |
| 43 | +```bash |
| 44 | +REDDIT_MCP_SERVER_PORT=5001 |
| 45 | +REDDIT_CLIENT_ID=your_client_id_here |
| 46 | +REDDIT_CLIENT_SECRET=your_client_secret_here |
| 47 | +REDDIT_USER_AGENT=klavis-mcp/0.1 (+https://klavis.ai) |
| 48 | + |
| 49 | +# For post creation (optional - only needed for reddit_create_post, reddit_create_comment, reddit_upvote) |
| 50 | +REDDIT_USERNAME=your_reddit_username |
| 51 | +REDDIT_PASSWORD=your_reddit_password |
| 52 | +``` |
| 53 | + |
| 54 | +### 2. Running the Server |
| 55 | + |
| 56 | +#### Docker (Recommended) |
| 57 | +```bash |
| 58 | +# From repository root |
| 59 | +docker build -t reddit-mcp-server -f mcp_servers/reddit_search/Dockerfile . |
| 60 | +docker run -p 5001:5001 --env-file mcp_servers/reddit_search/.env reddit-mcp-server |
| 61 | +``` |
| 62 | + |
| 63 | +#### Direct Python |
| 64 | +```bash |
| 65 | +cd mcp_servers/reddit_search |
| 66 | +python server.py --port 5001 |
| 67 | +``` |
| 68 | + |
| 69 | +## Cursor IDE Integration |
| 70 | + |
| 71 | +### 1. Configure MCP Server in Cursor |
| 72 | + |
| 73 | +Add to `~/.cursor/mcp.json`: |
| 74 | +```json |
| 75 | +{ |
| 76 | + "mcpServers": { |
| 77 | + "reddit-search": { |
| 78 | + "url": "http://localhost:5001/sse" |
| 79 | + } |
| 80 | + } |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +### 2. Test in Cursor Chat |
| 85 | + |
| 86 | +Try these example queries: |
| 87 | + |
| 88 | +- "Use reddit_find_subreddits to find subreddits related to machine learning" |
| 89 | +- "Use reddit_search_posts in subreddit 'programming' for query 'Python vs JavaScript'" |
| 90 | +- "Use reddit_get_post_comments for post_id '1nqa311' in subreddit 'programming'" |
| 91 | +- "Use reddit_find_similar_posts for post_id '1nqa311' with limit 5" |
| 92 | +- "Use reddit_create_post in subreddit 'test' with title 'Test Post' and text 'This is a test'" |
| 93 | + |
| 94 | +## API Endpoints |
| 95 | + |
| 96 | +- **SSE**: `GET /sse` - Server-Sent Events endpoint for MCP communication |
| 97 | +- **StreamableHTTP**: `POST /mcp` - StreamableHTTP endpoint for MCP communication |
| 98 | + |
| 99 | +## Authentication |
| 100 | + |
| 101 | +The server uses Reddit's OAuth2 client credentials flow. Access tokens are automatically obtained and cached for the duration of the server session. |
| 102 | + |
| 103 | +## Rate Limiting |
| 104 | + |
| 105 | +Built-in rate limiting and retry logic: |
| 106 | +- Respects Reddit's rate limits (429 responses) |
| 107 | +- Implements exponential backoff for failed requests |
| 108 | +- Includes jitter to prevent thundering herd effects |
| 109 | + |
| 110 | +## Dependencies |
| 111 | + |
| 112 | +- mcp>=1.12.0 |
| 113 | +- pydantic |
| 114 | +- typing-extensions |
| 115 | +- httpx |
| 116 | +- click |
| 117 | +- python-dotenv |
| 118 | +- starlette |
| 119 | +- uvicorn[standard] |
0 commit comments