Provides comprehensive Reddit API access with 13 tools covering both read-only operations (getting posts, comments, user profiles, subreddit info, search) and authenticated actions (voting, commenting, creating posts) through OAuth2 authentication.
MCP Reddit Server
A Model Context Protocol (MCP) server that provides access to Reddit's API through a standardized interface. This server supports both read-only operations and authenticated actions using OAuth2.
🚀 Features
- 13 Comprehensive Tools: Covering both read-only and action-based operations
- OAuth2 Support: Full OAuth2 Authorization Code flow with redirect URI
- Persistent Token Storage: Tokens are automatically saved and restored across server restarts
- Advanced Rate Limiting: Built-in rate limiting with Reddit API header monitoring
- Type-Safe Architecture: Full TypeScript with Zod schema validation and z.infer types
- Error Handling: Robust error handling with dynamic troubleshooting tips
- Clean Code Patterns: Consistent tool handlers with reduced boilerplate
- MCP Standard: Compliant with Model Context Protocol specifications
🔐 OAuth2 Authentication
This server uses OAuth2 Authorization Code flow which is required by Reddit for authenticated operations. The flow works as follows:
- User Authorization: User visits Reddit authorization URL
- Callback: Reddit redirects to our callback URL with authorization code
- Token Exchange: Server exchanges code for access token
- API Access: Server uses access token for authenticated API calls
Required Reddit App Configuration
Your Reddit app must be configured as:
- App Type:
script
(personal use script) - Redirect URI:
http://localhost:8080
(must match exactly) - OAuth Scopes:
read submit vote history privatemessages subscribe
🛠️ Installation
- Clone the repository:
- Install dependencies:
- Set up environment variables:
- Build the project:
- Start the server:
⚙️ Configuration
Create a .env
file with the following variables:
Getting Reddit API Credentials
- Go to Reddit App Preferences
- Click "create application" or "create another app"
- Fill in the form:
- Name: Your app name
- App Type: Select "script"
- Description: Brief description
- About URL: (optional)
- Redirect URI:
http://localhost:8080
- Click "create app"
- Copy the Client ID (under the app name) and Client Secret
🧪 Testing
Quick OAuth2 Test
Test the complete OAuth2 flow:
Basic API Test
Test basic API connectivity:
Detailed OAuth Test
Comprehensive OAuth testing:
🎯 Available Tools
📖 Read-Only Tools (Public API)
get_subreddit_posts
- Get posts from a subreddit with sorting optionssearch_reddit
- Search for posts across Reddit or within specific subredditsget_user_profile
- Get detailed user profile informationget_subreddit_info
- Get comprehensive subreddit informationget_post_comments
- Get comments for a specific post with sortingget_trending_subreddits
- Get trending and popular subredditsget_user_posts
- Get posts by a specific userget_user_comments
- Get comments by a specific user
🎯 Action Tools (OAuth Required)
get_oauth_url
- Generate OAuth2 authorization URLexchange_oauth_code
- Exchange authorization code for access tokenvote_post
- Vote on posts or comments (upvote/downvote)comment_on_post
- Submit a comment on a postcreate_post
- Create a new post in a subreddit
🔧 Tool Features
- Smart Defaults: Intelligent parameter defaults for better UX
- Type Safety: Full TypeScript validation with Zod schemas
- Error Handling: Comprehensive error messages with troubleshooting tips
- Rate Limiting: Built-in protection against API rate limits
- Inline Documentation: Detailed descriptions with examples for each tool
🔄 OAuth2 Flow Details
Authorization URL
The server generates an authorization URL that users visit to grant permissions:
Callback Handling
The server starts a local HTTP server on port 8080 to receive the authorization callback from Reddit.
Token Management
- Access Token: Used for API calls (expires in 1 hour)
- Refresh Token: Used to refresh access token (permanent)
- Automatic Refresh: Server automatically refreshes expired tokens
- Persistent Storage: Tokens are saved to
reddit_tokens.json
and restored on startup - Smart Recovery: Server automatically loads valid tokens and handles expired ones gracefully
📊 Rate Limiting & OAuth Scopes
Rate Limits
- OAuth Apps: 60 requests per minute
- Public API: 30 requests per minute
- Built-in Protection: Server includes rate limiting to prevent API abuse
- Header Monitoring: Automatically reads
X-Ratelimit-Remaining
andX-Ratelimit-Reset
headers - Smart Warnings: Logs warnings when approaching rate limits
- Graceful Handling: Returns helpful error messages when rate limits are exceeded
OAuth Scopes
read
: Read posts, comments, subredditssubmit
: Submit posts and commentsvote
: Upvote/downvote posts and commentshistory
: Save/unsave postsprivatemessages
: Send private messagessubscribe
: Subscribe/unsubscribe to subreddits
🚨 Troubleshooting
Common Issues
- 401 Unauthorized
- Check Client ID and Client Secret in
.env
file - Verify app type is "script" in Reddit app settings
- Ensure OAuth scopes are set correctly
- Check if tokens in
reddit_tokens.json
are expired
- Check Client ID and Client Secret in
- Redirect URI Mismatch
- Redirect URI in
.env
must match Reddit app settings exactly - Default:
http://localhost:8080
(not/callback
) - Ensure no trailing slashes or extra paths
- Redirect URI in
- 403 Forbidden
- Check User-Agent string format
- Verify app is not suspended on Reddit
- Ensure proper OAuth scopes are granted
- Try re-authenticating with OAuth flow
- Rate Limit Exceeded
- Server automatically monitors rate limits
- Check console for rate limit warnings
- Wait for the reset time shown in error messages
- Consider implementing request queuing for high-volume usage
- Token Issues
- Delete
reddit_tokens.json
to force re-authentication - Check if tokens are being saved correctly
- Verify OAuth flow completed successfully
- Delete
Debug Steps
- Test Basic Connectivity:
- Test OAuth Flow:
- Check Credentials:
🏗️ Technical Improvements
Code Quality Enhancements
- Type Safety: All tools now use
z.infer<typeof Schema>
for compile-time type checking - Consistent Patterns: Unified
createToolHandler
wrapper eliminates boilerplate try-catch blocks - Magic Number Constants: Replaced hardcoded values with named constants for better maintainability
- Error Handling: Dynamic error messages with context-specific troubleshooting tips
Architecture Improvements
- Persistent Token Storage: Automatic token persistence in
reddit_tokens.json
- Rate Limit Intelligence: Real-time monitoring of Reddit API rate limit headers
- Smart Defaults: Intelligent parameter defaults based on tool context
- Clean Separation: Clear separation between read-only and action-based tools
Developer Experience
- Inline Documentation: Comprehensive tool descriptions with examples and usage patterns
- TypeScript Strict Mode: Full type safety with strict TypeScript configuration
- Consistent Error Responses: Standardized error format across all tools
- Build Validation: Automated TypeScript compilation with error checking
📁 Project Structure
🤝 Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
📄 License
This project is licensed under the MIT License.
🔗 Links
This server cannot be installed
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.
Enables interaction with Reddit through a comprehensive API interface supporting both read-only operations (browsing posts, comments, user profiles) and authenticated actions (posting, commenting, voting) via OAuth2 authentication.
Related MCP Servers
- AsecurityAlicenseAqualityA server allowing interaction with Reddit via the public API, enabling browsing frontpage posts, retrieving subreddit details, and reading post comments through a Model Context Protocol.Last updated -894MIT License
- -securityAlicense-qualityEnables interaction with GitHub repositories through the GitHub API, allowing file operations, repository management, issue tracking, and code search through natural language commands.Last updated -102MIT License
- AsecurityFlicenseAqualityEnables users to interact with X (Twitter) through the X API. Supports posting tweets, retrieving user timelines, searching tweets, and replying to tweets with comprehensive error handling.Last updated -33
- -securityFlicense-qualityProvides access to Reddit's API for retrieving posts, comments, user information, and search functionality. Supports multiple authentication methods and comprehensive Reddit data operations including subreddit browsing, post retrieval, and user profile access.Last updated -62