Skip to main content
Glama

get_trending_subreddits

Discover trending subreddits to identify popular communities and topics currently active on Reddit.

Instructions

Get currently trending subreddits

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • src/index.ts:171-178 (registration)
    Registration of the 'get_trending_subreddits' tool in the MCP server's ListTools response, including name, description, and empty input schema.
    {
      name: "get_trending_subreddits",
      description: "Get currently trending subreddits",
      inputSchema: {
        type: "object",
        properties: {},
      },
    },
  • MCP server CallToolRequest handler that dispatches the 'get_trending_subreddits' tool call to the implementation.
    case "get_trending_subreddits":
      return await tools.getTrendingSubreddits();
  • Main tool handler function that orchestrates the call to Reddit client, handles errors, and formats the MCP response with a numbered list of trending subreddits.
    export async function getTrendingSubreddits() {
      const client = getRedditClient();
    
      if (!client) {
        throw new McpError(
          ErrorCode.InternalError,
          "Reddit client not initialized"
        );
      }
    
      try {
        console.log("[Tool] Getting trending subreddits");
        const trendingSubreddits = await client.getTrendingSubreddits();
    
        return {
          content: [
            {
              type: "text",
              text: `
    # Trending Subreddits
    
    ${trendingSubreddits
      .map((subreddit, index) => `${index + 1}. r/${subreddit}`)
      .join("\n")}
              `,
            },
          ],
        };
      } catch (error) {
        console.error(`[Error] Error getting trending subreddits: ${error}`);
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to fetch trending subreddits: ${error}`
        );
      }
    }
  • RedditClient helper method that performs the actual API request to Reddit's /subreddits/popular.json endpoint to retrieve popular (trending) subreddit names.
    async getTrendingSubreddits(limit: number = 5): Promise<string[]> {
      await this.authenticate();
      try {
        const response = await this.api.get("/subreddits/popular.json", {
          params: { limit },
        });
    
        return response.data.data.children.map(
          (child: any) => child.data.display_name
        );
      } catch (error) {
        console.error("[Error] Failed to get trending subreddits:", error);
        throw new Error("Failed to get trending subreddits");
      }
    }

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/samy-clivolt/reddit-mcp-server'

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