get_reddit_post_details
Retrieve comprehensive details about any Reddit post by providing its unique post ID to access information such as content, author, votes, and comments.
Instructions
Get detailed information about a specific Reddit post
Args: post_id: The Reddit post ID
Returns: Human readable string containing detailed post information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| post_id | Yes |
Implementation Reference
- reddit_mcp/server.py:181-233 (handler)The main tool handler function for 'get_reddit_post_details', decorated with @mcp.tool() which registers it in FastMCP. It handles input validation implicitly via type hints, fetches data using the RedditClient helper, formats the output as a human-readable string, provides initialization error messages, and error handling.@mcp.tool() async def get_reddit_post_details(post_id: str) -> str: """ Get detailed information about a specific Reddit post Args: post_id: The Reddit post ID Returns: Human readable string containing detailed post information """ if reddit_client is None: return """Error: Reddit client not initialized. To fix this: 1. Copy env.example to .env: cp env.example .env 2. Edit .env with your Reddit API credentials: - Get credentials from https://old.reddit.com/prefs/apps/ - Create a 'script' type app - Fill in REDDIT_CLIENT_ID, REDDIT_CLIENT_SECRET, and REDDIT_USER_AGENT 3. Restart the MCP server Example .env content: REDDIT_CLIENT_ID=your_14_char_client_id REDDIT_CLIENT_SECRET=your_27_char_client_secret REDDIT_USER_AGENT=reddit-mcp-tool:v0.2.0 (by /u/yourusername)""" try: post_details = await reddit_client.get_post_details(post_id) result = ( f"**{post_details['title']}**\n\n" f"Author: {post_details['author']}\n" f"Score: {post_details['score']} (upvote ratio: {post_details['upvote_ratio']:.0%})\n" f"Comments: {post_details['num_comments']}\n" f"Link: {post_details['permalink']}\n" f"Subreddit: r/{post_details['subreddit']}\n" f"Domain: {post_details['domain']}\n" f"Locked: {post_details['locked']}\n" f"Stickied: {post_details['stickied']}\n" ) if post_details.get('flair_text'): result += f"Flair: {post_details['flair_text']}\n" if post_details['selftext']: result += f"\nContent:\n{post_details['selftext']}\n" return result except Exception as e: logger.error(f"Error getting post details for {post_id}: {str(e)}") return f"Error getting post details for {post_id}: {str(e)}"
- reddit_mcp/reddit_client.py:73-98 (helper)The RedditClient.get_post_details method, a supporting utility that uses asyncpraw to fetch detailed post data from the Reddit API and returns a structured dictionary used by the tool handler.async def get_post_details(self, post_id: str) -> Dict[str, Any]: """Get detailed information about a specific post.""" try: submission = await self.reddit.submission(id=post_id) return { "id": submission.id, "title": submission.title, "author": str(submission.author) if submission.author else "[deleted]", "score": submission.score, "upvote_ratio": submission.upvote_ratio, "url": submission.url, "permalink": f"https://reddit.com{submission.permalink}", "created_utc": submission.created_utc, "num_comments": submission.num_comments, "selftext": submission.selftext, "is_self": submission.is_self, "domain": submission.domain, "subreddit": str(submission.subreddit), "flair_text": submission.link_flair_text, "locked": submission.locked, "stickied": submission.stickied, } except Exception as e: raise Exception(f"Error getting post details for {post_id}: {str(e)}")