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
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/subreddit-tools.ts:70-105 (handler)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: {}, }, },
- src/index.ts:451-453 (handler)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();
- src/client/reddit-client.ts:254-268 (helper)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"); } }