get_subreddit_info
Retrieve detailed information about any Reddit community including member count, description, rules, and activity metrics to understand subreddit characteristics and content focus.
Instructions
Get information about a subreddit
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| subreddit_name | Yes | Name of the subreddit |
Implementation Reference
- src/tools/subreddit-tools.ts:5-68 (handler)MCP tool handler that processes the tool call, fetches data from Reddit client, formats it, and returns markdown-formatted content.export async function getSubredditInfo(params: { subreddit_name: string }) { const { subreddit_name } = params; const client = getRedditClient(); if (!client) { throw new McpError( ErrorCode.InternalError, "Reddit client not initialized" ); } try { console.log(`[Tool] Getting info for r/${subreddit_name}`); const subreddit = await client.getSubredditInfo(subreddit_name); const formattedSubreddit = formatSubredditInfo(subreddit); return { content: [ { type: "text", text: ` # Subreddit Information: r/${formattedSubreddit.name} ## Overview - Name: r/${formattedSubreddit.name} - Title: ${formattedSubreddit.title} - Subscribers: ${formattedSubreddit.stats.subscribers.toLocaleString()} - Active Users: ${ typeof formattedSubreddit.stats.activeUsers === "number" ? formattedSubreddit.stats.activeUsers.toLocaleString() : formattedSubreddit.stats.activeUsers } ## Description ${formattedSubreddit.description.short} ## Detailed Description ${formattedSubreddit.description.full} ## Metadata - Created: ${formattedSubreddit.metadata.created} - Flags: ${formattedSubreddit.metadata.flags.join(", ")} ## Links - Subreddit: ${formattedSubreddit.links.subreddit} - Wiki: ${formattedSubreddit.links.wiki} ## Community Analysis - ${formattedSubreddit.communityAnalysis.replace(/\n - /g, "\n- ")} ## Engagement Tips - ${formattedSubreddit.engagementTips.replace(/\n - /g, "\n- ")} `, }, ], }; } catch (error) { console.error(`[Error] Error getting subreddit info: ${error}`); throw new McpError( ErrorCode.InternalError, `Failed to fetch subreddit data: ${error}` ); } }
- src/index.ts:157-170 (schema)Input schema for the get_subreddit_info tool, defining the required subreddit_name parameter.{ name: "get_subreddit_info", description: "Get information about a subreddit", inputSchema: { type: "object", properties: { subreddit_name: { type: "string", description: "Name of the subreddit", }, }, required: ["subreddit_name"], }, },
- src/index.ts:446-449 (registration)Registration and dispatch logic in the CallToolRequest handler that calls the tool function.case "get_subreddit_info": return await tools.getSubredditInfo( toolParams as { subreddit_name: string } );
- src/client/reddit-client.ts:137-162 (helper)Core Reddit API client method that fetches subreddit data from Reddit's /r/{subreddit}/about.json endpoint.async getSubredditInfo(subredditName: string): Promise<RedditSubreddit> { await this.authenticate(); try { const response = await this.api.get(`/r/${subredditName}/about.json`); const data = response.data.data; return { displayName: data.display_name, title: data.title, description: data.description || "", publicDescription: data.public_description || "", subscribers: data.subscribers, activeUserCount: data.active_user_count, createdUtc: data.created_utc, over18: data.over18, subredditType: data.subreddit_type, url: data.url, }; } catch (error) { console.error( `[Error] Failed to get subreddit info for ${subredditName}:`, error ); throw new Error(`Failed to get subreddit info for ${subredditName}`); } }
- src/utils/formatters.ts:290-331 (helper)Helper function that formats raw RedditSubreddit data into a structured FormattedSubredditInfo object used in the tool response.export function formatSubredditInfo( subreddit: RedditSubreddit ): FormattedSubredditInfo { const flags: string[] = []; if (subreddit.over18) flags.push("NSFW"); if (subreddit.subredditType) flags.push(`Type: ${subreddit.subredditType}`); const ageDays = (Date.now() / 1000 - subreddit.createdUtc) / (24 * 3600); return { name: subreddit.displayName, title: subreddit.title, stats: { subscribers: subreddit.subscribers, activeUsers: subreddit.activeUserCount !== undefined ? subreddit.activeUserCount : "Unknown", }, description: { short: subreddit.publicDescription, full: subreddit.description.length > 300 ? subreddit.description.substring(0, 297) + "..." : subreddit.description, }, metadata: { created: formatTimestamp(subreddit.createdUtc), flags: flags.length ? flags : ["None"], }, links: { subreddit: `https://reddit.com${subreddit.url}`, wiki: `https://reddit.com/r/${subreddit.displayName}/wiki`, }, communityAnalysis: analyzeSubredditHealth( subreddit.subscribers, subreddit.activeUserCount, ageDays ), engagementTips: getSubredditEngagementTips(subreddit), }; }