Skip to main content
Glama

get_trending_subreddits

Discover which subreddits are currently trending to identify popular communities and topics gaining attention on Reddit.

Instructions

Get currently trending subreddits

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Main handler function that executes the get_trending_subreddits tool logic. Uses the Reddit client to fetch trending subreddits and returns formatted markdown text response.
    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}` ); } }
  • src/index.ts:172-178 (registration)
    Registration of the get_trending_subreddits tool in the MCP server's list of tools, including name, description, and empty input schema (no parameters required).
    name: "get_trending_subreddits", description: "Get currently trending subreddits", inputSchema: { type: "object", properties: {}, }, },
  • MCP server request handler dispatcher case that invokes the tool handler when get_trending_subreddits is called.
    case "get_trending_subreddits": return await tools.getTrendingSubreddits();
  • Helper method in RedditClient that performs the actual API call to fetch trending subreddits from Reddit's /subreddits/popular.json endpoint.
    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