get_trending_subreddits
Discover trending subreddits to identify popular communities and topics currently active on Reddit.
Instructions
Get currently trending subreddits
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_trending_subreddits"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
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: {}, }, }, - src/index.ts:451-452 (handler)MCP server CallToolRequest handler that dispatches the 'get_trending_subreddits' tool call to the implementation.
case "get_trending_subreddits": return await tools.getTrendingSubreddits(); - src/tools/subreddit-tools.ts:70-105 (handler)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}` ); } } - src/client/reddit-client.ts:254-268 (helper)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"); } }