Skip to main content
Glama
tandat8503

Reddit MCP Server

by tandat8503

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