Skip to main content
Glama

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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); }) );
  • 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({});
  • 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 }, ); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tandat8503/mcp-reddit'

If you have feedback or need assistance with the MCP directory API, please join our Discord server