get_trending_subreddits
Fetch currently trending subreddits to discover popular communities and topics on Reddit.
Instructions
Get currently trending subreddits
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:420-436 (registration)Registration of the 'get_trending_subreddits' MCP tool, including inline handler (execute function), schema (empty parameters), and description. The handler fetches trending subreddits using the Reddit client and returns a formatted markdown list.server.addTool({ name: "get_trending_subreddits", description: "Get a list of currently trending subreddits", parameters: z.object({}), execute: async () => { const client = getRedditClient() if (!client) { throw new Error("Reddit client not initialized") } const trendingSubreddits = await client.getTrendingSubreddits() return `# Trending Subreddits ${trendingSubreddits.map((subreddit, index) => `${index + 1}. r/${subreddit}`).join("\n")}` }, })
- src/index.ts:424-435 (handler)Inline execute handler function for the get_trending_subreddits tool that initializes Reddit client, calls getTrendingSubreddits, and formats the result as a numbered list in markdown.execute: async () => { const client = getRedditClient() if (!client) { throw new Error("Reddit client not initialized") } const trendingSubreddits = await client.getTrendingSubreddits() return `# Trending Subreddits ${trendingSubreddits.map((subreddit, index) => `${index + 1}. r/${subreddit}`).join("\n")}` },
- src/client/reddit-client.ts:277-293 (helper)Supporting method in RedditClient class that authenticates and fetches popular subreddits from Reddit API endpoint /subreddits/popular.json, returning array of subreddit names used as trending subreddits.async getTrendingSubreddits(limit: number = 5): Promise<string[]> { await this.authenticate() try { const params = new URLSearchParams({ limit: limit.toString() }) const response = await this.makeRequest(`/subreddits/popular.json?${params}`) if (!response.ok) { throw new Error(`HTTP ${response.status}`) } const json = (await response.json()) as { data: { children: any[] } } return json.data.children.map((child: any) => child.data.display_name) } catch { // Failed to get trending subreddits throw new Error("Failed to get trending subreddits") } }