get_trending_subreddits
Fetch a list of currently popular and trending subreddits, including details like name, title, subscribers, description, and URL, for streamlined discovery and analysis.
Instructions
๐ฅ Get trending/popular subreddits ๐ฏ What it does: Fetches list of currently popular and trending subreddits ๐ Required: None (no parameters needed) ๐ก Examples: โข Get trending: {} โข Simple call: {} ๐ Output: List of trending subreddits with name, title, subscribers, description, and URL
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:671-710 (handler)The core execution logic of the get_trending_subreddits tool handler. It applies smart defaults, calls the Reddit API service to fetch trending subreddits, validates the response, creates a custom formatter for subreddits, uses formatDataList helper to preview limited results, and returns a formatted markdown text response via createSuccessResponse.createToolHandler(async (params: z.infer<typeof SimpleTrendingSubredditsSchema>) => { // ๐ง Smart defaults - no parameters needed const smartDefaults = getSmartDefaults(params, 'trending'); const finalParams = { ...smartDefaults }; const result = await redditAPI.getTrendingSubreddits(finalParams.limit || 25); // โ DRY: Sแปญ dแปฅng validateApiResponse helper const subreddits = validateApiResponse(result, "trending subreddits"); if (subreddits.length === 0) { return createSuccessResponse("No trending subreddits found"); } const summary = `๐ฅ Found ${subreddits.length} trending subreddits`; // โ DRY: Sแปญ dแปฅng formatDataList helper vแปi custom formatter const subredditFormatter = (subreddit: any) => { const name = subreddit.display_name || 'Unknown'; const title = subreddit.title || 'No title'; const subscribers = subreddit.subscribers || 0; const description = subreddit.public_description || 'No description'; let result = `๐ **r/${name}** - ${title}\n`; result += `๐ฅ ${subscribers.toLocaleString()} subscribers\n`; if (description.length > 100) { result += `๐ ${description.substring(0, 100)}...\n`; } else { result += `๐ ${description}\n`; } result += `๐ https://reddit.com/r/${name}\n`; return result; }; const subredditDetails = formatDataList(subreddits, subredditFormatter, TRENDING_SUBREDDIT_LIMIT, "subreddits"); const resultText = `${summary}\n\n${subredditDetails}`; return createSuccessResponse(resultText); })
- src/index.ts:661-712 (registration)MCP server tool registration for 'get_trending_subreddits'. Registers the tool with name, detailed usage description including examples, input schema reference, and the wrapped handler function using createToolHandler.server.tool( "get_trending_subreddits", "๐ฅ Get trending/popular subreddits\n" + "๐ฏ What it does: Fetches list of currently popular and trending subreddits\n" + "๐ Required: None (no parameters needed)\n" + "๐ก Examples:\n" + " โข Get trending: {}\n" + " โข Simple call: {}\n" + "๐ Output: List of trending subreddits with name, title, subscribers, description, and URL", SimpleTrendingSubredditsSchema.shape, createToolHandler(async (params: z.infer<typeof SimpleTrendingSubredditsSchema>) => { // ๐ง Smart defaults - no parameters needed const smartDefaults = getSmartDefaults(params, 'trending'); const finalParams = { ...smartDefaults }; const result = await redditAPI.getTrendingSubreddits(finalParams.limit || 25); // โ DRY: Sแปญ dแปฅng validateApiResponse helper const subreddits = validateApiResponse(result, "trending subreddits"); if (subreddits.length === 0) { return createSuccessResponse("No trending subreddits found"); } const summary = `๐ฅ Found ${subreddits.length} trending subreddits`; // โ DRY: Sแปญ dแปฅng formatDataList helper vแปi custom formatter const subredditFormatter = (subreddit: any) => { const name = subreddit.display_name || 'Unknown'; const title = subreddit.title || 'No title'; const subscribers = subreddit.subscribers || 0; const description = subreddit.public_description || 'No description'; let result = `๐ **r/${name}** - ${title}\n`; result += `๐ฅ ${subscribers.toLocaleString()} subscribers\n`; if (description.length > 100) { result += `๐ ${description.substring(0, 100)}...\n`; } else { result += `๐ ${description}\n`; } result += `๐ https://reddit.com/r/${name}\n`; return result; }; const subredditDetails = formatDataList(subreddits, subredditFormatter, TRENDING_SUBREDDIT_LIMIT, "subreddits"); const resultText = `${summary}\n\n${subredditDetails}`; return createSuccessResponse(resultText); }) );
- src/types/index.ts:124-124 (schema)Zod input schema for the get_trending_subreddits tool. Defined as an empty object since the tool requires no parameters, allowing parameterless calls.export const SimpleTrendingSubredditsSchema = z.object({});
- src/services/reddit-api.ts:411-416 (helper)Supporting API service method in RedditAPIService that performs the authenticated GET request to Reddit's /subreddits/popular.json endpoint to retrieve the list of popular/trending subreddits, handling OAuth, rate limiting, and error responses.async getTrendingSubreddits(limit: number = 25): Promise<ApiCallResult> { return this.makeRequest<{ data: { children: Array<{ data: RedditSubreddit }> } }>( "/subreddits/popular.json", { limit }, ); }