get_reddit_post
Fetch specific Reddit posts by providing the subreddit name and post ID to retrieve content and discussions from any community.
Instructions
Get a Reddit post
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| post_id | Yes | The ID of the post to fetch | |
| subreddit | Yes | The subreddit to fetch posts from |
Implementation Reference
- src/tools/post-tools.ts:5-73 (handler)Core handler function that executes the get_reddit_post tool: fetches Reddit post data, formats it richly with stats, metadata, engagement analysis, and returns MCP-formatted content.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:100-116 (schema)Tool schema definition including name, description, and input schema for validation in the ListTools response.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)Tool registration in the CallToolRequestHandler switch statement, dispatching to the handler function.case "get_reddit_post": return await tools.getRedditPost( toolParams as { subreddit: string; post_id: string } );