Skip to main content
Glama
jordanburke

reddit-mcp-server

get_trending_subreddits

Fetch currently trending subreddits to discover popular communities and topics on Reddit.

Instructions

Get currently trending subreddits

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

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")}`
      },
    })
  • 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")}`
      },
  • 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")
      }
    }

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

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