get_reddit_post
Fetch a specific Reddit post by providing its subreddit and post ID for content retrieval and analysis.
Instructions
Get a Reddit post
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| subreddit | Yes | The subreddit to fetch posts from | |
| post_id | Yes | The ID of the post to fetch |
Implementation Reference
- src/tools/post-tools.ts:5-73 (handler)The primary handler function for the 'get_reddit_post' tool. It fetches the specified Reddit post using the Reddit client, formats the information, and returns a detailed markdown-formatted response including post details, content, stats, metadata, links, and engagement analysis.export async function getRedditPost(params: { subreddit: string; post_id: string; }) { const { subreddit, post_id } = params; const client = getRedditClient(); if (!client) { throw new McpError( ErrorCode.InternalError, "Reddit client not initialized" ); } try { console.log(`[Tool] Getting post ${post_id} from r/${subreddit}`); const post = await client.getPost(post_id, subreddit); const formattedPost = formatPostInfo(post); return { content: [ { type: "text", text: ` # Post from r/${formattedPost.subreddit} ## Post Details - Title: ${formattedPost.title} - Type: ${formattedPost.type} - Author: u/${formattedPost.author} ## Content ${formattedPost.content} ## Stats - Score: ${formattedPost.stats.score.toLocaleString()} - Upvote Ratio: ${(formattedPost.stats.upvoteRatio * 100).toFixed(1)}% - Comments: ${formattedPost.stats.comments.toLocaleString()} ## Metadata - Posted: ${formattedPost.metadata.posted} - Flags: ${ formattedPost.metadata.flags.length ? formattedPost.metadata.flags.join(", ") : "None" } - Flair: ${formattedPost.metadata.flair} ## Links - Full Post: ${formattedPost.links.fullPost} - Short Link: ${formattedPost.links.shortLink} ## Engagement Analysis - ${formattedPost.engagementAnalysis.replace(/\n - /g, "\n- ")} ## Best Time to Engage ${formattedPost.bestTimeToEngage} `, }, ], }; } catch (error) { console.error(`[Error] Error getting post: ${error}`); throw new McpError( ErrorCode.InternalError, `Failed to fetch post data: ${error}` ); } }
- src/index.ts:99-116 (schema)Defines the input schema for the 'get_reddit_post' tool in the listTools response, requiring 'subreddit' and 'post_id' as strings.{ name: "get_reddit_post", description: "Get a Reddit post", inputSchema: { type: "object", properties: { subreddit: { type: "string", description: "The subreddit to fetch posts from", }, post_id: { type: "string", description: "The ID of the post to fetch", }, }, required: ["subreddit", "post_id"], }, },
- src/index.ts:429-432 (registration)Registers and dispatches the 'get_reddit_post' tool call to the imported tools.getRedditPost function in the CallToolRequest handler.case "get_reddit_post": return await tools.getRedditPost( toolParams as { subreddit: string; post_id: string } );