get_reddit_subreddit
Retrieve posts from a specific Reddit community to analyze content, trends, or discussions. Enter the subreddit name to access recent posts and engagement data.
Instructions
Get Reddit subreddit posts
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| subreddit | Yes | Subreddit name (without r/) |
Implementation Reference
- src/index.ts:511-530 (handler)Handler for the get_reddit_subreddit tool: extracts subreddit name from arguments, calls Sociavault API, processes response with extractRedditSubreddit helper, and returns formatted posts as JSON.if (name === "get_reddit_subreddit") { const { subreddit } = args as { subreddit: string }; const response = await axios.get(`${BASE_URL}/reddit/subreddit`, { headers: { "X-API-Key": API_KEY }, params: { subreddit }, }); const extracted = extractRedditSubreddit(response.data, 10); return { content: [ { type: "text", text: JSON.stringify( { subreddit, posts: extracted, total_returned: extracted.length }, null, 2 ), }, ], }; }
- src/index.ts:328-341 (registration)Registration of the get_reddit_subreddit tool in the tools array, including name, description, and input schema requiring 'subreddit' parameter.{ name: "get_reddit_subreddit", description: "Get Reddit subreddit posts", inputSchema: { type: "object", properties: { subreddit: { type: "string", description: "Subreddit name (without r/)", }, }, required: ["subreddit"], }, },
- src/index.ts:331-341 (schema)Input schema for get_reddit_subreddit tool, defining a required 'subreddit' string parameter.inputSchema: { type: "object", properties: { subreddit: { type: "string", description: "Subreddit name (without r/)", }, }, required: ["subreddit"], }, },
- src/index.ts:187-209 (helper)Helper function extractRedditSubreddit that parses API response data into a list of up to 10 formatted post objects with key fields like title, author, score, etc.function extractRedditSubreddit(data: any, limit = 10) { const posts = data?.data?.children || data?.children || data?.data?.posts || data?.posts || []; return posts.slice(0, limit).map((item: any) => { const post = item.data || item; return { title: post.title, author: post.author, score: post.score || 0, upvote_ratio: post.upvote_ratio || 0, num_comments: post.num_comments || 0, created_utc: post.created_utc, url: post.url, permalink: post.permalink, selftext: (post.selftext || "").substring(0, 200), // Limit text length is_video: post.is_video || false, }; }); }